From "The Little Schemer" to newLISP

Q&A's, tips, howto's
Post Reply
cameyo
Posts: 115
Joined: Sun Mar 27, 2011 3:07 pm
Location: Italy

From "The Little Schemer" to newLISP

Post by cameyo »

I am reading the book "The Little Schemer" (yes, i know newLISP is different from Scheme...but i'm learning)
Until chapter 8 i had no problem to translate the code in newLISP.
But now i have the following function:

Code: Select all

(define (rember-f test?)
    (lambda (a l)
      (cond
       ((null? l) '())
       ((test? (first l) a) (rest l))
       (true (cons (first l) ((rember-f test?) a (rest l)))))))
Calling it in the following way:

Code: Select all

((rember-f =) 'tuna '(shrimp salad and tuna salad))
I got an error:

Code: Select all

ERR: invalid function : (test? (first l) a)
Instead the correct output should be:

Code: Select all

(shrimp salad and salad)
Can you help me to solve this problem?
Thanks
cameyo

newBert
Posts: 149
Joined: Fri Oct 28, 2005 5:33 pm
Location: France

Re: From "The Little Schemer" to newLISP

Post by newBert »

I think the definition of ‘rember-f’ is wrong.
A correct writing of this lambda would be :

Code: Select all

(define rember-f
  (lambda (test? a l)
    (cond
      ((null? l) '())
      ((test? (first l) a) (rest l))
      (true (cons (first l) (rember-f test? a (rest l)))))))

> (rember-f = 'tuna '(shrimp salad and tuna salad))
(shrimp salad and salad)
or (define (rember-f test? a l) (cond and so on ...))
BertrandnewLISP v.10.7.6 64-bit on Linux (Peppermint 9)

cameyo
Posts: 115
Joined: Sun Mar 27, 2011 3:07 pm
Location: Italy

Re: From "The Little Schemer" to newLISP

Post by cameyo »

Thanks newBert.
Wrong method of passing parameters in my function.

Post Reply