0

A S-Expression is considered as a Number, a String, a Symbol, a Bool, an Image, empty or a List-of S-Expressions.

How do I achieve to make racket eval my S-Expression? '(1 2 (+ 2 1))) should yield (list 1 2 3).

I want to do this with Beginning Student Language with List-Abbreviations.

I have no idea how to achieve this, how do I know when a plus sign is coming up? Probably easy one for you guys here...

(define (eval s)
     (cond
        [(...) ...]
        [(...) ...]
        [else ...]))
HappyR
  • 23
  • 3
  • 1
    use recursion, and `first`, `rest`, `null?` and `pair?`. – Will Ness May 24 '18 at 10:49
  • Could you please guide me? Im stuck. How do I recognize the + sign? '(1 2 (+ 2 1))) is nothing else than (list 1 2 (list '+ 2 1)) The problem is how do I recognize this + sign and yield it? – HappyR May 24 '18 at 11:06
  • by using `eq?`: `(cond ... ((eq? s '+) +) ...)`. there's also `number?`, `symbol?`, ... – Will Ness May 24 '18 at 12:16
  • Does not work, it says it expects the first argument to be a symbol, but list '+ 2 1 given... :/ – HappyR May 24 '18 at 12:37
  • 1
    https://www.youtube.com/watch?v=ExeUbrynvNE – soegaard May 24 '18 at 18:55
  • include the code you used ([mcve]), the test call you made, and its results (if it was an error, copy-paste full error message). – Will Ness May 25 '18 at 10:43

0 Answers0