4 ms·
“The problem is that increment is calling get and set here, but those functions haven’t been declared yet. Unlike JavaScript, Dart doesn’t silently hoist functi
by LeoNatan25 9y ago
“The problem is that increment is calling get and set here, but those functions haven’t been declared yet. Unlike JavaScript, Dart doesn’t silently hoist function declarations up.”
Huh? What is this, the 80s?
- Scarbutt 9y agoFWIW, Clojure also by default doesn't let you use functions before they are declared but gives you a construct to do it explicitly, which I haven't seen much in the wild. And since Clojure doesn't have full TCO I guess its use won't rise either.
- JadeNB 9y ago> FWIW, Clojure also by default doesn't let you use functions before they are declared but gives you a construct to do it explicitly, which I haven't seen much in the wild. And since Clojure doesn't have full TCO I guess its use won't rise either. Honest question: what does TCO have to do with use-before-declaration? (Maybe you mean that self-calls—not the only possible kind of tail call!—aren't natively allowed? I don't use Clojure, so I don't know if that's the case.)
- Scarbutt 9y agoHonest question: what does TCO have to do with use-before-declaration? Mutual recursion, tails calls to other functions. If you have two functions that each one calls each other you get a compiler error cause one of the two has not seen the definition of the other. Since selfs-calls are easy to implement they are supported explicitly in Clojure via the recur keyword, they won't blow up the stack, but tails calls to other functions are not posible(without using some weird trickery) in Clojure because of the limitations in the JVM.
- munificent 9y agoI'm not sure what you're getting at here. Are you arguing that function hoisting is the better behavior?
- fasquoika 9y agoNote that this is for locals, not toplevel function declarations. https://dartpad.dartlang.org/74e990d984faad26dea0 https://dartpad.dartlang.org/74e990d984faad26dea0