4

How can I evaluate an s-expression only by the first term?

(define (fn x y) (print x) (print y))
(eval '(fn a b))

I am trying to evaluate something like this on a bigger expression but the interpreter is complaining that a and b variables don't exist (unbound variable a).

Is there something I can do to leave symbols as they are?

I have been trying to find information about this but I can't find it anywhere.

sjamaan
  • 2,282
  • 10
  • 19
shuji
  • 7,369
  • 7
  • 34
  • 49
  • `(fn 'a 'b)`? :) – rsm Feb 07 '19 at 02:42
  • Thanks but initially I need the list of symbols, from there I will be evaluating deep into the function. Eval could be perfect because the function will then be evaluating the next symbols as functions as well. – shuji Feb 07 '19 at 03:22

1 Answers1

2

How about the following?

(let ((expr '(fn a b)))
  (cons (eval (car expr)) (cdr expr)))

But please note that if you have to rely on eval, you're almost certainly doing things wrong.

sjamaan
  • 2,282
  • 10
  • 19
  • 1
    By the way, you might get more direct responses if you ask on IRC; we're in `#chicken` on Freenode. – sjamaan Feb 07 '19 at 09:18
  • thanks yes my solution was very much like this `(define (evals x) (apply (eval (car x)) (cdr x)))` – shuji Feb 07 '19 at 18:21