Software/LittleLogo

Little Logo is a simplified dialect of the Logo programming language. Specifically, it is modeled after UCB Logo, the de facto reference implementation nowadays. Unfortunately, UCB Logo suffers from an irregular syntax with lots of exceptions. As Little Logo is made for fun, I went for a simpler, uniform language. It loses to the original in many respects, but wins in others.

Pros

Little Logo is free form. If you were to feed this source code to UCB Logo:

print
3

You would receive two error messages in return:

not enough inputs to print
You don't say what to do with 3

Little Logo, on the other hand, will do what you expect.

Expressions are statements. In Lisp, Python and most (all?) curly brace languages, a stand-alone expression is a valid statement. That means you can call a function for its side effects, ignoring the return value, and docstrings don't need to be special-cased. To top it all, it makes for simpler syntax. Little Logo follows this model, unlike its illustrious predecessor.

In addition, Little Logo takes advantage of this by making several procedures return a meaningful value that don't do so in UCB Logo, most importantly MAKE.

Clean, portable semantics. While Little Logo is very close to the host language, the interpreter architecture is simple and very general; it should be trivial to port to any reasonably high-level language.

Cons

No TO ... END. That may be a staple of Logo, but it's a line-oriented construct that has to be special-cased, and it's confusing to boot, as it doesn't follow the same rules as the rest of the language (as the UCB Logo manual admits in the introduction). You do get user-defined words, though -- see below.

No infix arithmetic. Unfortunately, that would be difficult to implement with the current interpreter architecture. To compensate, Little Logo has sane aliases for certain operators. (GREATEREQUALP? seriously? What's wrong with GTE?)

No optional function arguments either, also due to the simplistic architecture.

Download

Little Logo is available under the MIT License:

© 2011 Felix Pleșoianu <felixp7@yahoo.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Status

As of 2011-05-18, the PHP implementation largely works, implementing over 60 primitives, not counting aliases. As it stands, it is able to run this simple script:

; Compute a square root through the Newton-Raphson method.
; Not a good show of Little Logo's capabilities, but I couldn't come
; up with anything more interesting. By the way, SQRT is implemented.

; This won't work in UCBLogo due to its lack of an ABS function.

make "a 42 ; Number to extract square root from.
make "precision 0.000001
make "x quotient :a 2
make "prev quotient :a :x

while [lessp :precision  abs difference :x :prev] [
	make "prev :x
	make "x quotient   sum :x  quotient :a :x   2
]

pr :x

The choice of primitives is a bit haphazard, but does include most (all?) control structures, including the "question mark" form of template-based iteration, most list manipulation primitives, some logic and arithmetic.

As of 2011-11-12, Little Logo also supports user-defined words, in a form inspired by the "named slot" form of template iteration, with a hint or two taken from Scheme:

make "hypot [[a b] sqrt sum product :a :a product :b :b]

; Works in both UCB Logo and Little Logo
pr apply :hypot [3 4]
; Works only in Little Logo
pr hypot 3 4

Unlike in UCB Logo, those are real functions, that can contain any number of expressions, and return the value of the last one. Nested (dynamic) scopes work as you might expect:

make "test [[]
	make "a 3
	localmake "b 5
	pr list :a :b
]
make "a 1
make "b 2
pr list :a :b
test
pr list :a :b

LOCAL turned out to be a little can of worms, so it's not implemented. You'll have to settle for LOCALMAKE.

Implementation details

The prototype and so far only implementation of Little Logo is written in PHP. Why? It looked like a fun thing to try. And it was! Moreover, it turns out several Logo primitives map very well onto PHP's, which made the implementation especially clean. FIRST, for example, was straightforward. Same for ISEQ and most array operations.

That said, some Logo operations make no sense in this implementation, for example LISTTOARRAY (since Little Logo uses native PHP arrays throughout); others are redundant -- LISTP and ARRAYP do the same thing.

Naturally, should you wish to embed Little Logo in a web application, you would have to take special precautions to avoid a DDoS attack or security breach.

TO DO

GOTO (?)

Fork me on GitHub
Last modified: Wed 25 06 2014, 16:34:43 UTC