I'd like to entertain you with a new subject: logic programming and
constraint-propagation features in Python.
I teach Python and advocate it often. One argument I use is that you
have several "programming paradigms" available in Python. You need
simple things and scripts? Use procedural programming, with variables
and functions. You need more structure? Use object-oriented programming.
You miss Lisp and need to process lists? use (some) functionnal
programming. You need concurrency? Look at Python 2.2's future and
stackless. It's all there. Mix'n match as you wish, you're not tied to
a specific approach, just use what fits best your model and data. No
need to mix languages.
Now, what if you need logical programming? Use pyprolog. And copy
your data back-and-forth from prolog-space to python space. Or look
at Mozart/Oz. Yeah, it's all there too: procedure, functions, objects,
concurrency, logic, constraint-propagation, even distribution and
security.
Right, but the syntax is... difficult. I'm sorry to have to tell
Mozart folks lurking here, that I'm a big fan of "indent-what-you-mean"
and will have trouble telling our new programmers that this complicated
syntax is good for them. And that brackets have different meanings
depending on where they are.
And Python already has a user-base that's increasing at rocket-speed.
When teaching Python I often tell people "if you need to code something
in Python, go to google first, you'll probably find it there and move
to more important matters".
As you already understood, I am thinking about implenting some
logical/constraint-propagation features on Python. My (rough)
understanding is that is would be doable on top of
microthreads/stackless/generators.
I am looking for interested people to form a Logic-SIG or CLP-SIG.
You think this is a great idea? You think this is stupid? Please
speak up! If you have no idea what I am talking about, don't worry,
I'll try to post an example here this week-end.
Waiting for your comments.
--
Nicolas Chauvat
http://www.logilab.com - "Mais oů est donc Ornicar ?" - LOGILAB, Paris (France)
That's putting it nicely.
Not that I've done very much besides 'Hello, world' in the Mozart
tutorial, though.
Gerhard
--
mail: gerhard <at> bigfoot <dot> de registered Linux user #64239
web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
Laura Creighton
Count me in.
> I'll try to post an example here this week-end.
Looking forward to it, I'll have a counter example on Monday. :-)
Joel
I would be very interested in a finite domain constraint slover
in/connected-to Python.
though-not-volunteering-to-implement-it-<wink>-ly y'rs
Benji York
Includes fintie domain backtracking search (with optional forward
checking, domain ordering, and variable ordering); hill-climbing
min-conflicts search; examples from map coloring, n-queens, and the
zebra puzzle.
-Peter
benji...@cal-na.com (Benji York) wrote in message news:<59667b81.02032...@posting.google.com>...
Go for it!
Logic programming (or even something similar, with implicit
backtracking etc.) would be very nice to have, IMO. The backtracking
stuff itself ought to be easy to implement (efficiently, even) with
generators.
(So, yes, I'm interested :)
--
Magnus Lie Hetland The Anygui Project
http://hetland.org http://anygui.org
Rather. And makes one wonder if the way to go would not be to compile
python source syntax to the Oz or Erlang VM... while adding to it
something in the way Screamer adds to Common Lisp. (Erlang has a nice
syntax, BTW).
Another thing I am missing in python is Prolog-type metaprogramming
and/or lisp-type macro; first step would be S-expressions; the closest
python provides are the syntax trees from the parser module, but...
well, they really don't provide a similar facility. Now what about
defining a two-way translation to a syntax Lisp or Scheme systems could
read as S-expressions that could then be intelligently manipulated
by lisp-technology macros ?
> I am looking for interested people to form a Logic-SIG or CLP-SIG.
Count me in, especially for useless commenting :)
Regards,
Boris Borcic
--
Python >>> filter(lambda W : W not in "ILLITERATE","BULLSHIT")
does the use of generators imply that I need Python 2.2?
--
Robin Becker
There are some very interesting examples of using generators to do
backtracking in, I believe, test_generators.py in the distribution.
As I remember, both n-queens and knights tour examples are present.
Terry J. Reedy
I propose to add a few keywords, hopefully I'll be using terms
consistent with Prolog, but it's been a while, and other comments are
welcome.
First, add 'goal' to define goals, like functions:
goal sibling(X,Y):
parent(Z,X)
parent(Z,Y)
A goal looks like a function call in the code.
adam, betsy, clide, dave, edith = range(5)
assert(parent(adam, clide)) # needs help...
assert(parent(adam, dave))
def test1():
print "Ah!"
sibling(clide, dave)
print "Yes!"
>>> test1()
Ah!
Yes!
Then add 'cut' and 'fail' as statements:
def test2():
sibling(clide,X)
print X
cut
print "-cut-"
fail
>>> test2()
3
-cut-
Without the cut statement the output would look like this, because clide
is considered a sibling of himself:
def test3():
sibling(clide,X)
print X
fail
>>> test3()
3
2
Unlike Python functions, the same goal could be defined more than one
way:
goal sibling(X,Y):
mom(Z,X)
mom(Z,Y)
goal sibling(X,Y):
dad(Z,X)
dad(Z,Y)
With my limited Python experience I get the impression that the variable
'_' is frowned upon, so I would replace it with the keyword 'Any'.
goal isachild(X):
parent(Any,X)
Goals can return values, so they can be used like functions:
goal sibling2(X,Y):
parent(Z,X)
parent(Z,Y)
return Z
def test4():
p = sibling2(clide,dave)
print p
>>> test4()
0
Almost every Prolog book has an example of list membership, but while
the slicing operation can be done simply in Prolog:
member(X,[X|_]).
member(X,[_|Y]) :- member(X,Y).
The same kind of thing doesn't seem to fit Python:
goal member(X,[X|_]): pass
So it would have to be done with a some statements:
goal member(X,L):
if (len(x) == 0):
fail
if (X != L[0]):
fail
goal member(X,L):
member(X,L[1:])
Comments?
Joel
Oops.
goal member(X,L):
if (len(L) == 0):