jrincayc / ucblogo-code

Berkeley Logo interpreter
https://people.eecs.berkeley.edu/~bh/logo.html
GNU General Public License v3.0
182 stars 34 forks source link

optional inputs notation #183

Open guidoBenvenuto opened 3 months ago

guidoBenvenuto commented 3 months ago

In the manual section "8.1 Procedure Definition", optional inputs are represented by the following notation:

[:inputname default.value.expression]

The following notation is on the other side valid:

[inputname default.value.expression]

as can be seen in the following example:

to add [num 2]
output sum 3 :num
end

to add1 [:num 2]
output sum 3 :num
end

? show add
5
? show add1
5

? show text "add
[[[num 2]] [output sum 3 :num]]
? show text "add1
[[[num 2]] [output sum 3 :num]]

Please note that "fulltext" preserves the differences:
? show fulltext "add
[to add [num 2] output sum 3 :num end]
? show fulltext "add1
[to add1 [:num 2] output sum 3 :num end]

I wonder if this alternative notation could be explainded in the manual. Yours Guido Gay

guidoBenvenuto commented 1 month ago

Sorry, I didn't notice this clear explanation in the manual (pages 4-5, Introduction):

One final point: The TO command in Logo has always been a special case; the rest of the line starting with TO is not evaluated as ordinary Logo expressions are. In particular, the colons used to mark the names of inputs to the procedure do not cause THING to be invoked. They are merely mnemonic aids, reminding the Logo user that these words are names of variables. ... Berkeley Logo therefore makes the colons optional: TO FOO :IN1 :IN2 and TO FOO IN1 IN2 are both allowed.

Yours Guido Gay