Welcome! Log In Create A New Profile

Advanced

Amzi Prolog

Posted by DJ_Paulo 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Amzi Prolog
September 06, 2012 03:11PM
Hi all

Does anyone else have issues with Amzi Prolog not recognising built-in predicates like "member" and "fail"?
From day one I've had to manually define the member predicate and now it says that fail is not defined as well.

Kind regards
Paulo
avatar Re: Amzi Prolog
September 07, 2012 07:46AM
Hi Paulo,

"Member" and "fail" are not built-in predicates in Amzi Prolog, that is why you have to define them yourself. Other Prolog packages have them included as built-in predicates (basically predefined Prolog predicates stored in a library). The issue here is the same as in C where you have different versions of C, like ANSI C, Borland C, K&R C etc. with the same basic language constructs, but different built-in functions. Look at the AMZI help file for the defined predicates it has.

Cheers
Re: Amzi Prolog
September 07, 2012 09:17AM
Ah ok that would explain it. I tried to Google it and all examples seem to use these predicates regardless, which is why I thought that I need to load a library of some sort.
What is the best way of defining the fail predicate?
Re: Amzi Prolog
September 07, 2012 09:41AM
Currently I'm replacing the word "fail" with "1 \== 2"
avatar Re: Amzi Prolog
September 07, 2012 10:08AM
Sorry, my bad - "fail" is defined in AMZI Prolog as a predicate (along with "true" for what it's worth). I did not use them that much - opting rather for "cut" (!) as it prevents backtracking and is thus more efficient (I think). I have to be honest here, I am not 100% sure about the use and effect of cut at this stage - need to study this some more. Maybe using "fail" for program control is a better option.

With regard to Prolog examples on the interwebs, I found that (almost) nobody uses AMZI Prolog, but they rather use SWI-Prolog (http://www.swi-prolog.org/) which has a very large number of added features and predicates compared to AMZI, which explains why most of the Prolog code on the interwebs won't work directly in AMZI. It took me a while to figure this out.
Re: Amzi Prolog
September 07, 2012 10:32AM
That's weird because I get an error saying that the fail predicate is not defined.

I find Amzi very frustrating to use as well. It is so flippin fussy about everything and the error messages are terrible.
Having worked with cool IDEs like MS Visual Studio, I guess I've been spoilt smiling smiley

I can't seem to be able to compile my code. Instead I've been running everything as an interpreted .pro file.
The problem with this is that often it runs out of memory and the only way to get around it (according to Amzi) is to increase the stack space or compile the code.
Just can't figure out how to compile the code properly sad smiley
avatar Re: Amzi Prolog
September 07, 2012 10:53AM
DJ_Paulo Wrote:
-------------------------------------------------------
> Currently I'm replacing the word "fail" with "1
> \== 2"

What you defined with "1\==2" is "true". From the AMZI docs "X \== Y succeeds if X and Y are not identical. " If you want it to fail then it must be "1\==1" or something like that. Or not??
avatar Re: Amzi Prolog
September 07, 2012 11:02AM
DJ_Paulo Wrote:
-------------------------------------------------------
> That's weird because I get an error saying that
> the fail predicate is not defined.
I'm just guessing here, but how are you using it? Post a code snippet perhaps. I am not an expert at Prolog by a long shot, but maybe I can spot something wrong.


> I find Amzi very frustrating to use as well. It is
> so flippin fussy about everything and the error
> messages are terrible.
Yes, I agree. At least we are in the same boat. Mine would crash randomly as well with not explanation. and sometimes give these random errors like Error 144 or 114 or something with not indication of what caused it.


> I can't seem to be able to compile my code.
> Instead I've been running everything as an
> interpreted .pro file.
Me as well. I gave up on that issue a long time ago.


> The problem with this is that often it runs out of
> memory and the only way to get around it
> (according to Amzi) is to increase the stack space
> or compile the code.
> Just can't figure out how to compile the code
> properly sad smiley
I tried the stack space trick as well. Took me a solid week to figure out how to do it as the documentation is poor. It did not help at all - it actually made AMZI more unstable in my case and it would slow down as well. The most effective way I found is to use cut (!) to limit backtracking and save memory that way.
Re: Amzi Prolog
September 07, 2012 11:58AM
Sorry, I typed it wrong earlier, I meant to type "1 \== 1".

I really don't get this! Sometimes it complains about fail not being defined, then at other times everything just runs.
I've replaced the "fail;true" code with a not( Condition) now and it seems to work.

I'm a bit worried about the exam. I really don't know what to expect in it.
It's difficult to remember syntax etc.
avatar Re: Amzi Prolog
September 07, 2012 12:09PM
DJ_Paulo Wrote:
-------------------------------------------------------
> Sorry, I typed it wrong earlier, I meant to type
> "1 \== 1".
Right, that makes sense now.


> I really don't get this! Sometimes it complains
> about fail not being defined, then at other times
> everything just runs.
Ok, so I have had similar problems before with other predicates not working. I think the issue is not with the use of the "fail" predicate itself, but if you make a mistake with another predicate somewhere else before you use "fail" then it returns an error about "fail" for some reason and not the actual predicate error. It's one of those Idiosyncrasies of AMZI I think.


> I'm a bit worried about the exam. I really don't
> know what to expect in it.
> It's difficult to remember syntax etc.
Me too. I am already having sleepless nights about it. I am trying to better understand how Prolog actually works compared to a trail and error approach as I have used in the assignments so far as that won't work in the exam. Hopefully we get a sample exam paper to see what the questions are like.
Re: Amzi Prolog
September 07, 2012 12:23PM
I hope so too, because then we'll have a better idea as to how to prepare for the exam.
Really hope that getting syntax wrong won't weigh heavily on the marks.
Sorry, only registered users may post in this forum.

Click here to login