I didn’t know the length property on JavaScript functions was obscure.
Curly Logo uses the length property to decide the arity of its procedures.
Consider a Logo program like «fd prod 10 5». How does Logo know that it should evaluate (prod 10 5) producing 50, and then evaluate (fd 50)? Consider the similarly shaped program «prod minus 10 5»; this evaluates (minus 10) first, to produce -10, then evaluates (prod -10 5) to produce -50. The evaluation of Logo is directed by the arity of the operators.
Logo knows that “prod” takes 2 inputs and that “minus” takes 1 input, so it doesn’t evaluate a call to “prod” until there are 2 inputs to consume.
Curly Logo implements “prod” as a JavaScript function that takes 2 arguments. The execution of Curly Logo proceeds by using the length property of the “prod” JavaScript function to decide how many inputs it requires. Curly Logo has a magic “javascript” command which adds a javascript button. Now you can type either Logo or JavaScript and have it evaluated using the appropriate button. Evaluating «logo.global.prod.length» as JavaScript will yield 2, «logo.global.fd.length»
yields 1 (all of Logo’s globals are stored in the logo.global JavaScript object). This feature allows built-in Curly Logo procedures to be implemented as natural JavaScript functions. I suppose Apple would call it a Curly Logo JavaScript bridge.
In fact “prod” can be coerced into taking any number of arguments by using Lisp style calling syntax, «(prod 1 2 3 4) ⇒ 24». This is a standard Logo feature and not special to Curly Logo.
JavaScript can be used to “peek under the hood”, once you’ve turned the javascript button on you can use it to inspect the implementation of “prod”: «logo.global.prod ⇒ function (multiplicand, multiplier) {
var a = 1, i;
for (i = 0; i < arguments.length; ++i) {
a *= arguments[i];
}
return a;
}».
2007-11-14 at 14:18:10
I guess this syntactic feature rules out any first-class functions in Logo (otherwise prod minus 10 5 would attempt to multiply minus by 10 before encountering the 5).
2007-11-14 at 15:35:02
Yes. And it strikes me as a potentially fatal flaw in the language.
Of course they get in through the backdoor of quoting:
erase “foo
erases the procedure named foo, and
repeat 4 [ fd 50 rt 90 ]
passes the quote listed [fd 50 rt 90] to repeat which more or less treats it as a lambda. Kinda.
None of this makes the language friendly to a compiler.
2008-05-31 at 00:48:20
how come this post is not tagged “curly logo”
2008-06-02 at 07:21:59
Umm, mistake? I’ve filed it under Curly Logo as well now, but it’s not like I pretend to have a consistent policy or anything.