Lolcode spec fixes - #102
Conversation
IT was used ("if IT can be cast to WIN") without ever being introduced.
Doc claimed "three types" while listing four; clarify TROOF is a value type produced by comparisons, not a declarable variable type.
LOLCODE's math operators are fully bracketed by keywords (SUM OF x AN y), so there's no ambiguous infix chain for precedence rules to resolve; this was unadapted leftover content.
The "types must match" requirement contradicted this doc's own math-operator casting rule and the official LOLCODE spec, which auto-casts YARN/NUMBR the same way for both.
The official LOLCODE spec never specifies scope more finely than function/main-block level, leaving if/loop block scoping undefined. State it explicitly for this course's implementation.
|
|
||
| Parenthesis ('()') can be used to group operations to override precedence or | ||
| clarify the evaluation order. | ||
|
|
There was a problem hiding this comment.
precedence is implicit because of the operators
There was a problem hiding this comment.
I added the parenthesis because I didn't understand how precedence works. Can you show me some examples? Can we put them in the spec so it's clear for the students?
There was a problem hiding this comment.
I might get it: is x+2*y written as sum of x an produkt of 2 an y?
There was a problem hiding this comment.
Yes, exactly. And (x+2)*y is written as produkt of sum of x an 2 an y
| All variable scope is local to the main program block. | ||
| Variables are only accessible after declaration, and there is no global scope. | ||
|
|
||
| Blocks introduced by ``O RLY?``/``YA RLY``/``MEBBE``/``NO WAI``, ``WTF?``/``OMG``, and ``IM IN YR``/``IM OUTTA YR`` are their own scope: a variable declared with ``I HAS A`` inside one of these blocks is only visible within that block, and ceases to exist once the block ends. |
There was a problem hiding this comment.
I assume this is the intention, we may also want a single global scope? However, the
IM IN YR <label> <operation> YR <variable> [TIL|WILE <expression>]
<code block>
IM OUTTA YR <label>
loop has a temporary local variable, so they have to do scoping anyway.
There was a problem hiding this comment.
I thought I had a Scope section that reads something like:
All variable scope, as of this version, is local to the enclosing function or to the main program block. Variables are only accessible after declaration, and there is no global scope.
There was a problem hiding this comment.
Yes, this is that section. However,
- This version does not have functions
<variable>in the loop example above is local according to the spec, so your scope rule alone is inconsistent with this part of the spec.
I would prefer that we have no scope, as SCalc has no scope and I have written VCalc exams with the assumption that VCalc introduces scoping. However, IDK how to resolve this—maybe the loop requires an already declared variable?
There was a problem hiding this comment.
My reading of the Scope section is that there is no scope since we don't have functions, i.e. it already was like SCalc. Somehow I thought you were adding block scoping with your suggested changes.
I suggest we resolve the weird loop iterators exactly as intended by the spec: they are special variables that do not need to be declared and only exist within their loop body. That's the great fun of inventing your own language - you can do whatever you want!
There was a problem hiding this comment.
That is what I was saying, but I no longer hold that position.
I am thinking of how the student implement the parser/interpreter. If there are these temporary variables that only exist within the loop body, then they must implement a scope table—which they did not have to do for SCalc. Then, lolcode does not have global scope, it also has block scoping rules, but only for this one specific part of the language.
I think this is not educational for the students, and we should either do real block scoping (not recommended) or get rid of this specific type of block scoping (recommended).
There was a problem hiding this comment.
Decision: advise students they should not bother with a scope table, all global scope except for implicit loop vars.
Note: investigate nested loops
| ~~~~~ | ||
|
|
||
| For the purposes of this assignment, LOLCODE only recognizes three types: | ||
| For the purposes of this assignment, LOLCODE recognizes four types, though only three of them can be declared as variables: |
There was a problem hiding this comment.
SCalc (and VCalc) only have integers. I found the interpreter was much trickier to write with two types (and automatic promotion). It actually made we want to do more passes (symbol creation and type checking) before doing the interpreter.
There was a problem hiding this comment.
When I say "this is like SCalc", I mean that SCalc also has an implicit boolean type that exists for conditionals but can not be explicitly created by the programmer.
rcunrau
left a comment
There was a problem hiding this comment.
Good analysis and good suggestions!
|
|
||
| These operators apply to both strings and integers. Since both types are | ||
| supported, the types of ``<x>`` and ``<y>`` must match. | ||
| These operators apply to both strings and integers. As with the math operators above, if either argument is a ``YARN``, it is converted to an integer and the operation proceeds if the conversion succeeds. |
There was a problem hiding this comment.
I was going from the compare op in the spec:
Comparisons are performed as integer math in the presence of two NUMBRs, but if either of the expressions are NUMBARs, then floating point math takes over. Otherwise, there is no automatic casting in the equality, so BOTH SAEM "3" AN 3 is FAIL.
| If-then | ||
| ~~~~~~~ | ||
|
|
||
| A bare expression statement (one not assigned to a variable) stores its result in the implicit variable ``IT``. ``IT`` holds that value until the next bare expression replaces it, and is what ``O RLY?`` and ``WTF?`` test against. |
There was a problem hiding this comment.
IT is used in a bunch of places in the spec, but not anywhere else in our spec. Do you think we should introduce it?
There was a problem hiding this comment.
Decision: Remove IT, use explicit conditions in every case
| All variable scope is local to the main program block. | ||
| Variables are only accessible after declaration, and there is no global scope. | ||
|
|
||
| Blocks introduced by ``O RLY?``/``YA RLY``/``MEBBE``/``NO WAI``, ``WTF?``/``OMG``, and ``IM IN YR``/``IM OUTTA YR`` are their own scope: a variable declared with ``I HAS A`` inside one of these blocks is only visible within that block, and ceases to exist once the block ends. |
There was a problem hiding this comment.
I thought I had a Scope section that reads something like:
All variable scope, as of this version, is local to the enclosing function or to the main program block. Variables are only accessible after declaration, and there is no global scope.
| ~~~~~ | ||
|
|
||
| For the purposes of this assignment, LOLCODE only recognizes three types: | ||
| For the purposes of this assignment, LOLCODE recognizes four types, though only three of them can be declared as variables: |
There was a problem hiding this comment.
SCalc (and VCalc) only have integers. I found the interpreter was much trickier to write with two types (and automatic promotion). It actually made we want to do more passes (symbol creation and type checking) before doing the interpreter.
|
|
||
| Parenthesis ('()') can be used to group operations to override precedence or | ||
| clarify the evaluation order. | ||
|
|
There was a problem hiding this comment.
I added the parenthesis because I didn't understand how precedence works. Can you show me some examples? Can we put them in the spec so it's clear for the students?
|
|
||
| Parenthesis ('()') can be used to group operations to override precedence or | ||
| clarify the evaluation order. | ||
|
|
There was a problem hiding this comment.
I might get it: is x+2*y written as sum of x an produkt of 2 an y?
Some fixes/clarifications to the lolcode spec