Hi Cle,

> The Prolog definitions are:
>
>   member(X, [X|_]).
>   member(X, [_|T]) :- member(X, T).
>
>   append([], L, L).
>   append([H|L1], L2, [H|L3]) :- append(L1, L2, L3).

You can directly translate them to Pilog, if you follow the rules:

   1. Define clauses with 'be' in the style of 'de'
   2. Variables start with '@' instead of an uppercase letter
   3. Commas, :- and the final dot are omitted
   4. Lists are surrounded by parentheses instead of brackets
   5. Dotted pairs have a dot instead of '|'
   6. The 'cut' operator is 'T' instead of '!'

With that you get;

   (be member (@X (@X . @)))
   (be member (@X (@ . @Y)) (member @X @Y))

   (be append (NIL @X @X))
   (be append ((@A . @X) @Y (@A . @Z)) (append @X @Y @Z))

(in fact, I copy/pasted that from "lib/pilog.l:117" :-)


> I already fail defining a correct Pilog member. This is, what I already got:
>
>   (be mymember (@ NIL) T)
>   (be mymember (@X @L) (equal (-> @X) (car (-> @L))))
>   (be mymember (@X @L) (mymember @X (cdr (-> @L))))

This is not so bad. The first clause is OK as it is.

In the second clause you are doing it halfway correct. (-> @X) is the
way to access a Pilog binding in a Lisp expression. You can use a
Lisp expression in a clause if that expression has a variable in its
CAR, then the CDR should be Lisp. The second clause could be

   (be mymember (@X @L) (@ = (-> @X) (car (-> @L))))

The third clause, however, is difficult to get straight in this way, as
'mymember' is not a Lisp function. So it is better to use the standard
Prolog method of supplying a pattern like (@X . @) or (@ . @Y) to split
a list, as in the Pilog clauses above.


I really need to document Pilog! I have it on my todo list, but
currently I try to document the database classes first.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to