This is unmatched, and can never be matched, by Python.
You can probably reimplement much in Python, but at some point you will have to admit you’ve written a LOGO interpreter.
Anyway, I've taught with Python a fair amount and have been pleased with the results, especially when using the `turtle` module.
to circle
fd 3
rt 7
circle
end
Add a parameter, and get a spiral. The turtle winds its way off the screen, and again the student can stop the program manually: to spiral :x
fd :x
rt 30
spiral (:x + 1)
end
Introduce a base-case, and now the program stops itself at a desired size: to spiral :x
if (:x = 30) [ stop ]
fd :x
rt 30
spiral (:x + 1)
end
Small, unsurprising steps building up an intuitive grasp of a useful concept.TCE can also improve the economy of the language, reducing the number of "primitive" control flow concepts that need to be provided out of the box. Since Logo has no "special forms" and is not eagerly evaluated like a Lisp, it's easy to make new control constructs without needing to teach any magic:
to while :cond :proc
unless run :cond [ stop ]
run :proc
while :cond :proc
end
Little things matter.Yet, the creation of a "while" here isn't so different than making a new function which performs that logic. Was your example intended to demonstrate creating new syntax?
It takes two arguments ("cond" and "proc") which would both be bracketed lists. "unless" is common sugar for a negated if statement. "run" evaluates a list as an expression. You'll notice that if/unless also take their bodies as lists, rather than any sort of special-purpose block syntax. "stop" short-circuits the current procedure and immediately returns.
Since Logo has dynamic scope, any variable references in "cond" and "proc" will resolve the same within "while" as they did in its caller; no nasty visibility surprises. Since Logo does not eagerly evaluate lists, there is no need to "quote" or otherwise escape the lists in the caller's context. It is precisely that one can define such a construct without defining new syntax per se that is useful.
That's a handy feature. Thanks for the explanation.
One extra note: LOGO does not have closures (closures require lexical scope). Dynamic scope gives the possibility to, e.g., define new control flow without quoting, but lexical closures are not possible.