项目作者: meric

项目描述 :
Lisp是Lisp。 Lua是Lua。 Lisp和Lua是一体的。
高级语言: Lua
项目地址: git://github.com/meric/l2l.git
创建时间: 2012-01-26T13:38:35Z
项目社区:https://github.com/meric/l2l

开源协议:BSD 2-Clause "Simplified" License

下载


l2l

This language is a superset of Lisp and Lua.

Example

boolean.lisp, implements and, or special forms:

  1. @import quasiquote
  2. @import quote
  3. @import fn
  4. @import local
  5. @import do
  6. @import let
  7. @import cond
  8. (fn circuit_and (invariant cdr output truth)
  9. (cond cdr
  10. (let (
  11. car (:car cdr)
  12. ref (lua_name:unique "_and_value"))
  13. `\
  14. local \,ref = \,\(expize(invariant, car, output))
  15. if \,ref then
  16. \,(cond (:cdr cdr)
  17. (circuit_and invariant (:cdr cdr) output truth)
  18. `\\,truth = \,ref)
  19. else
  20. \,truth = false
  21. end)))
  22. (fn expize_and (invariant cdr output)
  23. (let (ref (lua_name:unique "_and_bool"))
  24. (table.insert output `\local \,ref = true)
  25. (table.insert output (circuit_and invariant cdr output ref))
  26. ref))
  27. (fn statize_and (invariant cdr output)
  28. (to_stat (expize_and invariant cdr output)))
  29. (fn circuit_or (invariant cdr output truth)
  30. (cond cdr
  31. (let (
  32. car (:car cdr)
  33. ref (lua_name:unique "_or_value"))
  34. `\
  35. if not \,truth then
  36. local \,ref = \,\(expize(invariant, car, output))
  37. if \,ref then
  38. \,truth = \,ref
  39. end
  40. end
  41. \,(cond (:cdr cdr)
  42. (circuit_or invariant (:cdr cdr) output truth)))))
  43. (fn expize_or (invariant cdr output)
  44. (let (ref (lua_name:unique "_or_bool"))
  45. (table.insert output `\local \,ref = false)
  46. (table.insert output (circuit_or invariant cdr output ref))
  47. ref))
  48. (fn statize_or (invariant cdr output)
  49. (to_stat (expize_or invariant cdr output)))
  50. {
  51. lua = {
  52. ["and"] = {expize=expize_and, statize=statize_and},
  53. ["or"] = {expize=expize_or, statize=statize_or}
  54. }
  55. }

Quick Start

  1. # Requires https://github.com/meric/leftry cloned as a sibling to this repo.
  2. git clone git@github.com:meric/leftry.git
  3. git clone git@github.com:meric/l2l.git
  4. cd l2l
  5. make clean
  6. make test
  7. make repl

Run the following commands:

  1. > (print "hello world")
  2. hello world
  3. > \print("hello world")
  4. hello world
  5. > (let (a 1) (print `\print(\,a)))
  6. print(1)
  7. > (let (a 1) (print (getmetatable `\print(\,a))))
  8. lua_block

Syntax Highlighting

l2l-syntax-highlighting

Naming

Lisp names are mangled into Lua by replacing non lua compliant characters
with lua compliant characters. (See the mangle function in l2l/reader.lua).

Lisp names can contain dashes, dots, alphabets, numbers, underscores, and many
more characters, but they must not consist of two dots consecutively unless
the name is .. (lua string concat) or ... (lua vararg).

This is so the compiler can mangle lua field accessor names
my_table.my_subtable-with-dashes.some_key properly.

Features

  • Mix Lisp and Lua in source code with backslash.

    1. \print(\(+ 1 2 3 4))
  • Quasiquoting Lua expressions.

    1. (table.insert output `\local \,ref = false)
  • Macro and special form aliasing.

  • Macro as modules.

    1. @import (let x); (x.let (y 1) (print y))
  • Custom special forms as modules.

    For example, boolean.lisp.

  • Zero-cost map, filter, reduce abstractions.

  • Implement special forms that can inline anonymous functions as macros.
  • Special forms in Lua.

    1. @import iterator
    2. \
    3. map(function(x) return x + 2 end,
    4. filter(function(x) return x % 2 == 0 end,
    5. map(function(x) return x + 1 end, {1, 2, 3, 4})))

    Compiles into (nested loops collapsed into a single pass):

    1. local ipairs = require("l2l.iterator")
    2. local vector = require("l2l.vector")
    3. local next38,invariant37,i39 = ipairs({1,2,3,4});
    4. local values41 = vector();
    5. while i39 do
    6. local v40;i39,v40=next38(invariant37,i39);
    7. if i39 then
    8. v40=v40 + 1;
    9. if v40 % 2 == 0 then
    10. v40=v40 + 2;
    11. (values41):insert(v40)
    12. end
    13. end
    14. end
    15. return values41

Philosophy

The Tao begot one. One begot two.

Laozi

Now I do not know whether I was then a man dreaming
I was a butterfly,

Or whether I am now a butterfly, dreaming I am a man.

Zhuangzi

I have put duality away, I have seen that the two worlds are one;

One I seek, One I know, One I see, One I call.

Jalaluddin Rumi

Now I do not know whether I was writing Lua inside of Lisp,

Or whether I am now writing Lisp, inside of Lua.

I have put duality away, I have seen that the two worlds are one;

One I read. One I write. One I compile. One I run.

You

Obligatory

I am the servant of the Qur’an as long as I have life.

I am the dust on the path of Muhammad, the Chosen one.

If anyone quotes anything except this from my sayings,

I am quit of him and outraged by these words.

Jalaluddin Rumi