Question 1 @ 2025-02-04 18:18
What does it mean for functions to be a first-class citizens in a programming language?
- Functions can only be used as values
- Functions can only be used as arguments to other functions
- Functions are created at compile-time
- Functions are values that can be passed to & returned from functions, and created at run-time
- Functions can only be defined and called by their name
Question 2 @ 2025-02-04 18:23
Which of the following are true about different treatments of functions in programming languages?
-
First order: functions can be used as values
-
First order: function values can be created in any scope
-
Higher order: functions can be used as values
-
Higher order: function values can be created in any scope
-
First class: functions can be used as values
-
First class: function values can be created in any scope
Question 3 @ 2025-02-04 18:26
What would be the result of running this expression using our Flang language implementation (the one with substitutions)?
- Compilation error
- 2
- 3
-
Unbound
+
error -
Unbound
*
error -
bad
with
syntax in
Question 4 @ 2025-02-04 18:30
Given the following code and one sample test:
(lambda (y) (f x y)))
(test ((fix1 mul 10) 5) => 50)
Which of the following type declarations is best for fix1
?
-
(: fix1 : (All (A B) (A A -> B) -> A -> B))
-
(: fix1 : (All (A B) (A A -> B) A -> (A -> B)))
-
(: fix1 : (All (A B C) (A B -> C) A -> (B -> C)))
-
(: fix1 : (All (A B C) (A B -> C) -> (A -> (B -> C))))
-
(: fix1 : (All (A B C) (A B -> C) -> A -> (B -> C)))
-
(: fix1 : (All (A B C) (A B -> C) (A -> B) -> C))
Question 5 @ 2025-02-04 18:34
Which of the following FLANG expressions are equivalent in terms of how they get evaluated (ie, ignoring substitutions on the way)?
- (A)
{+ E1 E2}
- (B)
{with {x E1} {with {y E2} {+ x y}}}
- (C)
{with {y E2} {with {x E1} {+ x y}}}
(Be careful when you think about it.)
- None are equivalent
- A is equivalent to B
- A is equivalent to C
- B is equivalent to C
- All three are equivalent
- Trick question: the answer depends on Racket’s behavior