lazily evaluated
MarisaKirisame opened this issue · 15 comments
Wondering a clearer description
Functions' results should be lazy evaluated.
Functions' results should be lazily evaluated.
Or better yet,
Functions should be lazy.
but how do I achieve that? Or how should it be like?
4instance:
(def square n (* n n))
(def getn (|>
(println "evaluated")
(+ 100 200)))
(square (getn))
should it print once or twice the word "evaluated"?
If twice, it will be very slow(without saving the result).
If once, it might behave strangely with multi-threading.(Also needs a large refactor)
Scheme will print once.
That is to say scheme saves the result of first evaluation, and return the same value afterwards.
Clojure uses lazy evaluation optionally, whether to lazy evaluate or not, depends on you.
I've done a part of it.
- For conditional clauses(if, while, when), it's lazily evaluated. But in the repl, they'll still be evaluated(because the repl want to print them)
- For functions, they can't be lazily evaluated because of that fucking dynamic scoping.
@MarisaKirisame So is that acceptable?
Why Dynamic Scoping than.
Change too many features at the same time would make everything difficult.
I'll do the fucking lambda first.
There should be 3 types of lambdas:
\ is cbv
\ is cbneed
\\ is cbname
\ cbv
\\ cbneed
\\\ cbname
if you have cbneed, you dont need cbname
cbneed can be easily implemented in the language, as long as you have assignment.
That is to say I should change (defexpr) into cbneed, and give up cbname
Yes.
Another choice is to keep assignment and use cbv, and simulate laziness
Now, defexpr becomes cbneed. cbname is given up.
I used unit test to prove that's true.
So is that acceptable?
If so, I'll close this issue, and go working on lambda.