Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
/ lunar-logo Public archive

Experimental scripting language based on Logo and Lua

License

Notifications You must be signed in to change notification settings

felixp7/lunar-logo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lunar Logo

Welcome to Lunar Logo, an experimental scripting language based on Logo and Lua, with a tiny core and clean, minimal syntax. Example usage:

$ ./lunar.py sqrt add mul 3 3 mul 4 4
5.0

That's right, you can type Lunar Logo code at a Bash prompt without escaping it (within reason). For a bigger sample, put this code in a file, say repl.lulz:

print [Welcome to Lunar Logo. Enter your commands, or BYE to quit.]
while [true] do
	type >
	type space
	make cmd readlist
	if eq nil :cmd do
		break
	end
	if eq 0 count :cmd do
		continue
	end
	if eq bye lowercase first :cmd do
		break
	end
	foreach i results parse :cmd do
		if neq :i nil do
			show :i
		end
	end
end

Now you can load it as follows:

$ ./lunar.py load repl.lulz

Indeed, Lunar Logo doesn't need a built-in interactive mode because you can code one yourself in just a few lines!

Features

  • A blend of two programming languages famous for friendliness.
  • First-class functions with lexical scoping (and blocks with dynamic scoping).
  • Metaprogramming: code is data; the parser and evaluator are procedures in the language.
  • Tiny core: under 200 lines of code in the prototype -- squeaky-clean code, too!
  • Easily extensible and embeddable: many built-in procedures are literal one-liners.

Project goals

  • A language that needs little or no escaping when embedded into string literals, command lines and such.
  • A language that doesn't run too slowly when implemented in another interpreted language.
  • A language that throws few exceptions. A surprising amount of modern languages in widespread use have other error handling mechanisms.

Uses

You know how modern command line applications have a lot of options, and invocations can become really hairy? For that reason, many of them grow an option to load more options from a file... which of course just complicates things even more.

Lunar Logo solves that problem neatly. Note how in the example above load isn't some special command line option, but an ordinary Logo procedure. You just got the aforementioned ability for free!

Of course, now your application is driven by a whole scripting language, and that requires more care. With great power comes great responsibility.

Other possible uses are as a fancy calculator (much more powerful than expr), or for writing Awk-style filters: Lunar Logo should handle TSV files very well indeed.

As of 08 February 2017, Lunar Logo is used to drive Stereo Imagination, a command-line tool to automate the generation of 3D models.

History

This is the second time I do a Logo dialect. The first time around I kept much closer to the original language, but the result was a messy implementation that left much of the heavy lifting to individual procedures, and still didn't have much in the way of speed or capabilities.

Status

As of 31 January 2017, Lunar Logo has two implementations that can run all the examples correctly. The language supports over 100 procedures (you can find a concise list at the end of lunar.py). See the tutorial for an overview.

The software is considered beta quality. More real-world testing is needed, and the feature set may still change. Anything mentioned in the tutorial and examples should stay put from now on, though.

To Do

Error reporting needs some way to provide better context.