Prolog-style unification?

Nielson Family junk at geekabytes.net
Mon Jun 9 10:13:42 EDT 2003


Simon,

See comments in line,

Simon Burton wrote:

>On Sat, 07 Jun 2003 14:38:40 -0600, junk wrote:
>
>  
>
>>Hi Robert,
>>
>>I am working on a Master's Thesis currently where this issue is of 
>>concern.  I would also like to know if there is such a module.
>>
>>In the mean time, I have written my own module which does a pretty good 
>>job of simulating Prolog style calls.  Here is what my syntax looks like 
>>right now:
>>
>>import logic
>>Father = logic.Fact()
>>Father("Seth","Alex")
>>Father("James","Seth")
>>X = logic.LogicalVariable()
>>Y = logic.LgocialVariable()
>>    
>>
>
>too verbose for me. howbout just Var ?
>
This logic code is currently _very_ experimental and the pseudo-syntax 
is still very fluid.  Expect many changes to come.

However, I should point out that I chose verbose names so that anyone 
looking at the code could read immediately what the logic code was.

For example, suppose we chose your syntax and called the logic variables 
'var'.  That works okay using an import statment, but what if you use 
from logic import *?

X = var()
Y = var()

That doesn't seam as clear to me as X = LogicalVariable().  I suppose it 
coulod be shortened to X = LogicVar()

>
>  
>
>>while Father(X,Y):
>>    print X, Y
>>    
>>
>
>Know about iterators?
>
>i'd like to see
>for x,y in Father():
>  print x, y
>
>are you trying too hard to adhere to prolog syntax maybe?
>
I am considering implementing iterators, but I _am_ trying to adhere to 
a prolog syntax as much as possible.  My thesis work is in multiparadigm 
design patterns; in my current research, I have come to the conclusion 
that when attempting to make a language multiparadigm, it is often 
helpful to have each individual paradigm close to the most popular 
language of that paradigm rather than inventing 'new' syntax.

On the other hand, I am also looking at multiparadigm syntax.  I think 
that the iterators you suggest above are a good example of that 
(combining imperative and logical into a single construct).  I am 
considering providing multiple syntax to perform the same functions.  
One syntax would be highly python-esque while the other would be more 
like Prolog (for example, I worked really hard to come up with a way to 
define inferences without creating them as a function; I did this so 
that it would look like Prolog but also that a reader would know 
instantly that it's not a function, its an inference; however, I think 
that in the end, I'll provide _both_ syntax as acceptable options).

>
>  
>
>>print "--------------"
>>
>>Grandfather = logic.Fact()
>>Grandfather(Grandfather.Grandfather, Grandfather.Grandson) (
>>    Father(Grandfather.Grandfather, Grandfather.Son)
>>    Father(Grandfather.Son, Grandfather.Grandson))
>>    
>>
>
>does this use __getattr__ hooks? otherwise where does the attributes of
>Grandfather come from?
>
Yes, this is using the __getattr__ hooks.  There are all sorts of crazy 
things going on behind the scenes to get the constructs to work right.

>
>  
>
>>while Grandfather(X,Y):
>>    print X,Y
>>
>>
>>The output of this is:
>>
>>James Seth
>>Seth Alex
>>------------------
>>James Alex
>>
>>I'm still tracking down bugs all the time, but it's getting pretty good.
>>
>>Would you PLEASE let me know what you think?
>>
>>-- Seth James Nielson
>>    
>>
>
>
>Excellent; i'd like to see more logic for python stuff.
>Please post your code!
>
>Simon Burton.
>
>
>
>  
>
As I said, my code is very very experimental.  I want to get it just a 
little more stable before posting.  I'm hoping to post within a week or 
two (between working on my thesis proposal and working 30 hours a week, 
my time is kinda short ;)

Thanks for your input!  You're very helpful!

-- Seth






More information about the Python-list mailing list