Updating the docs and somewhat packaging for submission

This commit is contained in:
Reid 'arrdem' McKenzie 2021-08-21 22:25:31 -06:00
parent 7ef2f53db8
commit 89f9adc33c
5 changed files with 124 additions and 38 deletions

View file

@ -2,6 +2,10 @@
> The theme of the jam is "first-class comments".
Okay so _enormous bong rip_ what is a comment anyway.
### Comments
```c
// foo bar baz
```
@ -13,6 +17,16 @@
(def ^{:doc "foo bar baz"} <name> <value>)
```
Traditionally, comments are just text that the language throws away or that the compiler ignores.
For instance `//` or `;` comments just discard an entire line.
`/* ... */` or `(* ... *)` comments discard a block.
Languages that want to play games with comment inspection need customized parsers different from the one used by the language itself to extract this text which implementers usually just drop on the floor.
### Docstrings
Another take on the idea of putting text in the source file but privileging it more is docstrings - special strings understood by the language to have interpretation.
``` python
"""modules have __doc__ as a property defined by the FIRST heredoc-string in the file"""
@ -37,45 +51,103 @@ def foo(a, b):
(+ a b))
```
- Object code
- .... Other media?
But these are both deeply syntactically limited.
DSLs inside of strings .... are inside of strings.
Special separate parsers are required to work with or on them.
Users have to write those DSLs within the context of embedded strings.
It just doesn't work well.
``` clojure
(defn foo [a b]
(!doc "")
(!doctest "")
(!test "")
What if we wanted to put other media in a "source" file?
What if the "doctest" grammar was something you could just type at the top level?
Or you could embed YAML or SQL into a file without special escaping airs?
(!impl
(+ a b)))
## Enter Lilith
Lilith is a sketch at what if you took the ideas from literate programming (having fragments of text from which programs are composed) but deliberately DID NOT privilege the "source" for a "document" over the "source" for the "program".
Documents and programs could be co-equal and co-resident artifacts.
To achieve this vision, Lilith uses a context sensitive block-prefixed syntax which SHOULD be uncommon enough not to involve collisions with other languages.
Lilith is an [M-expression](https://en.wikipedia.org/wiki/M-expression) esque language with a "meta" language and two "object" languages.
The meta-language is `!` prefixed M-expressions.
At present the meta-language has two directives, `!def[<name>, <language>]` and `!import[<from>, ...]`.
This Lilith implementation is bootstrapped off of Python, and provides two built-in languages, `lil` AKA Lilith and `py` AKA python3.
Lilith interpretation is actually dual (or potentially N) interpreter based.
When a given name is evaluated, its body or definition is evaluated in the given language.
For instance, this snippet would define a pair of Lilith "foreign" functions in Python (`gt` and `sub`), which would then be used from the definiton of `fib`.
``` lilith
!def[gt, py]
return lambda x, y: x > y
!def[sub, py]
return lambda x, y: x - y
!def[fib, lil]
lambda[[x]
, cond[[gt[x, 1],
add[fib[sub[x, 1]], fib[sub[x, 2]]]],
[true,
0]]]
]
```
``` clojure
(defn foo [a b]
"---
doc: |
Adds a and b
Where this gets really fun is that there are no restrictions on the number of sub-languages which Lilith can support.
For instance, Markdown could be a sub-language.
---
doctest:
- in: (foo 1 2)
out: 3
"
)
``` lilith
!def[docstring, md]
This module has a docstring, defined to be whatever the `md` language processor produces.
For instance, this could be compiled HTML.
Or it could be source markdown, post-validation.
When executed, this module will evaluate the docstring and print it.
!def[main, lil]
print[docstring]
```
``` org
#+TITLE: foo
* my bullet
#+BEGIN_SRC clojure
(defn foo [a b] (+ a b))
#+END_SRC
We could even get real weird with it, embedding GraphViz graphs or YAML documents within a Lilith file and composing them all together.
### The Demo
``` shell
$ python3 setup.py develop
$ lil
>>> print["hello, world!"]
hello, world!
```
`org-babel` `org-babel-tagle`
### Generating HTML with Markdown from the designdoc
``` clojure
(defn foo [] ..)
``` shell
$ lil src/lark/designdoc.lil
<h1>The Lilith Pitch</h1>
<p>Code is more than .. just code for the compiler.
....
```
####################################################################################################
## Hackweek disclaimers
Python packaging is the devil.
This code was originally developed in [my monorepo](https://github.com/arrdem/source/tree/trunk/projects/lilith) where it is build and tested via a reproducible Bazel setup.
I don't want to try and make the judges install Bazel, so `python3 setup.py develop` is the lowest common denominator.
Note that `setup.py install` doesn't work for resource packaging reasons I haven't sorted out.
While this README may be stale of language features, at this time Lilith is mostly concerned with parsing, building a runtime/namespace system of and evaluating fragments.
While the machinery is there in the form of a relatively classical lisp `eval[]` operation to implement `if`, `lambda` and other such traditional special forms, that really wasn't the intent of the language syntax.
Most of Lilith's standard library (`src/python/lilith/prelude.lil`) consists of establishing a FFI prelude to Python, which makes the language seem more fully featured than it is.
**Currently missing:**
- `eval[]`
- `apply[]` (although this is trivial to implement)
- `if[]`
- `not[]`
- `=[]`
- `let[]`
## License
This code is copyright Reid D. 'arrdem' McKenzie 2021, published under the terms of the MIT license.

View file

@ -0,0 +1,3 @@
lark
markdown
prompt_toolkit

View file

@ -1,5 +1,8 @@
from setuptools import setup
with open("requirements.txt") as fp:
requirements = [l.strip() for l in fp.readlines()]
setup(
name="arrdem.lilith",
# Package metadata
@ -10,11 +13,15 @@ setup(
packages=[
"lilith",
],
install_requires=[
"lark",
],
test_requires=[
"pytest",
"hypothesis",
],
package_data={"": [
"src/python/lilith/*.lark",
"src/python/lilith/*.lil",
]},
include_package_data=True,
install_requires=requirements,
entry_points={
"console_scripts": [
"lil = lilith.__main__:main",
],
},
)

View file

@ -122,7 +122,7 @@ parser.add_argument(
parser.add_argument("-v", "--verbose", action="count", default=0)
parser.add_argument("file", nargs="?", help="A file to start executing from")
if __name__ == "__main__":
def main():
opts, args = parser.parse_known_args()
if opts.verbose == 0:
@ -178,3 +178,7 @@ if __name__ == "__main__":
batch(opts, args, runtime)
else:
repl(opts, args, runtime)
if __name__ == "__main__":
main()