Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bugs/problems with Paul graham's article on the roots of lisp

51 views
Skip to first unread message

Abdullah Abdul Khadir

unread,
Aug 2, 2009, 9:48:01 AM8/2/09
to
Hi,
I am fairly new to lisp and I am currently reading Paul graham's
article on the roots of lisp at http://www.paulgraham.com/rootsoflisp.html.
I was reading the complete article (postscript) and I found a few
problems with the functions referred there, though, the code he posted
at http://lib.store.yahoo.net/lib/paulgraham/jmc.lisp is alright. One
of the issues was with the lambda form which was resolved by
comp.lang.lisp
at
http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/1861e201b6eabd33/24f81737975355bb?lnk=gst&q=lambda+form#24f81737975355bb.

Here is the current problem I am facing,
Quoting from Paul's article,
" There is another notation for functions that enables the function to
refer to itself, thereby giving us a convenient way to define
recursive functions. The notation

(label f (lambda (p1 ... pn) e) )

denotes a function that behaves like (lambda (p1 ... pn) e), with the
additional property that an occurrence of f within e will evaluate to
the label expression, as if f were a parameter of the function"

Well, the label function does not exist
I tried,
> (label subst. (lambda (x y z)
(cond ((atom z)(cond ((eq z y) x)
('t z)))
('t (cons (my-subst x y (car z))
(my-subst x y (cdr z)))))))

And received the error,

Error in KERNEL::UNBOUND-SYMBOL-ERROR-HANDLER: the variable SUBST. is
unbound.
[Condition of type UNBOUND-VARIABLE]

I checked that there is a labels function. Is it the same thing? If
yes a few examples will be really helpful.

Thank You,

Pascal J. Bourguignon

unread,
Aug 2, 2009, 10:13:47 AM8/2/09
to
Abdullah Abdul Khadir <abdull...@gmail.com> writes:

> Hi,
> I am fairly new to lisp and I am currently reading Paul graham's
> article on the roots of lisp at http://www.paulgraham.com/rootsoflisp.html.
> I was reading the complete article (postscript) and I found a few
> problems with the functions referred there, though, the code he posted
> at http://lib.store.yahoo.net/lib/paulgraham/jmc.lisp is alright. One
> of the issues was with the lambda form which was resolved by
> comp.lang.lisp
> at
> http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/1861e201b6eabd33/24f81737975355bb?lnk=gst&q=lambda+form#24f81737975355bb.
>
> Here is the current problem I am facing,
> Quoting from Paul's article,
> " There is another notation for functions that enables the function to
> refer to itself, thereby giving us a convenient way to define
> recursive functions. The notation
>
> (label f (lambda (p1 ... pn) e) )
>
> denotes a function that behaves like (lambda (p1 ... pn) e), with the
> additional property that an occurrence of f within e will evaluate to
> the label expression, as if f were a parameter of the function"
>
> Well, the label function does not exist

... anymore. Yes.


> I tried,
>> (label subst. (lambda (x y z)
> (cond ((atom z)(cond ((eq z y) x)
> ('t z)))
> ('t (cons (my-subst x y (car z))
> (my-subst x y (cdr z)))))))
>
> And received the error,
>
> Error in KERNEL::UNBOUND-SYMBOL-ERROR-HANDLER: the variable SUBST. is
> unbound.
> [Condition of type UNBOUND-VARIABLE]
>
> I checked that there is a labels function. Is it the same thing? If
> yes a few examples will be really helpful.

Yes, it provides the same functionality. Only for several functions,
that may call each other.

Nowadays we would write:

(labels ((subst (new old tree)
(cond ((consp tree) (cons (subst new old (car tree))
(subst new old (cdr tree))))
((eq old tree) new)
(t tree))))
(subst '42 'x '(+ (* 4 x x) (* -5 x) 3)))

--> (+ (* 4 42 42) (* -5 42) 3)


But if you have an old program and you want to run it in CL, you may
easily define the missing operators, to avoid modifying the old program:

(defmacro label (name (lambda arguments &body body))
(assert (eq 'lambda lambda))
`(labels ((,name ,arguments ,@body))
(function ,name)))

(funcall (label my-subst (lambda (x y z)


(cond ((atom z)(cond ((eq z y) x)
('t z)))
('t (cons (my-subst x y (car z))
(my-subst x y (cdr z)))))))

'42 'x '(+ (* 4 x x) (* -5 x) 3))
--> (+ (* 4 42 42) (* -5 42) 3)


--
__Pascal Bourguignon__

Pascal J. Bourguignon

unread,
Aug 2, 2009, 10:15:03 AM8/2/09
to
Abdullah Abdul Khadir <abdull...@gmail.com> writes:
> I am fairly new to lisp and I am currently reading Paul graham's
> article on the roots of lisp at http://www.paulgraham.com/rootsoflisp.html.
> [...]

> Well, the label function does not exist

Also have a look at:

http://www.informatimago.com/develop/lisp/small-cl-pgms/wang.html

--
__Pascal Bourguignon__

Abdullah Abdul Khadir

unread,
Aug 3, 2009, 2:10:16 PM8/3/09
to
On Aug 2, 7:15 pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:

> Abdullah Abdul Khadir <abdullah....@gmail.com> writes:
>
> >     I am fairly new to lisp and I am currently reading Paul graham's
> > article on the roots of lisp athttp://www.paulgraham.com/rootsoflisp.html.
> > [...]
> > Well, thelabelfunction does not exist

>
> Also have a look at:
>
> http://www.informatimago.com/develop/lisp/small-cl-pgms/wang.html
>
> --
> __Pascal Bourguignon__


Thank You Pascal for answering I will check out whatever you have
posted. It looks very interesting, indeed.
In fact I have bookmarked most of what McCArthy wrote and I plan on
going through it thoroughly.

Thank You once again,
Abdullah

0 new messages