Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/l2lPublic

Lisp is Lisp. Lua is Lua. Lisp and Lua as One.

License

NotificationsYou must be signed in to change notification settings

meric/l2l

Repository files navigation

This language is a superset of Lisp and Lua.

Example

boolean.lisp, implementsand,or special forms:

@importquasiquote@importquote@importfn@importlocal@importdo@importlet@importcond(fncircuit_and (invariantcdroutputtruth)  (condcdr    (let (car (:carcdr)ref (lua_name:unique"_and_value"))`\local \,ref= \,\(expize(invariant,car,output))if \,refthen          \,(cond (:cdrcdr)              (circuit_andinvariant (:cdrcdr)outputtruth)`\\,truth = \,ref)else          \,truth=falseend)))(fnexpize_and (invariantcdroutput)  (let (ref (lua_name:unique"_and_bool"))    (table.insertoutput`\local \,ref = true)    (table.insertoutput (circuit_andinvariantcdroutputref))ref))(fnstatize_and (invariantcdroutput)  (to_stat (expize_andinvariantcdroutput)))(fncircuit_or (invariantcdroutputtruth)  (condcdr    (let (car (:carcdr)ref (lua_name:unique"_or_value"))`\ifnot \,truththenlocal \,ref= \,\(expize(invariant,car,output))if \,refthen            \,truth= \,refendend        \,(cond (:cdrcdr)            (circuit_orinvariant (:cdrcdr)outputtruth)))))(fnexpize_or (invariantcdroutput)  (let (ref (lua_name:unique"_or_bool"))    (table.insertoutput`\local \,ref = false)    (table.insertoutput (circuit_orinvariantcdroutputref))ref))(fnstatize_or (invariantcdroutput)  (to_stat (expize_orinvariantcdroutput))){lua= {    ["and"]= {expize=expize_and,statize=statize_and},    ["or"]= {expize=expize_or,statize=statize_or}  }}

Quick Start

# Requires https://github.com/meric/leftry cloned as a sibling to this repo.git clone git@github.com:meric/leftry.gitgit clone git@github.com:meric/l2l.gitcd l2lmake cleanmaketestmake repl

Run the following commands:

> (print "hello world")hello world> \print("hello world")hello world> (let (a 1) (print `\print(\,a)))print(1)> (let (a 1) (print (getmetatable `\print(\,a))))lua_block

Syntax Highlighting

l2l-syntax-highlighting

Naming

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

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

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

Features

  • Mix Lisp and Lua in source code with backslash.

    \print(\(+1234))
  • Quasiquoting Lua expressions.

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

  • Macro as modules.

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

    For example,boolean.lisp.

  • Zero-costmap,filter,reduce abstractions.

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

  • Special forms in Lua.

    @importiterator\map(function(x)returnx+2end,filter(function(x)returnx%2==0end,map(function(x)returnx+1end, {1,2,3,4})))

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

    localipairs=require("l2l.iterator")localvector=require("l2l.vector")localnext38,invariant37,i39=ipairs({1,2,3,4});localvalues41=vector();whilei39dolocalv40;i39,v40=next38(invariant37,i39);ifi39thenv40=v40+1;ifv40%2==0thenv40=v40+2;      (values41):insert(v40)endendendreturnvalues41

Philosophy

The Tao begot one. One begot two.
Laozi

Now I do not know whether I was then a man dreamingI 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


[8]ページ先頭

©2009-2025 Movatter.jp