-
Notifications
You must be signed in to change notification settings - Fork 1
FAQ
For anything not listed below and not clear in the document, just assume a reasonable solution and mention it in the presentation.
- non-boolean condition in
if
statements - non-integral expression in
Range
- meaning of
[not] IntegerLiteral
- using
reverse
with an invalid range - declaring a routine with 0 parameters
- assigning integer (not 0 or 1) to boolean
- memory leaks and garbage collection
- redeclaring variables/types
The grammar specifies that it can be any
Expression
, which includesreal
andinteger
. What to do?
Convert the expression to a boolean using the normal casting rules.
The grammar defines the range as
Range :: Expression '..' Expression
. What if the expression is a boolean or a real number?
Convert the expresion to an integer using the normal casting rules.
So is
x=4..3+1
a valid range?
Yes. Depending on the value of x
, it will be equivalent to either 0..4
or 1..4
.
What does
[not] IntegerLiteral
in the grammar mean, and why is it notBooleanLiteral
?
I am not sure, but it is a mistake. You can use not
with booleans, and integers can be cast to booleans.
What would be the range expressed by
reverse x..y
, wherex > y
?
The range is evaluated first before the reversing. A Range where the first number is larger is an empty range. Consider the examples below:
Range | Values taken by loop variable (in order) |
---|---|
2..5 |
[2, 3, 4, 5] |
5..2 |
[] |
reverse 2..5 |
[5, 4, 3, 2] |
reverse 5..2 |
[] |
Is it possible to define a routine without any parameters?
Yes. There is a mistake in the grammar. Just declare a routine as normal and keep the parentheses empty.
What kind of error should assigning an integer (that is not 0 or 1) throw?
A run-time error, as it cannot be detected in compile-time.
Types do not exist in run-time
Whenever such an assignment is detected, inject some code into the compiled program that detects for erroneous assignment.
If user-defined types are assigned by reference, this can leave objects without a reference
Either implement garbage collection or just let the memory leak.
Can variables or types be redeclared?
Variables and types cannot be redeclared in the same scope. Declarations with the same name can only occur in different scopes, and the nested scope shadows the outer one.