From "The Little Schemer" to newLISP

Started by cameyo, May 25, 2020, 02:15:13 AM

Previous topic - Next topic

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:
(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:
((rember-f =) 'tuna '(shrimp salad and tuna salad))
I got an error:
ERR: invalid function : (test? (first l) a)
Instead the correct output should be:
(shrimp salad and salad)
Can you help me to solve this problem?

Thanks

cameyo

newBert

#1
I think the definition of 'rember-f' is wrong.

A correct writing of this lambda would be :

(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 ...))
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>

cameyo

#2
Thanks newBert.

Wrong method of passing parameters in my function.