• Please review our updated Terms and Rules here

Lisp 1.5 COND Multiple Expressions?

cr1901

Veteran Member
Joined
Dec 28, 2011
Messages
817
Location
NJ
Anybody here remember Lisp 1.5, specifically remember how to program using it? I know it's quite a ways back, but I've been studying it... possibly even thinking about implementing my own.

Modern Lisps such as Scheme allow COND to have multiple statements to evaluate after each condition; this contrived example demonstrates, showing the return value is that of the last expression of each possible condition:
Code:
> (define (test-cond a)
    (cond (a (+ 0 1) (+ 3 4))
          (#t (+ 5 6) (+ 7 8))))
> (test-cond #t)
7
> (test-cond #f)
15
>

Lisp 1.5 programmer's manual is available online. It gives basically enough information to implement one's own Lisp. However, on page 71 (79 in the PDF), Lisp 1.5's evaluator is implemented in terms of itself, and COND's implementation (using EVCON) appears to only be able to evaluate a single expression per condition:

Code:
eval[form; a]= [...
eq[car[form]; COND]->evcon[cdr[form]; a]; 
...]

evcon[c; a]= [null[c]->error [A3];
eval[caar[ c]; a]->eval[cadar [a];a];
T->evcon[cdr [ c];a]]

To get the desired results (evaluate all expressions), it seems that I should use cdar instead of cadar as a starting point:
Code:
> (cadar (cdr '(cond (a (+ 0 1) (+ 3 4)) (#t (+ 5 6) (+ 7 8)))))
'(+ 0 1)
> (cdar (cdr '(cond (a (+ 0 1) (+ 3 4)) (#t (+ 5 6) (+ 7 8)))))
'((+ 0 1) (+ 3 4))

Can anyone who has used Lisp 1.5 confirm this is indeed the case? This is an awfully specific question for an old topic, so I'm not getting good answers from search engines. I think my understanding of the M-expressions are correct, but I'm not certain. Additionally COND 1.5 in Lisp appears to be internally implemented in machine code (FSUBR), so I'm not sure if the machine code is doing anything "funny" that would be difficult to express in Lisp.

Why is this important? Well, it isn't all that much really. The behavior can be easily worked around by just wrapping desired statements into a PROG expression or multiple small functions. Just that if I do happen to make a Lisp 1.5, it would be nice to try to run some ancient code- so making sure behavior is consistent would be ideal.
 
Back
Top