mirror of
https://github.com/kanaka/mal.git
synced 2024-09-11 21:57:38 +03:00
Change \177 to \u{029e}, correctly define keyword, change loadstring to load
This commit is contained in:
parent
a62a56f535
commit
e2b93732eb
@ -233,7 +233,7 @@ local function lua_to_mal(a)
|
||||
end
|
||||
|
||||
local function lua_eval(str)
|
||||
local f, err = loadstring("return "..str)
|
||||
local f, err = load("return "..str)
|
||||
if err then
|
||||
types.throw("lua-eval: can't load code: "..err)
|
||||
end
|
||||
@ -250,8 +250,14 @@ M.ns = {
|
||||
['number?'] = function(a) return types._number_Q(a) end,
|
||||
symbol = function(a) return types.Symbol:new(a) end,
|
||||
['symbol?'] = function(a) return types._symbol_Q(a) end,
|
||||
['string?'] = function(a) return types._string_Q(a) and "\177" ~= string.sub(a,1,1) end,
|
||||
keyword = function(a) return "\177"..a end,
|
||||
['string?'] = function(a) return types._string_Q(a) and "\u{029e}" ~= string.sub(a,1,2) end,
|
||||
keyword = function(a)
|
||||
if types._keyword_Q(a) then
|
||||
return a
|
||||
else
|
||||
return "\u{029e}"..a
|
||||
end
|
||||
end,
|
||||
['keyword?'] = function(a) return types._keyword_Q(a) end,
|
||||
['fn?'] = function(a) return types._fn_Q(a) end,
|
||||
['macro?'] = function(a) return types._macro_Q(a) end,
|
||||
@ -272,7 +278,7 @@ M.ns = {
|
||||
['-'] = function(a,b) return a-b end,
|
||||
['*'] = function(a,b) return a*b end,
|
||||
['/'] = function(a,b) return math.floor(a/b) end,
|
||||
-- ['time-ms'] = function() return math.floor(socket.gettime() * 1000) end,
|
||||
['time-ms'] = function() return math.floor(os.clock()*1000) end,
|
||||
|
||||
list = function(...) return List:new(table.pack(...)) end,
|
||||
['list?'] = function(a) return types._list_Q(a) end,
|
||||
|
@ -23,8 +23,8 @@ function M._pr_str(obj, print_readably)
|
||||
end
|
||||
return "{".. table.concat(res, " ").."}"
|
||||
elseif type(obj) == 'string' then
|
||||
if string.sub(obj,1,1) == "\177" then
|
||||
return ':' .. string.sub(obj,2)
|
||||
if string.sub(obj,1,2) == "\u{029e}" then
|
||||
return ':' .. string.sub(obj,3)
|
||||
else
|
||||
if _r then
|
||||
local sval = obj:gsub('\\', '\\\\')
|
||||
|
@ -46,15 +46,15 @@ function M.read_atom(rdr)
|
||||
elseif float_re:exec(token) then return tonumber(token)
|
||||
elseif string_re:exec(token) then
|
||||
local sval = string.sub(token,2,string.len(token)-1)
|
||||
sval = string.gsub(sval, '\\\\', '\177')
|
||||
sval = string.gsub(sval, '\\\\', '\u{029e}')
|
||||
sval = string.gsub(sval, '\\"', '"')
|
||||
sval = string.gsub(sval, '\\n', '\n')
|
||||
sval = string.gsub(sval, '\177', '\\')
|
||||
sval = string.gsub(sval, '\u{029e}', '\\')
|
||||
return sval
|
||||
elseif string.sub(token,1,1) == '"' then
|
||||
throw("expected '\"', got EOF")
|
||||
elseif string.sub(token,1,1) == ':' then
|
||||
return "\177" .. string.sub(token,2)
|
||||
return "\u{029e}" .. string.sub(token,2)
|
||||
elseif token == "nil" then return Nil
|
||||
elseif token == "true" then return true
|
||||
elseif token == "false" then return false
|
||||
|
@ -118,7 +118,7 @@ end
|
||||
|
||||
-- Keywords
|
||||
function M._keyword_Q(obj)
|
||||
return M._string_Q(obj) and "\177" == string.sub(obj,1,1)
|
||||
return M._string_Q(obj) and "\u{029e}" == string.sub(obj,1,2)
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user