FAQ
If anyone is interested, I'm working on (yet another) project to implement a Prolog-like syntax in

I know there are a few attempts that have been made at this, but for various reasons (usually lack
of rich data structures), I have not felt that I could build on those previous attempts, though I
confess that Prolog::Alpha is rather interesting to me.

The nature of the above post is to nail down the underlying data structure before I go willy-nilly
coding something and find myself coded into a corner.

Cheers,
Curtis "Ovid" Poe

=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,\$_ for reverse q.e...q.n.;for(@A){\$_=unpack(q|c|,\$_);@a=split//;
shift@a;shift@a if \$a[\$[]eq\$[;\$_=join q||,@a};print \$_,\$/for reverse @A

__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com

## Search Discussions

•  at Jul 16, 2002 at 7:36 pm ⇧
This is a follow up to my previous email re: http://www.perlmonks.org/index.pl?node_id=181980.

Since I'm trying to create "Perlog", a Prolog-like implementation in Perl, I've run across an
issue which could cause some problems. Specifically, are variadic (varying number of arguments)
predicates allowed in Prolog? In other words, can someone do this:

foo( bar, baz ).
foo( bar, quux, camel ).

I think I have the data structure issue figured out, but if I have to allow for the above syntax,
I'm going to have problems auto-generating code.

I'm *assuming* that anything approaching variadic predicates would be handled with lists, thereby
avoiding the problem:

foo( bar, [ baz ] ).
foo( bar, [ quux, camel ] ).

If variadic predicates are allowed, what would they be used for? If I can safely exclude them
from the Perl implementation, this would make life much easier.

Cheers,
Curtis "Ovid" Poe

=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,\$_ for reverse q.e...q.n.;for(@A){\$_=unpack(q|c|,\$_);@a=split//;
shift@a;shift@a if \$a[\$[]eq\$[;\$_=join q||,@a};print \$_,\$/for reverse @A

__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com
•  at Jul 17, 2002 at 10:46 am ⇧
Ovid writes:
Since I'm trying to create "Perlog", a Prolog-like implementation
in Perl, I've run across an issue which could cause some problems.
Specifically, are variadic (varying number of arguments) predicates
allowed in Prolog?
While I always have done some (simple) Prolog, unfortunately it got
rusty. It seems to be better to ask such a question on a Prolog
list. Anyway, I have never used variadic variables and I would be
very surprised if the are allowed in Prolog.
In other words, can someone do this:
foo( bar, baz ).
foo( bar, quux, camel ).
Yes this is allowed in Prolog. But, this are two DIFFERENT predicates
like "@bar" is different from "%bar". Inside Prolog remembers them as
foo/2 or foo/3.

Perl. Try to implement logical programming in Perl. Just a matter
of reprogramming your mind;-) If you stop to think "it has to be
like Prolog" things get easier. BTW, appart from Prolog logic-based
languages like Mercury have there appeal as well.
If you decide that giving two predicates the same name is not allowed,
go ahead. Just few yourself as a language designer and not only as
Prolog implementor.

Andreas Marcel
•  at Jul 17, 2002 at 4:40 pm ⇧

At 21:35 16/07/2002, Ovid wrote:
This is a follow up to my previous email
re: http://www.perlmonks.org/index.pl?node_id=181980.

Since I'm trying to create "Perlog", a Prolog-like implementation in Perl,
I've run across an
issue which could cause some problems. Specifically, are variadic
(varying number of arguments)
predicates allowed in Prolog? In other words, can someone do this:

foo( bar, baz ).
foo( bar, quux, camel ).
Yes. they're essential. Your two predicates would
be foo/2 and foo/3.
...
If variadic predicates are allowed, what would they be used for? If I can
safely exclude them
from the Perl implementation, this would make life much easier.
You certainly cannot exclude them from any implimentation
of PROLOG and call it PROLOG - for examples of use, see any
number of textbooks. One thought is a routine that calls
itself with an argument: if there is no argument, it's the
first call. Agh, not clear, sorry, but I've had a very
busy weekend, and am still a tad drunk (just married).

Lee
•  at Jul 17, 2002 at 5:28 pm ⇧

--- Lee Goddard wrote:
At 21:35 16/07/2002, Ovid wrote:
In other words, can someone do this:

foo( bar, baz ).
foo( bar, quux, camel ).
Yes. they're essential. Your two predicates would
be foo/2 and foo/3.
Aah. Thanks.
You certainly cannot exclude them from any implimentation
of PROLOG and call it PROLOG - for examples of use, see any
number of textbooks. One thought is a routine that calls
itself with an argument: if there is no argument, it's the
first call. Agh, not clear, sorry, but I've had a very
busy weekend, and am still a tad drunk (just married).
Congratulations! You're a brave man. Not about getting married, but about sending email while
drunk. I've had to apologize on more than one occassion for that (though I got a date out of it
once :)
Yes I have. Unfortunately, they do not support rich enough data structures. Currently, none of
them appear to support lists and I don't think they allow facts as arguments to other facts.
Mathematical operations are out the window with them. Language::Prolog *might* be extensible
enough, but I decided not to go that route for a couple of reasons.

1. I don't really want to reimplement Prolog. I want to use a Prolog model to create Perl
programs. For example, returning "no" on false is useless to most Perl programmers. The logic of
Prolog is so straightforward, though, that I thought it would be a good model.

2. The other reason is fairly simple: I'm hardly a Prolog expert. I've worked with quite a few
programming languages, but all of them have been imperative or object oriented. Prolog was my
only excursion into Logic programming and my functional programming knowledge is pretty limited.

There are many who are more qualified than I to write AI::Perlog, but no one seems to be putting
any time towards it. It's kind of like my online CGI programming course. No on seemed to want to
write a *good* CGI course (online, that it), so I concluded that if I wanted it done, I had to do
it myself.

I have work started on an AI::Perlog distro, but presently I can only add facts. When I can start
adding simple rules and support a variety of data types, I'll release an Alpha, but I'm pretty
booked up for the next week or so, so don't hold your breath!

I also expect to throw away several versions (I've already tossed one) while learning this, so
this could be a long process.

Cheers,
Curtis "Ovid" Poe

=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,\$_ for reverse q.e...q.n.;for(@A){\$_=unpack(q|c|,\$_);@a=split//;
shift@a;shift@a if \$a[\$[]eq\$[;\$_=join q||,@a};print \$_,\$/for reverse @A

__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com
•  at Jul 17, 2002 at 7:09 pm ⇧

At 19:28 17/07/2002, Ovid wrote:
There are many who are more qualified than I to write AI::Perlog, but no
one seems to be putting
any time towards it.
Maybe Language::Perlog would be a better namespace?
Easier for people to find? (But then Perlog is a
not-easy-to-find name, I guess).
I also expect to throw away several versions (I've already tossed one)
while learning this, so
this could be a long process.
Hey, well keep us posted - it sounds interesting.

I learnt PROLOG on my MSc course at Uni, and
enjoyed it alot -- sadly rarely use it since I'm
working in the boring Internet field atm. The
best book I found was Bratko:

Prolog Programming for Artificial Intelligence (Ivan Bratko)
http://www.amazon.co.uk/exec/obidos/ASIN/0201403757/ref=sr_aps_books_1_1/202-2061866-6899823

Good luck
lee (now slightly more hungover)
•  at Aug 19, 2002 at 5:37 pm ⇧
For those who may be curious, some of the initial work on AI::Perlog is coming along nicely.

The code in http://www.perlmonks.org/index.pl?node_id=191060 basically implements the following
Prolog program.

steals(PERP, STUFF) :-
thief(PERP),
valuable(STUFF),
owns(VICTIM,STUFF),
not(knows(PERP,VICTIM)).
valuable(gold).
valuable(rubies).
owns(merlyn,gold).
owns(ovid,rubies).

We only have the ability to add basic facts, do boolean queries and simple unification (it can't
yet unify across more than one predicate).

To do:

1. Implement lists.

\$pg->add_fact( owns => 'Ovid', [qw/foo bar baz/] );

2. Embeddeding facts in other facts.

\$pg->add_fact( owns => 'Ovid', book( 'Learning Perl' ) );

3. Easy-to-create rules.

Haven't determined the syntax yet.

4. Unification across multiple predicates

I can't list a sample in Perl until I get the syntax for 3 down.

If anyone's interested in helping, let me know.

Also, the API is going to change (probably). All user-defined predicates will have to start with
a lower case letter. This means that I can simply designate upper case predicates as reserved
rather than trying to make the user memorize a bunch of built-ins such as 'head', 'tail',

that I listed above), so you'll have to rely on code samples that I've posted and the test suite
that's included.

Cheers,
Curtis "Ovid" Poe

=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,\$_ for reverse q.e...q.n.;for(@A){\$_=unpack(q|c|,\$_);@a=split//;
shift@a;shift@a if \$a[\$[]eq\$[;\$_=join q||,@a};print \$_,\$/for reverse @A

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com

## Related Discussions

Discussion Overview
 group ai categories perl posted Jul 16, '02 at 4:34p active Aug 19, '02 at 5:37p posts 7 users 3 website perl.org

### 3 users in discussion

Content

People

Support

Translate

site design / logo © 2021 Grokbase