Updating the docs and somewhat packaging for submission
This commit is contained in:
parent
3fc5bff69c
commit
6c2c9190c9
5 changed files with 124 additions and 38 deletions
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
> The theme of the jam is "first-class comments".
|
> The theme of the jam is "first-class comments".
|
||||||
|
|
||||||
|
Okay so _enormous bong rip_ what is a comment anyway.
|
||||||
|
|
||||||
|
### Comments
|
||||||
|
|
||||||
```c
|
```c
|
||||||
// foo bar baz
|
// foo bar baz
|
||||||
```
|
```
|
||||||
|
@ -13,6 +17,16 @@
|
||||||
(def ^{:doc "foo bar baz"} <name> <value>)
|
(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
|
``` python
|
||||||
"""modules have __doc__ as a property defined by the FIRST heredoc-string in the file"""
|
"""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))
|
(+ a b))
|
||||||
```
|
```
|
||||||
|
|
||||||
- Object code
|
But these are both deeply syntactically limited.
|
||||||
- .... Other media?
|
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
|
What if we wanted to put other media in a "source" file?
|
||||||
(defn foo [a b]
|
What if the "doctest" grammar was something you could just type at the top level?
|
||||||
(!doc "")
|
Or you could embed YAML or SQL into a file without special escaping airs?
|
||||||
(!doctest "")
|
|
||||||
(!test "")
|
|
||||||
|
|
||||||
(!impl
|
## Enter Lilith
|
||||||
(+ a b)))
|
|
||||||
|
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
|
Where this gets really fun is that there are no restrictions on the number of sub-languages which Lilith can support.
|
||||||
(defn foo [a b]
|
For instance, Markdown could be a sub-language.
|
||||||
"---
|
|
||||||
doc: |
|
|
||||||
Adds a and b
|
|
||||||
|
|
||||||
---
|
``` lilith
|
||||||
doctest:
|
!def[docstring, md]
|
||||||
- in: (foo 1 2)
|
This module has a docstring, defined to be whatever the `md` language processor produces.
|
||||||
out: 3
|
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
|
We could even get real weird with it, embedding GraphViz graphs or YAML documents within a Lilith file and composing them all together.
|
||||||
#+TITLE: foo
|
|
||||||
* my bullet
|
### The Demo
|
||||||
#+BEGIN_SRC clojure
|
|
||||||
(defn foo [a b] (+ a b))
|
``` shell
|
||||||
#+END_SRC
|
$ python3 setup.py develop
|
||||||
|
$ lil
|
||||||
|
>>> print["hello, world!"]
|
||||||
|
hello, world!
|
||||||
```
|
```
|
||||||
|
|
||||||
`org-babel` `org-babel-tagle`
|
### Generating HTML with Markdown from the designdoc
|
||||||
|
|
||||||
``` clojure
|
``` shell
|
||||||
(defn foo [] ..)
|
$ 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.
|
||||||
|
|
3
projects/lilith/requirements.txt
Normal file
3
projects/lilith/requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
lark
|
||||||
|
markdown
|
||||||
|
prompt_toolkit
|
|
@ -1,5 +1,8 @@
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
|
with open("requirements.txt") as fp:
|
||||||
|
requirements = [l.strip() for l in fp.readlines()]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="arrdem.lilith",
|
name="arrdem.lilith",
|
||||||
# Package metadata
|
# Package metadata
|
||||||
|
@ -10,11 +13,15 @@ setup(
|
||||||
packages=[
|
packages=[
|
||||||
"lilith",
|
"lilith",
|
||||||
],
|
],
|
||||||
install_requires=[
|
package_data={"": [
|
||||||
"lark",
|
"src/python/lilith/*.lark",
|
||||||
],
|
"src/python/lilith/*.lil",
|
||||||
test_requires=[
|
]},
|
||||||
"pytest",
|
include_package_data=True,
|
||||||
"hypothesis",
|
install_requires=requirements,
|
||||||
],
|
entry_points={
|
||||||
|
"console_scripts": [
|
||||||
|
"lil = lilith.__main__:main",
|
||||||
|
],
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
0
projects/lilith/src/python/lilith/__init__.py
Normal file
0
projects/lilith/src/python/lilith/__init__.py
Normal file
|
@ -122,7 +122,7 @@ parser.add_argument(
|
||||||
parser.add_argument("-v", "--verbose", action="count", default=0)
|
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||||||
parser.add_argument("file", nargs="?", help="A file to start executing from")
|
parser.add_argument("file", nargs="?", help="A file to start executing from")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main():
|
||||||
opts, args = parser.parse_known_args()
|
opts, args = parser.parse_known_args()
|
||||||
|
|
||||||
if opts.verbose == 0:
|
if opts.verbose == 0:
|
||||||
|
@ -178,3 +178,7 @@ if __name__ == "__main__":
|
||||||
batch(opts, args, runtime)
|
batch(opts, args, runtime)
|
||||||
else:
|
else:
|
||||||
repl(opts, args, runtime)
|
repl(opts, args, runtime)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in a new issue