Skip to content

Commit

Permalink
if-some
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Oct 17, 2024
1 parent a27c7dd commit c59e863
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/sci/impl/namespaces.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,16 @@
(defn if-some*
([&form &env bindings then]
(if-some* &form &env bindings then nil))
([_&form _&env bindings then else & _oldform]
(let [form (bindings 0) tst (bindings 1)]
`(let [temp# ~tst]
(if (nil? temp#)
([&form _&env bindings then else & _oldform]
(let [form (bindings 0) tst (bindings 1)
tmp (gensym "temp")]
`(let [~tmp ~tst]
(if (nil? ~tmp)
~else
(let [~form temp#]
~then))))))
~(with-meta
`(let [~form ~tmp]
~then)
(meta &form)))))))

(defn when-let*
[&form _&env bindings & body]
Expand Down
1 change: 1 addition & 0 deletions test/sci/error_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
["(str (map (fn [[a]] a) [0]))" [1 11]]
["(str (if-let [[a] 0] a))" [1 6]]
["(str (when-let [[a] 0] a))" [1 6]]
["(str (if-some [[a] 0] a))" [1 6]]
["(str (when-some [[a] 0] a))" [1 6]]]]
(try
(sci.core/eval-string snippet)
Expand Down

0 comments on commit c59e863

Please sign in to comment.