## [squeak-dev] [ANN] Prolog update

rabbit rabbit at callistohouse.org
Tue Oct 4 22:19:49 UTC 2022

This is greek to me. Would you be interested in loading ELinda and
implementing Linda match: using Prolog? I would be **very** interested
to see it!

Have a good one; keep it, light.
Kindly,
rabbit
. .. … ‘…^,^

Sent from Callisto House :: decentralized mobile homeless solutions

On 10/4/22 18:13, Stéphane Rollandin wrote:
>> Could this be easily done using Prolog?
>
> Very easily. Prolog is the king of pattern-matching!
>
> For example, the append/2 predicate is implemented as
>
>     logicAppend
>
>     append([], X, X).
>     append([H | X], Y, [H | Z]) :- append(X, Y, Z).
>
> and this is the *actual code* for the method #logicAppend in class
> Prolog.
>
> Now equipped with this, you can do
>
>     append([a, b], [c, d], List)
>
> and you will get the unification (Prolog's uber-notion for
> pattern-matching)
>
>     List = [a,b,c,d].
>
> So far, so good. But you can also do
>
>     append(A, B, [1, 2])
>
> which will give you the three ways two lists A and B can be appended
> to get [1,2]. The answer will be
>
>     A = []. B = [1,2].
>     A = [1]. B = [2].
>     A = [1 2]. B= [].
>
> But there is more. You can in fact use any pattern in the arguments,
> and unification will tell you what works.
>
> For example,
>
>     append([X | T], [a], [Z, Z, Z])
>
> will give you the only way it is possible to append [a] to some [X |
> T] (that's a cons cell with car X and cdr T) and get some [Z, Z, Z] as
> result (note that only the capitalized terms are variables). It is:
>
>     X = a. T = [a]. Z = a
>
> The code snippets above can be directly tested in the REPL you get by
> evaluating
>
>     Prolog new openGui
>
> Best,
>
> Stef
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20221004/d22cf002/attachment.html>