ell/README.adoc

195 lines
5.5 KiB
Plaintext
Raw Normal View History

2017-05-06 14:12:46 +02:00
ell
===
:compact-option:
2017-05-27 20:20:49 +02:00
'ell' is a middle ground between Scheme and Tcl. The goal was to conceive
a programming language implementable with as little code as possible while
still being reasonably comfortable to use.
2017-05-06 14:12:46 +02:00
2018-10-09 10:37:56 +02:00
This package contains two implementations of said language--one in C and
another in Go--which are meant to be self-contained, portable and reusable.
Performance is specifically not an intent.
2017-05-06 14:12:46 +02:00
2017-05-25 14:38:43 +02:00
The project is currently in a "proof of concept" stage with many useful data
operations missing but I believe it won't be a problem to implement them as
needed for anyone interested.
2017-05-20 21:24:11 +02:00
2017-05-06 14:12:46 +02:00
Syntax
------
2017-05-27 20:20:49 +02:00
Owing to its heritage, 'ell' is homoiconic, that is a program can be directly
expressed using the language's data types. There are only two of those:
the list and the string. Any numerical conversions are made on an as-needed
basis. Similarly, strings act like atoms/symbols when executed.
2017-05-06 14:12:46 +02:00
The parser, however, does a bunch of transformations:
* `[a b c]` makes a call to `(list a b c)`;
* `@var` is a shorthand for `(set var)`;
* `{ code }` is the most complex one. Each line within the curly braces is
wrapped in parentheses, and the resulting sequence is wrapped in a quoted
list, so that it doesn't execute immediately.
2017-05-06 14:12:46 +02:00
As an example, consider the following snippet:
2017-05-21 11:26:59 +02:00
print (if { eq? @var foo } {
values 'Hello world\n'
2017-05-06 14:12:46 +02:00
} else {
values 'Error\n'
2017-05-06 14:12:46 +02:00
})
which gets expanded to the following:
((print (if (block (eq? (set var) foo))
(block (values 'Hello world\n'))
2017-05-06 14:12:46 +02:00
else
(block (values 'Error\n')))))
2017-05-06 14:12:46 +02:00
Observe that the whole program is enclosed in an implicit pair of `{}` and that
`block` is all that's left of special forms.
2017-05-06 14:12:46 +02:00
2017-05-26 20:31:30 +02:00
For a slightly more realistic example you can have a look at 'greet.ell'.
2017-05-25 14:38:43 +02:00
2017-05-06 14:12:46 +02:00
Runtime
-------
Variables use per-block dynamic scoping. Arguments to a block (which is a list
of lists) are assigned to local variables named `1`, `2`, etc., and the full
2017-05-28 10:02:19 +02:00
list of them is stored in `args`.
2017-05-06 14:12:46 +02:00
When evaluating a command, the first argument is typically a string with its
name and it is resolved as if `set` was called on it. Lists are left for
execution as they are.
2017-05-06 14:12:46 +02:00
The last expression in a block is the return value.
2017-05-21 13:37:43 +02:00
Special Forms
2017-05-06 14:12:46 +02:00
-------------
`block [<arg>]...`
2017-05-06 14:12:46 +02:00
Like `list` but doesn't evaluate arguments. A more appropriate name might be
`quoted-list`, which is not as descriptive in terms of syntax. If simple
quoting is desired, the list can be unpacked by an ordinary command.
2017-05-06 14:12:46 +02:00
Standard Library
2017-05-06 14:12:46 +02:00
----------------
2017-05-21 12:24:04 +02:00
The standard library interprets the empty list and the empty string as false
values, everything else is considered true. Numbers are floating point with
double precision, trailing zeroes are truncated.
Where a `<body>` is expected, strings retain their value, and block evaluation
is postponed as necessary.
2017-05-21 12:24:04 +02:00
`local <names> [<value>]...`
Create local variables in the current block. Names for which there are no
values left default to `()`.
2017-05-20 21:24:11 +02:00
`set <name> [<value>]`
2017-05-21 13:37:43 +02:00
Retrieve or set a named variable. The syntax sugar for retrieval is `@`.
2017-05-20 21:24:11 +02:00
2017-05-21 18:20:12 +02:00
`list [<item>]...`
2017-05-20 21:24:11 +02:00
2017-05-21 13:37:43 +02:00
Return a list made of given arguments. The syntax sugar for lists is `[]`.
2017-05-20 21:24:11 +02:00
`values [<item>]...`
Return an arbitrary number of values.
2017-05-06 14:12:46 +02:00
`if <cond> <body> [elif <cond> <body>]... [else <body>]`
Conditional evaluation.
2017-05-06 14:12:46 +02:00
2017-05-20 21:24:11 +02:00
`for <list> <body>`
2017-05-06 14:12:46 +02:00
2017-05-20 21:24:11 +02:00
Run the body for each element.
2017-05-06 14:12:46 +02:00
2017-05-21 12:24:04 +02:00
`break`
Abort the running loop.
2017-05-20 21:24:11 +02:00
`map <list> <body>`
2017-05-18 18:13:33 +02:00
2017-05-26 20:31:30 +02:00
Transform each element with the given function into any number of values.
2017-05-20 21:24:11 +02:00
`filter <list> <body>`
Return a new list consisting of matching elements only.
`.. [<string>]...`
2017-05-21 12:24:04 +02:00
Concatenate strings.
2017-05-20 21:24:11 +02:00
`print [<item>]...`
2017-05-21 12:24:04 +02:00
Print all items in sequence--strings directly, lists as source code.
`system <command>`
Run a system command and return its return value.
2017-05-25 14:38:43 +02:00
`parse <program>`
Parse a program into a list of lists.
`try <body> <handler>`
Execute the body and pass any error to the handler instead of propagating it.
`throw <message>`
Throw an error. Messages starting on an underscore don't generate backtraces,
2017-05-26 20:31:30 +02:00
which can be used to catch them.
2017-05-25 14:38:43 +02:00
`not <value>`
Return a boolean with the opposite truthiness.
`and [<body>]...`, `or [<body>]...`
Short-circuit evaluation, trying to return whatever the bodies result in.
2017-05-21 12:24:04 +02:00
`+`, `-`, `*`, `/`
Arithmetic operations on floating point numbers.
`=`, `<>`, `<`, `>`, `<=`, `>=`
Arithmetic comparisons on floating point numbers.
`eq?`, `ne?`, `lt?`, `gt?`, `le?`, `ge?`
Simple string comparisons.
2017-05-18 18:13:33 +02:00
2017-05-21 13:37:43 +02:00
Building and Running
--------------------
By default, running `make' will only build the interpreter:
$ make
$ ./interpreter greet.ell
Install development packages for GNU Readline to get a REPL for toying around:
$ make repl
$ ./repl
2017-05-25 14:38:43 +02:00
Possible Ways of Complicating
-----------------------------
2017-05-28 10:02:19 +02:00
* `local [_a _b _rest] @args` would elegantly solve the problem of varargs,
2017-05-27 20:20:49 +02:00
that is, unpack a list when names are list, and make the last element a list
when there are more arguments than names
2017-05-25 14:38:43 +02:00
* reference counting: currently all values are always copied as needed, which
is good enough for all imaginable use cases, simpler and less error-prone
2017-05-06 14:12:46 +02:00
Contributing and Support
------------------------
2018-06-24 03:49:31 +02:00
Use https://git.janouch.name/p/ell to report any bugs, request features,
or submit pull requests. `git send-email` is tolerated. If you want to discuss
the project, feel free to join me at ircs://irc.janouch.name, channel #dev.
2017-05-06 14:12:46 +02:00
2018-06-24 03:49:31 +02:00
Bitcoin donations are accepted at: 12r5uEWEgcHC46xd64tt3hHt9EUvYYDHe9
2017-05-18 18:13:33 +02:00
2017-05-06 14:12:46 +02:00
License
-------
This software is released under the terms of the 0BSD license, the text of which
is included within the package along with the list of authors.