Hi,

I used AI::Prolog once briefly, and that's the extent of my logic programming
knowledge.  There do seem to be a few Perl 6 features that may be useful for
logic programming, although I'm not really qualified to judge.

How would one assert facts and rules in Perl6? How would one know
that a variable is a logic variable and not a normal one? Assignment
to a logic variable which is still subject to rebinding could break
code. On the other hand, using normal variables for logic variables
could let us use objects for them and I think this might get us
contraint programming (long story).

"let" variables and "hypothetical" assignments within rules may be a
good starting point.

Hypothetical variables are mentioned here:
http://dev.perl.org/perl6/doc/design/syn/S04.html#Definition_of_Success

While they usually occur within rules, hypothetical assignments can
be to a target variable:
http://dev.perl.org/perl6/doc/design/syn/S05.html#External_aliasing

and "let" can now be used in any other closure.

More details in A05:
http://dev.perl.org/perl6/doc/design/apo/A05.html#Hypothetical_Variables,_er_Values

There's also the question of non-logical behavior in logic
programming. What happens if you try to use math in Perl6 logic
programming? Generally speaking, math is "non-logical" in the sense
that it's used in Prolog (see the aforementioned article). Opening
and reading from a file is also non-logical (you can't backtrack over
it). How are those issues to be handled?

Closures may have an "undo" trait which should be written to revert
the side-effects of the closure when it receives an UNDO control
exception (the block fails, see Definition of Success above).

http://dev.perl.org/perl6/doc/design/syn/S04.html#Closure_traits

For file reading the undo would seek back to the correct point.
This does require the programmer to code the undo operation, which
may not be possible (with non-seekable handles for examples).

Are there other languages that blend logic and imperative styles that
can be stolen from?

Perl6 grammars may be able to assist with this, but grammars (as far
as I can tell) are still based around strings and not data
structures. Admittedly, Prolog is essentially a fancy string
rewriting system, but it's not clear how the grammars would be
applied to this problem.

There's some information about this in S05, with more info promised:

http://dev.perl.org/perl6/doc/design/syn/S05.html#Matching_against_non-strings

Brad

--
Dohaku's wife suffered some severed fingers.  Dohaku's wound was a severed
neck bone, and since only his throat remained intact, his head hung down in
front.  Now boosting his head up with his own hands, Dohaku went off to the
surgeon's.                        -- Hagakure http://bereft.net/hagakure/

Reply via email to