Crab – an interpreter for a tiny subset of Logo
beyondloom.com
beyondloom.com
At first I couldn't believe that's all there was. The heart of the interpreter is "almost nothing":
const think = (l,r,x) => (iter(l, (f,l) => (r.push(x = call(f,l,r,x)), args[f])), {r,x})
const wrap = x => /[a-z]+/.test(x) ? '\''+x+'\'' : x
const parse = x => eval('['+x.replace(/([a-z]+)|(-?\d+)|(\])/g, x => wrap(x)+',')+']')
const run = (text, x) => [x].concat(think(parse(text), [], x).r)
And the LOGO commands are simply global variables.It's a fun project, and I appreciated the hand-crafted code. It reminded me of how much is possible with so little, small is beautiful indeed.
I recently submitted a small post here about implementing a simple FORTH-like language, in golang. I figured I should go a step further and document how you'd embed that inside a host-application. So I came up with a trivial turtle-implementation.
To draw a square:
50 forward
90 turn
50 forward
90 turn
50 forward
90 turn
50 forward
Of course with FORTH you'd define a word to draw a square of the given size: : square ( top of the stack is length of side)
dup dup dup
4 0 do
forward \ move forward, drawing a line
90 turn \ turn 90 degrees. we're a square!
loop
;
The result was definitely fun to play with, especially once I made it output both the final result and an animated gif of each draw-step:This reminds me strongly of that post. DSLs are fun, and something like FORTH maps well to a lot of simple use-cases.
With Logo you would do exactly the same. In fact, growing the language’s base vocabulary with your own words is the whole point of Logo and Forth. Why waste your entire lifetime speaking the machine’s primitive, low-level language when you can teach it how to speak your own powerful, high-level ones?
+1 for using the amazing horseshoe crab† as cursor, but -1,000,000 for so utterly missing the point.
--
† Not actual crabs, they’re more closely related to spiders and have lived on Earth virtually unchanged for almost half a billion years. https://oceantoday.noaa.gov/fullmoon-remarkablehorseshoecrab...
Thus Logo got placed into the box labeled “How to Teach Programming”, when that was never its goal: its purpose was to provide children a tool to explore and play with math and numbers and how to think for themselves.
It reminds me of Feynman’s excoriation of “New Math” textbooks (https://rangevoting.org/FeynTexts.html):
“Finally I come to a book that says, "Mathematics is used in science in many ways. We will give you an example from astronomy, which is the science of stars." I turn the page, and it says, "Red stars have a temperature of four thousand degrees, yellow stars have a temperature of five thousand degrees . . ." – so far, so good. It continues: "Green stars have a temperature of seven thousand degrees, blue stars have a temperature of ten thousand degrees, and violet stars have a temperature of . . . (some big number)." There are no green or violet stars, but the figures for the others are roughly correct. It's vaguely right – but already, trouble! That's the way everything was: Everything was written by somebody who didn't know what the hell he was talking about, so it was a little bit wrong, always! And how we are going to teach well by using books written by people who don't quite understand what they're talking about, I cannot understand. I don't know why, but the books are lousy; UNIVERSALLY LOUSY!”
..
Yet the problem wasn’t New Math itself, which was about giving kids the confidence to play with numbers, teaching them to explore and experiment for themselves, not obediently jump through rote hoops like some circus dog mindlessly converting canned inputs into “right answers” till utterly bored by the whole process and turned off all math for life.
The problem was these “New Math” textbooks were clarly written by Old Math teachers—and those teachers had no interest in learning or doing anything different, so they just wrote old math lessons as before, skimmed over with a shallow mimicry of “new math” language; a zombie draped in the flayed skin of its erstwhile successor, and an atrocity to all math, both old and new. A threat of change, successfully defused; the status quo ensured. Old Math teachers could safely go on teaching their old math to their millions of students who would safely go on failing it.
..
Papert himself was a mathematician, a lover of math so frustrated by maths’ inaccessibility to millions of kids that he devised a tool to make math friendly and accessible, even fun.
Papert’s mistake was not in teaching kids how to use Logo to learn for themselves, because kids can learn anything, including how not to learn and to hate learning itself. The kids got it, and the teachers who got kids got it too. All that part worked great.
No, Papert’s mistake——and it seems obvious in hindsight—was in not teaching Logo to the people in charge. Why should they want to change anything, when their current practices clearly work well—after all, why else would they have been promoted to be in charge of it all?
But without all the decision-makers (head teachers, school boards, education departments, government, and parents) on-side, no greater change could be effected, and the entire project doomed to fail. Because, in all those Responsible Grown-Up eyes, Logo is “Programming”—and they already had a box for teaching that. And so in it went, and—yay!—for there was no more unwanted disruption in class.
..
Which is ironic, when you consider that any old foul-tempered Master of Ancient Greek could have taught them just how grossly wrong they were in their perception of Logo, no doubt with a sound thrashing to accompany the lesson too.
Logos - Longer definition: The Greek word logos (traditionally meaning word, thought, principle, or speech) has been used among both philosophers and theologians. In most of its usages, logos is marked by two main distinctions - the first dealing with human reason (the rationality in the human mind which seeks to attain universal understanding and harmony), the second with universal intelligence (the universal ruling force governing and revealing through the cosmos to humankind, i.e., the Divine).
Whilst we were in lockdown the first time, I wrote a small Logo interpreter for my son with almost exactly the same commands: https://freememory.github.io/azlogo/ (https://github.com/freememory/azlogo)
My code isn't nearly as elegant, not at all animated, and my parsing is awful but I had a lot of fun doing it.
There's something magical about Logo, and even now as an adult of almost 40 I continue to enjoy playing with it and making pretty line graphics.
Port it to WebAseembly/WebGL already! No downloads, no warnings, also works on phones, etc.
EDIT: just wanted to add that you have something really incredible in your hands, try to make it more accessible, more tutorials would be good
They do make for good languages for toy robots, though - for instance, you can use Scratch with Lego Mindstorms in a way that's not much more advanced than Logo.