hs-logo icon indicating copy to clipboard operation
hs-logo copied to clipboard

Add support for optional arguments to builtins as well as defined functions

Open deepakjois opened this issue 13 years ago • 2 comments

deepakjois avatar Feb 15 '12 03:02 deepakjois

This depends on some refactoring as part of #40. Will defer until then.

deepakjois avatar Feb 25 '12 17:02 deepakjois

Here is an example of an interesting way to call the for library procedure taken from the Logo 15-word challenge.

for [i 0 220 sin :i/1000] [fd :i bk :i rt 41]

One interesting thing about the statement above is that the value :i/1000 evaluates to 0 and hence the program should go into an infinite loop. It is unclear how it generates the figure as shown on the page.

Moreover, this is in violation of the the Berkeley Logo spec for the for library procedure:

FOR forcontrol instructionlist

The first input must be a list containing three or four members: (1) a word, which will be used as the name of a local variable; (2) a word or list that will be evaluated as by RUN to determine a number, the starting value of the variable; (3) a word or list that will be evaluated to determine a number, the limit value of the variable; (4) an optional word or list that will be evaluated to determine the step size. If the fourth member is missing, the step size will be 1 or –1 depending on whether the limit value is greater than or less than the starting value, respectively.

The best way to resolve this seems to be to obey the spec, and modify the statement above appropriately.

for [i 0 220 [sin :i/1000]] [fd :i bk :i rt 41]

However the problem of infinite looping remains.

deepakjois avatar Mar 18 '12 23:03 deepakjois