Skip to content

Commit

Permalink
fix #696: add let* special form
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Mar 19, 2022
1 parent dac9591 commit b833ad0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For a list of breaking changes, check [here](#breaking-changes)
- [#693](https://github.com/babashka/sci/issues/693): extend protocol to IRecord doesn't work on SCI records
- [#695](https://github.com/babashka/sci/issues/695): `(identical? [] [])` works
- [#700](https://github.com/babashka/sci/issues/700): loop doesn't expand in fully qualified let
- [#696](https://github.com/babashka/sci/issues/696): add let* special form

## v0.3.2

Expand Down
5 changes: 3 additions & 2 deletions src/sci/impl/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

;; derived from (keys (. clojure.lang.Compiler specials))
;; (& monitor-exit case* try reify* finally loop* do letfn* if clojure.core/import* new deftype* let* fn* recur set! . var quote catch throw monitor-enter def)
(def special-syms '#{try finally do if new recur quote catch throw def . var set!})
(def special-syms '#{try finally do if new recur quote catch throw def . var set! let*})

(defn- throw-error-with-location [msg node]
(utils/throw-error-with-location msg node {:phase "analysis"}))
Expand Down Expand Up @@ -457,7 +457,7 @@
(fn [iden->invoke-idx]
(if (contains? iden->invoke-idx ob)
iden->invoke-idx
(assoc iden->invoke-idx ob (+ #_arity (count iden->invoke-idx))))))))
(assoc iden->invoke-idx ob (count iden->invoke-idx)))))))
closure-idx (get-in new-cb (conj parents :syms ob))]
closure-idx))

Expand Down Expand Up @@ -1220,6 +1220,7 @@
;; every sub expression
do (return-do ctx expr (rest expr))
let (analyze-let ctx expr)
let* (analyze-let* ctx expr (second expr) (nnext expr))
(fn fn*) (analyze-fn ctx expr false)
def (analyze-def ctx expr)
;; NOTE: defn / defmacro aren't implemented as normal macros yet
Expand Down
4 changes: 3 additions & 1 deletion test/sci/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@
'(let [x 3] (f) (f) x) {:bindings {'f #(swap! a inc)}})
@a)))))
(testing "nested lets"
(is (= [2 1] (eval* "(let [x 1] [(let [x 2] x) x])")))))
(is (= [2 1] (eval* "(let [x 1] [(let [x 2] x) x])"))))
(testing "let*"
(is (= [2 1] (eval* "(let* [x 1] [(let* [x 2] x) x])")))))

(deftest closure-test
(testing "closure"
Expand Down

0 comments on commit b833ad0

Please sign in to comment.