prolog program logic wrong - prolog

I am new to the Prolog programming language. When I give input as fly(x,y), I want a value to be displayed. I was just trying to execute the following code:-
fly(x,y):-
t is 1.5,
write(t).
Can I know what's wrong with this code?

Related

Prolog procedure does not exist (cant run rules in prolog)

I am new to Prolog and using the SWISH SWI online PROLOG website. https://swish.swi-prolog.org/
I am trying a really basic program:
a('jae').
b('lii').
c('jackson').
happy(A):-sings(A).
happy(B):-dances(B).
goToPlay(C):-free(C).
trying to run happy(jae). gives the following error
procedure `sings(A)' does not exist
Reachable from:
happy(A)
Please help me solve this.
If submit the goal
happy(jae).
Then rule
happy(A) :- sings(A).
applies, which means that the next goal to be solved is
sings(A).
with A = jae.
Unfortunately the one-argument predicate sings/1 is nowhere to be found, so you get the same error as for a missing procedure in another programming language.
You have to define sings/1.

Creating calculator in abap

I've build a basic calculator in abap which is pretty simple and knows how to get 2 inputs and calculate them by pressing a push button of the operator( + - / *).
Now I want to make a calculator which gets one input like : "12+5*3-9"
But I really don't know how to start it.
Can anyone help me a little bit please?
Thank you.
You question is related with an algorithm for parsing mathematical strings rather than ABAP. One of them is Shunting-yard.
If you need to short way, you can add your expression into java script function and run it in CL_JAVA_SCRIPT class in ABAP.
Check example ABAP program DEMO_JAVA_SCRIPT_MINI_EDITOR.

VHDL project : create a components and combine to Digital function generator + Create a tester of circuit?

I am a student in a VHDL&Verilog class, so I have assignment in VHDL to build a function generator like shown in the picture Generator with given specifications.
Also I have a PDF file from the professors with current specifications, from where I started to build the Counter, Negator, FSM automata, Memory and the Multiplexor, but I did them separately.
Now the problem is to combine them togeter in Generator and make a test on it?
But I am stucked, because I have never learned this type programming language.
Have you got experence in VHDL and can anyone help me?
Thank you in advance. I apreciate this.

Prolog existence_error for predicate in generated prolog file

I'm having a problem with a program that I'm writing. The program takes an input and generates a prolog program based on it. It generates something like this:
test(A):-condA(A),condB(A).
condA(val).
condB(val).
My problem is that sometimes, there is no condB(val), or condB anywhere in the program, except in the above definition of test. In that case, I got existence_error for condB, when I try to ask test(val), for example. Is there a way to add something to the prolog program that would define condB as false for all values of it's argument?
I'm sorry if this is stupid question, as I'm new to prolog.
You can tell the prolog processor that condB/1 is dynamic:
:-dynamic condB/1.
Answer to your question is simple.
condB(_):-fail.
the symbol '_' is free variable.

How can I call a function random inside other function in prolog?

I'm trying to call the random function inside another function. For example I want to do this assert(fact(random()). But it does not work. How can I insert a random number this way? Thanks.
In prolog there is no concept of functions like you are trying to do in your code. You should do:
random(N), assert(fact(N))
I recommend reading at least first two chapters Learn Prolog Now! to better understand search and unification.

Resources