The explicit-evaluation paradigm is NOT new!

84 views
Skip to first unread message

Yi Dai

unread,
Jul 19, 2013, 6:34:43 AM7/19/13
to kl...@googlegroups.com
Hi,


I recently started playing with Prolog.  When I came to the predicate 'is/2', I suddenly realized that Prolog has embraced the explicit-evaluation paradigm for such a long time!

To show you an example.  Below are two definitions are length:

length1([], 0).
length1([_ | Xs], 1 + N) :- length1(Xs, N).

length2([], 0).
length2([_ | Xs], N) :- length2(Xs, M), N is 1 + M.

Querying `length1([1, 2], N)' gives N = (1 + (1 + 0)), while querying `length2([1, 2], N)` gives N = 2.  In  Prolog, computation is *more* symbolic.  Inputs and output of a predicate are all (syntactic) terms.  So in `length1', the recursive call will return a term ((1 + 0) in the example) bound to the variable N, then the original call will construct a new term by substituting (1 + 0) for N in the pattern (1 + N) and gives (1 + (1 + 0)) as result.  In `length2', however, after the recursive call, we ask Prolog to evaluate the arithmetic expression by means of the `is' predicate (this is quite similar to an explicit call of `eval'), the result of the evaluation will be bound to the variable N, which is returned by the original call.

Thanks to this "program is data" (note that I do not use "program as data" since in Prolog you do not need any `quote' operator to turn program into data), Prolog offers very powerful meta-programming features.  Moreover, there is no variable capturing, no triviality of equational theory.  It is a new land.  I highly recommend you guys explore it.


Best regards,


Yi

Andres Navarro

unread,
Aug 16, 2013, 12:10:42 PM8/16/13
to kl...@googlegroups.com
Sorry I took so long to reply,

While explicit evaluation is not new, I think John Shutt's work on Kernel certainly shines a new
light on it, and uncovers a number of hidden assumptions in certain arguments.
I recommend everyone here to read recent posts in John's Blog about the topic (or if you are
feeling brave reading his phd dissertation, which discuss it further).

As for the prolog example, while it's true that you can decide if you want to "evaluate" or not an
expression, you don't have control over the environment as you do in Kernel.  Moreso, Prolog
works with unification & sustitution (not environments) so it isn't exactly comparable with Kernel
in that regard. 
A closer example may be the use of quote and eval in scheme or common lisp, but there again
there is little or no control of the environment in which that evaluation takes place. 

This shouldn't be taken as putting Prolog down, of course.  It's actually quite nice and should be
certainly studied carefully by every programmer.  I got introduced to the ideas in SICP and later
got some hands-on experience in a couse about PL Paradigms at college and found it really
interesting.

As a side note:
I think the idea of first class environments and the possibility of using them as arguments to eval
is a more central idea to Kernel than even operatives/fexprs.  Of course the idea isn't new either,
some of the reflective lisps had that already years ago.  John's work adds however certain
mechanisms of encapsulation of environments which (in principle) open the way to possible
optimizations/compilation and justifies them in rather elegant way in the Kernel Report.  Whether
all of these ideas will pan out, however, is still an open question.

Regards,
Andrés


 


--
You received this message because you are subscribed to the Google Groups "klisp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to klisp+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages