3 ms·
The authors of the JS version of SICP had a problem: Scheme is expression based and JavaScript is statement based. When I say Scheme is expression based, I am
by soegaard 2y ago
The authors of the JS version of SICP had a problem:
Scheme is expression based and JavaScript is statement based.
When I say Scheme is expression based, I am alluding to the fact that constructs such as `if`, `cond`, `case` etc. are all expressions. Scheme also has several binding constructs (let, letrec, etc) that allows in an expression context to bind the result of a computation in a subexpression. These are all expressions.
The expression version of `if` is in JavaScript called ternary if.
A direct translation from Scheme to JavaScript therefore uses ternary if.
But why make a direct translation?
Well, later in the book one writes an interpreter for Scheme.
This interpreter shows how the expression based language constructs are implemented. It is therefore necessary that the reader is very familiar with these constructs.