0

im trying to get a lambda function from this list of lists '((0 4) (lambda (x) (+ x 100)))

if i do (car (cdr list) ) i get (lambda (x) (+ x 100)), and im using (car (cdr list) ) to get the lambda function to the parameters of another function that uses it but i get the error

application: not a procedure;
 expected a procedure that can be applied to arguments
  given: (lambda (x) (+ x 100))

If instead of (car (cdr list) ) i write (lambda (x) (+ x 100)) it works, but i need to get it from the second element of the list of lists

Patrick C
  • 1
  • 1
  • 2
    You don't have a function, you have a bunch of symbols... – Shawn Nov 09 '22 at 05:21
  • 3
    Does this answer your question? [What is the difference between quote and list?](https://stackoverflow.com/questions/34984552/what-is-the-difference-between-quote-and-list) – Shawn Nov 09 '22 at 05:22
  • how would i transform this symbols to an actual lambda function that i can use in another function? im trying with let and define but it doesnt works – Patrick C Nov 10 '22 at 16:06

1 Answers1

0

The second entry in the list '((0 4) (lambda (x) (+ x 100))) is a list of the symbol lambda the list (x) and the list (+ x 100). This is because the expression (lambda (x) (+ x 100)) is not evaluated due to the leading quote.

When the list is defined using `((0 4) ,(lambda (x) (+ x 100))) the lambda expression is evaluated. Now the list contains (0 4) as the first entry and a function as the second. Then the second entry can be called as the following example demonstrates:

(define lst `((0 4) ,(lambda (x) (+ x 100))))
(print ((car (cdr lst)) 10))
Johann Schwarze
  • 161
  • 1
  • 4