return "(fn* "..M._pr_str(obj.params).." "..M._pr_str(obj.ast)..")"
elseif types._atom_Q(obj) then
return "(atom "..M._pr_str(obj.val)..")"
- elseif type(obj) == 'function' then
+ elseif type(obj) == 'function' or types._functionref_Q(obj) then
return "#<function>"
else
return string.format("%s", obj)
end
function M.copy(obj)
+ if type(obj) == "function" then
+ return M.FunctionRef:new(obj)
+ end
if type(obj) ~= "table" then return obj end
-- copy object data
return utils.instanceOf(obj, M.Atom)
end
+-- FunctionRefs
+
+M.FunctionRef = {}
+function M.FunctionRef:new(fn)
+ local newObj = {fn = fn}
+ return setmetatable(newObj, self)
+end
+function M._functionref_Q(obj)
+ return utils.instanceOf(obj, M.FunctionRef)
+end
+function M.FunctionRef:__call(...)
+ return self.fn(...)
+end
+
return M