Add tests for eval#868
Conversation
|
Note that this does not test ClojureScript |
This is how I'd do it, too. All good. |
|
Oh, actually, can we just have one reader conditional, as a top-level |
| (is (= 43 (eval '(let [y 43] (or false y))))) | ||
| (is (= 43 (eval '(loop [y 0] (if (= y 43) y (recur (inc y))))))))))) |
There was a problem hiding this comment.
Note that both of these are macros and not special forms. That's not to say this is wrong, it's just not exactly testing what's commented. let* and loop* are the special forms, which would work just as well here. The macros just add destructuring support.
There was a problem hiding this comment.
Hm. I relied on https://clojure.org/reference/special_forms for the list of special forms. And the doc strings for both let and loop say they are special forms. For example:
user> (doc loop)
-------------------------
clojure.core/loop
(loop [bindings*] exprs*)
([bindings & body])
Special Form
Evaluates the exprs in a lexical context in which the symbols in
the binding-forms are bound to their respective init-exprs or parts
therein. Acts as a recur target.
Please see http://clojure.org/special_forms#loop
and
user> (doc let)
-------------------------
clojure.core/let
(let [bindings*] exprs*)
([bindings & body])
Special Form
binding => binding-form init-expr
binding-form => name, or destructuring-form
destructuring-form => map-destructure-form, or seq-destructure-form
Evaluates the exprs in a lexical context in which the symbols in
the binding-forms are bound to their respective init-exprs or parts
therein.
See https://clojure.org/reference/special_forms#binding-forms for
more information about destructuring.
Please see http://clojure.org/special_forms#let
Spec
args: (cat :bindings :clojure.core.specs.alpha/bindings :body (* any?))
ret: any?
| #?(:cljs nil | ||
| :default (testing "Lists, function application, and macros" | ||
| ;; empty list evaluates to itself | ||
| (is (= '() (eval '()))) |
There was a problem hiding this comment.
What are you trying to test with that? That it doesn't get realized?
There was a problem hiding this comment.
So, eval'ing an infinite range returns a clojure.lang.Iterate object. I'm not even sure what that is.
user> (class (eval '(range)))
clojure.lang.Iterate
What are you wanting to test with that?
There was a problem hiding this comment.
Interestingly, eval'ing a fixed range returns a clojure.lang.LongRange:
user> (class (eval '(range 10)))
clojure.lang.LongRange
There was a problem hiding this comment.
What are you trying to test with that? That it doesn't get realized?
Yep.
So, eval'ing an infinite range returns a clojure.lang.Iterate object. I'm not even sure what that is.
That's the type of (range).
Interestingly, eval'ing a fixed range returns a clojure.lang.LongRange:
LongRange was the type that went in. The Long is because each value is a Long (i.e. 10 is a Long).
So, eval clearly doesn't realize the seq, from the behavior. That's a great test case to have.
There was a problem hiding this comment.
So, how do I test for not being realized, exactly? Is it just that I get something back at all, because if it tried to realize the infinite sequence it would wait until the full sequence was realized and finally throw and OOM exception?
There was a problem hiding this comment.
Exactly. If we get it back and continue running the test, we can know that it wasn't realized.
|
I think this is good to go now. |
|
Great work, Dave! |
Closes #259