Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically puts list around functions in threading macros if absent #132

Merged
merged 2 commits into from
Jan 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions fennel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ local function macroGlobals(env, globals)
return allowed
end

local function addMacros(macros, ast, scope, parent)
local function addMacros(macros, ast, scope)
assertCompile(isTable(macros), 'expected macros to be table', ast)
for k, v in pairs(macros) do
scope.specials[k] = macroToSpecial(v)
Expand Down Expand Up @@ -2062,21 +2062,24 @@ end
local stdmacros = [===[
{"->" (fn [val ...]
(var x val)
(each [_ elt (ipairs [...])]
(table.insert elt 2 x)
(set x elt))
(each [_ e (ipairs [...])]
(let [elt (if (list? e) e (list e))]
(table.insert elt 2 x)
(set x elt)))
x)
"->>" (fn [val ...]
(var x val)
(each [_ elt (pairs [...])]
(table.insert elt x)
(set x elt))
(each [_ e (pairs [...])]
(let [elt (if (list? e) e (list e))]
(table.insert elt x)
(set x elt)))
x)
"-?>" (fn [val ...]
(if (= 0 (# [...]))
val
(let [els [...]
el (table.remove els 1)
e (table.remove els 1)
el (if (list? e) e (list e))
tmp (gensym)]
(table.insert el 2 tmp)
`(let [@tmp @val]
Expand All @@ -2087,7 +2090,8 @@ local stdmacros = [===[
(if (= 0 (# [...]))
val
(let [els [...]
el (table.remove els 1)
e (table.remove els 1)
el (if (list? e) e (list e))
tmp (gensym)]
(table.insert el tmp)
`(let [@tmp @val]
Expand Down