Skip to content

vieiro/luacons

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

S-Expressions in Lua

Manipulating S-Expressions

See cells.lua

local cells = require 'cells'

local cons = cells.cons
local car  = cells.car
local cadr = cells.cadr
local cddr = cells.cddr
local list = cells.list
-- etc.

local _, c = list(3, 'A', 'B', 'C')
print(c)       -- (A B C)
print(car(c))  -- A
print(cadr(c)) -- B
print(cddr(c)) -- (C)

Reading S-Expresions

local reader = require 'reader'

local r = reader.new('(A    (B    "string"    -123.456    (C . D))) (x y)')
local c, errors = r:read()

print(#c)   -- 2
print(c[1]) -- (A (B "string" -123.456 (C . D))
print(c[2]) -- (x y)

See reader.lua

More examples

See test.lua for examples on how to do reading and for examples of use of 'map', 'zip' and 'apply'.

Features

  • 2014-01-23: list, map, apply, zip. Since Lua does not handle varargs properly adding an integer as companion to all varargs '{...}' and as result to all 'return' clauses.

  • 2014-01-21: reads quoted strings, parses some Scheme source code

  • 2014-01-20: cons, cdr, car, set-car, set-cdr et al cells.lua.

  • 2014-01-20: prints cells with cycles

  • 2014-01-20: a reader with line/column debugging info reader.lua

  • 2014-01-20: The in_c directory keeps an old C version that does not handle cycles properly (GC), but it's still kept there for historical reasons.

About

Different experiments to build cons-cells in Lua

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published