Skip to content

Commit

Permalink
when-some
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Oct 17, 2024
1 parent 512256c commit a27c7dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/sci/impl/namespaces.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,16 @@
(let [~x (first xs#)]
~@body))))

(defn when-some* [_ _ bindings & body]
(let [form (bindings 0) tst (bindings 1)]
`(let [temp# ~tst]
(if (nil? temp#)
(defn when-some* [&form _ bindings & body]
(let [form (bindings 0) tst (bindings 1)
tmp (gensym "temp")]
`(let [~tmp ~tst]
(if (nil? ~tmp)
nil
(let [~form temp#]
~@body)))))
~(with-meta
`(let [~form ~tmp]
~@body)
(meta &form))))))

(defn some->*
[_&form _&env expr & forms]
Expand Down
3 changes: 2 additions & 1 deletion test/sci/error_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@
["(str (for [[a] 1] (/ 1 a)))" [1 6]]
["(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 (when-let [[a] 0] a))" [1 6]]
["(str (when-some [[a] 0] a))" [1 6]]]]
(try
(sci.core/eval-string snippet)
(is false)
Expand Down

0 comments on commit a27c7dd

Please sign in to comment.