Question 1 @ 2024-02-06 19:14
Which kinds of functions do we have in our current version of the Flang language?
- First-order functions.
- First-class functions.
- Higher-order functions.
- Higher-class functions.
- None of the above, since our support for functions is premature.
Question 2 @ 2024-02-06 19:17
We know that we can drop with
from the Flang language, because we can
replace any of its uses:
with a combination of call
+fun
:
Is this symmetric? That is, could we similarly drop the call
+fun
and
manage with just with
?
-
Yes we can: we just need to do a similar substitution as above, only going in reverse direction.
-
The question is nonsensical: we cannot always translate a
with
to uses ofcall
+fun
. -
We cannot do that: we can express more since we broke
with
into two independent features. -
Of course not, since any kind of such substitution loses the original code and therefore the intended meaning that the programmer had.
Question 3 @ 2024-02-06 19:20
What is the main problem with our current Flang language implementation?
-
Our bindings are not handled correctly.
-
Function calls are slow, so we need to change the interpreter-based implementation into a compiler using de-Bruijn indexes.
-
We’re missing a way to build object values.
-
We’re missing a way to check that expressions make sense — a type checker.
-
Function calls are slow, corresponding to the function sizes.
Question 4 @ 2024-02-06 19:22
Bob wants to map a curried version of the expt function onto a list of inputs. He first writes the function currify, which takes a two argument function and returns the curried version of the function.
(lambda (x)
(lambda (y)
(f x y))))
He then writes a test using a curried expt
function (Racket’s
exponent):
What will be the result of this test?
-
It will do whatever Racket does.
-
It will pass, because
(expt 2 3)
evaluates to8
. -
It will fail, because the map will evaluate to a list of numbers, not just a single number.
-
It will error, because the function
(currify expt)
needs to be called on an input before it is passed into map. -
It will fail, because the map will evaluate to a list of one argument functions instead.
Question 5 @ 2024-02-06 19:27
What is a good name for the following function?
(lambda (f g)
(lambda (x)
(g (f x)))))
-
Trick question: this has free identifiers and therefore always an error.
-
functional-addition
-
compose
-
compose-at-point
-
reverse-compose
-
currify-3-args