Retro is a concatenative, stack based language with roots in Forth.

It is designed to be small, easily learned, and easily modified to meet specific needs, it has been developed and refined through continual use by a small community over the last decade.


This blog is written in Retro and has served as my primary means of posting things concerning Retro since 2010. The core code for Corpse is included in the Retro releases and can be freely studied and deployed.

The most recent posts are shown below. You can also view a list of all posts.

Post 192 of 215

2012-06-03

Programming in Parable

While Parable remains unfinished, it is now at a point where it is possible to write and run small programs within it.

Code entry is a big part of the interface. The code entry area sits in the center to make it easy to spot. Based on recent input from Luke and others in the #retro IRC channel, a few improvements have been made.

Luke (docl in #retro) suggested that clicking on a name in the dictionary list add it to the code entry area. This has been done, and I'm quite pleased with how easy it was. It certainly saves a fair amount of typing on my iPad.

The second improvement is autocompletion. This isn't quite as satisfying (it tries to guess what you are typing, but doesn't display a list you can choose from.) I'll probably be changing this in the future.

Documentation is done in Markdown format. Functions defined through the UI can have documentation associated with them. It will soon be possible to edit the docs for each function.

So here's the gist of how code is handled in Parable. You have tokens, with optional prefixes that provide hints to the system on how to handle them. Tokens are separated by whitespace.

PrefixExamplesUsage
$$a $1 $$Rest of token is a character. Type is :character
&&+ &string.toUpperCaseRest of token is a function name; push a pointer to the stack. Type is :function
##100 #-100 #0.504Rest of token is a number. Type is :number
""hello" "a string"Rest of token (and following tokens, up to next one ending in a " is a string). Type is :string

Apart from these, tokens are looked up in the dictionary, and then get compiled into the current function definition. There is only one exception: the [ and ] functions get called rather than compiled. These two are used to build new anonymous functions, so they form a special case.

Just as in Retro, code between [ and ] are called quotes. The same basic rules apply: you can create them, nest them, pass them around, and operate on them using combinator functions. Unlike Retro, the use of quotes and combinators are the only method of flow control provided. Parable has no special syntax for loops or conditionals.

All code is compiled before being run. This requires a bit of care if you are creating new named functions. E.g., a block like this will result in an error:

    [ #100 ] "ONE-HUNDERED" define 
    ONE-HUNDRED #2 *

The ONE-HUNDRED will only become visible after the code is run, so the second line would need to be compiled and run separately.

For those wanting to play with Parable, see the parable demo page. A link the bzr repo is also provided there. Keep in mind that there is no storage of the compiled code yet, so refreshing will lose anything you work on. I hope to rectify this over the next couple of weeks.

In the next post I'll explain the memory model, and provide a couple of examples showing how to create simple variables.


blog comments powered by Disqus