Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Crab – an interpreter for a tiny subset of Logo (beyondloom.com)
70 points by beagle3 on Sept 22, 2020 | hide | past | favorite | 19 comments


The source is fascinating to read, it's a self-contained HTML document with a single style and script element.

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 had fun reading that too.

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:

https://github.com/skx/turtle

This reminds me strongly of that post. DSLs are fun, and something like FORTH maps well to a lot of simple use-cases.


“Of course with FORTH you'd define a word to draw a square”

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...


Exactly. Logo is a real programming language and it is a shame that it gets reduced to "that children's toy for doing turtle graphics" in pop tech culture.


I think the way Logo was taught in schools certainly didn't help. When baby programmer me first discovered you could define functions and used them I remember getting scolded for not following the lesson plan and continuing to do things the hard way. The lesson plan of course lumped function definitions as "advanced" and really only for "the next grade up". My impression is most teachers didn't actually want to teach "the next grade up" of Logo (as it was hard for them) so it was always just the same basic Turtle graphics anyone ever learned (sometimes over and over again, grade to grade), diminishing the point of Logo as an entry way into those harder to teach topics such as functions and recursion. It doesn't seem surprising that pop culture only remembers turtle graphics, when that's all anyone was ever taught.


Papert’s problem was not realizing that most people, especially people in charge, like to put things into neat boxes, not break them out.

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).


As always line breaks and de-nesting a bit would make it more obvious and not quite so terse. However, parsers and DSL usually do look almost like nothing in lispy like languages/ functional style, yet in C it’s a rats nest of for loops and flow control to parse things.


This is awesome!

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.


Cool! On the opposite end of the spectrum, we're working on a very complex Logo with 3D OpenGL support https://turtlespaces.org


Imagine just a kid on Windows, you have to go to the download page, find the right link (not at all clear from your CSS styles by the way). Then, if they don't read the warning you'll have a security warning. Then, Windows will warn because it's a downloaded executable from a website. Then you have to find where it extracted it and then run it!

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


Is turtlespace planned to be open source? Wondering if possible to contribute. Its a very nice platform - congrats.


If you enjoy this, you might also like http://beyondloom.com/somascape/index.html


Logo was the first "programming language" I ever used. I had a fantastic primary school teacher in year 3 who introduced us to an implementation called MSW Logo. Very fond memories.


I could have sworn that Logo was a tiny subset of Logo. Live and learn.


Yeah, "turtle graphics" were a tiny subset of what Logo was meant to teach.


More seriously, this is cute and it brings back fond memories of L-systems.


What are the current applications of these languages? Is there anything besides educational one (I remember we had a class at the middle school).


We're working on making a Logo-based game engine; we're also going to release a command-line version for scripting soon. Actual Logo is a fully-complete language with sophisticated string and list handling. So we're hoping to make Logo more useful than just for education! =)


Just education and toys. The simplest ones like this aren't even Turing-complete, so you couldn't really program much in them even if you wanted to as a weird challenge - they're more like automated Etch-a-Sketches.

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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: