Question 1 @ 2024-02-20 18:38
What is true about a syntactic evaluator?
-
It doesn’t implement closures and lexical scope, instead using the fact that the evaluated language itself has them.
-
It is implemented as just a different syntax on top of an existing language.
-
It is an evaluator where implementing each semantic feature is simple.
-
It implements most of a language explicitly instead of embedding features of the implementation language.
-
It relies on a strong match between the implementation language and the evaluated language to be easy to write.
Question 2 @ 2024-02-20 18:41
Consider the following code refactoring:
(let ([foo ...])
...)
=>
...
(define foo ...)
...
Is this a simple enough transformation that could be done by just regexp-replacing (assuming only simple one-lines as above) and re-indenting?
(Remember: choose the best answer.)
- Yes, of course.
-
Yes, provided that you manually remove the last
)
too. - No, since regexps cannot handle a (possibly recursive) grammar.
-
No, because
define
andlet
are different things. -
No, because
let
is not a recursive binder likedefine
.
Question 3 @ 2024-02-20 18:44
Are the following two definitions of Y valid and equivalent?
(lambda (f)
((lambda (x) (f (lambda (n) ((x x) n))))
(lambda (x) (f (lambda (n) ((x x) n)))))))
(define Y2
(lambda (f)
((lambda (x) (x x))
(lambda (x) (f (lambda (n) ((x x) n)))))))
- Yes.
- Yes, only if we’re using an eager language.
- Yes, only if we’re using an lazy language.
- They’re equivalent, but wrong.
- They’re equivalent, but wrong: both will loop infinitely.
Question 4 @ 2024-02-20 18:47
We’ve seen how the core of the Y combinator leads to an inifinte nesting of calls to F:
(lambda (x) (F (x x))))
=>
(F (F (F ...)))
What would we get if we’d change it to:
(lambda (x) (F (x x))))
=>
???
- (G (F (G (F …))))
- (F (G (F (G …))))
- (G (F (F (F …))))
- (F (G (G (G …))))
- It’s an infinite loop anyway, so it doesn’t matter
Question 5 @ 2024-02-20 18:50
What would you get if you evaluate the next expression in Schlac?
(foo 1 2)
- 1
- 2
- 3
- An error about duplicate bindings.
- An error since Schlac doesn’t have definitions.
-
The shadowing would make it use dynamic scope and therefore an
error about unbound
x
. -
Forget what
E3
said, you’d get an unbound identifier error, but not with the dynamic scope nonsense.