Skip to content

Commit

Permalink
Reimplement variadic if without recursion (closes hylang#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
refi64 committed Aug 7, 2017
1 parent 7e5d483 commit 00a9a11
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions hy/core/bootstrap.hy
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
"if with elif"
(setv n (len args))
(if* n
(if* (= n 1)
(get args 0)
`(if* ~(get args 0)
~(get args 1)
(if ~@(cut args 2))))))
(do
(setv args (list args))
(setv else-branch (if* (% n 2) (.pop args) `None))
(.reverse args)
(reduce (fn [current-else [then-branch cond]]
`(if* ~cond ~then-branch ~current-else))
(zip (cut args None None 2) (cut args 1 None 2))
else-branch))))

(defmacro macro-error [location reason]
"error out properly within a macro"
Expand Down

0 comments on commit 00a9a11

Please sign in to comment.