Something I don’t get. Odin doesn’t support closures (a la C++ or Rust) The thing is, I don’t understand why. Odin’s FAQ says it’s because closures require automatic memory management. [0] But if that’s the case, why do languages like C++ and Ada [1] support closures? [0] https://odin-lang.org/docs/faq/#does-odin-have-closures [1] https://learn.adacore.com/courses/advanced-ada/parts/resourc...
If Odin Had Macros
11–20 of 29 posts
Re: If Odin Had Macros
#12Re: If Odin Had Macros
#13Earlier quoted context omitted.
All of those languages have a lot of freedom, you just ("just") need to reach into the FFI to do it. Lua, which is the only one I have used extensively, is the most literal definition of scripting. It's designed to be written in conjunction with C. Even languages like Haskell with a gigantic runtime still expect you to put in some C for hot paths.
FFI scares me if I am being honest and that is why I always try to think of a language which can do a lot of things themselves without having to reach for FFI thinking its going to be my last resort most of the time. So that was my perspective when I had written up my comment. What are some really good languages for FFI? Lua as you suggest? I have always had this notion that FFI is really hard and so firstly I would…
Re: If Odin Had Macros
#14Something I don’t get. Odin doesn’t support closures (a la C++ or Rust) The thing is, I don’t understand why. Odin’s FAQ says it’s because closures require automatic memory management. [0] But if that’s the case, why do languages like C++ and Ada [1] support closures? [0] https://odin-lang.org/docs/faq/#does-odin-have-closures [1] https://learn.adacore.com/courses/advanced-ada/parts/resourc...
what ginger bill actually said was > I’d argue that actual closures which are unified everywhere as a single procedure type with non-capturing procedure values require some form of automatic-memory-management. That does not necessarily garbage collection nor ARC, but it could be something akin to RAII. This is all still automatic and against the philosophy of Odin. C++ doesn't have this feature either. A C++ closure…
> For closures to work correctly would require a form of automatic memory management which will never be implemented into Odin.
I suppose you can insist Bill thinks "correctly" means all that verbiage about unified types - but then a reasonable question would be why doesn't Odin provide these "not correct" closures people enjoy in other languages ?
RAII is entirely irrelevant, the disposal of a closure over a Goose is the same as disposal of a Goose value itself. In practice I expect a language like Odin would prefer to close over references, but again Odin is able to dispose of references so what's the problem?
Re: If Odin Had Macros
#15Making these types of programs relatively easy in Go (with stdlib ways to manipulate source code) has been a huge boon to the ecosystem (golangci-lint linters, code gen tools).
I'd love to see examples of what that looks like in Odin
Re: If Odin Had Macros
#16Something I don’t get. Odin doesn’t support closures (a la C++ or Rust) The thing is, I don’t understand why. Odin’s FAQ says it’s because closures require automatic memory management. [0] But if that’s the case, why do languages like C++ and Ada [1] support closures? [0] https://odin-lang.org/docs/faq/#does-odin-have-closures [1] https://learn.adacore.com/courses/advanced-ada/parts/resourc...
Rust shows that closures don't require automatic memory management, unless you consider Rust's static ownership analysis to be "automatic memory management", which I suppose you could, but it's all at compile-time, not runtime. Of course, it's fair if he doesn't want his language to have an ownership system, but ownership systems honestly aren't very complex, they're just different.
I just watched a recent Polonius talk ( https://m.youtube.com/watch?v=uCN_LRcswts ) and came away very impressed with the difficulty of implementing (or even modeling) the borrow checker. Or maybe you're referring to something else?
Re: If Odin Had Macros
#17Earlier quoted context omitted.
FFI scares me if I am being honest and that is why I always try to think of a language which can do a lot of things themselves without having to reach for FFI thinking its going to be my last resort most of the time. So that was my perspective when I had written up my comment. What are some really good languages for FFI? Lua as you suggest? I have always had this notion that FFI is really hard and so firstly I would…
PUC Lua is supposedly a bit of a pain for ffi, but I havent tried it myself. Luajit is some kind of crazy magic. You can (almost) just copy and paste the c header file into the ffi.cdef function and then start using c functions as if they were lua functions.
Re: If Odin Had Macros
#18Does anyone have good examples of the "metaprograms (programs that make/analyse a program" he's referring to? Making these types of programs relatively easy in Go (with stdlib ways to manipulate source code) has been a huge boon to the ecosystem (golangci-lint linters, code gen tools). I'd love to see examples of what that looks like in Odin
That's a little tricky because almost anything can be a metaprogram. They're basically used when something could be "simplified" by writing a DSL, but you don't want to invent a whole new language (but you're going to anyway).
But some examples off the top of my head:
- For HTTP routers: HTTP methods (GET/POST/PATCH/DELETE/QUERY) are used when requesting a route. Instead of setting up the boilerplate of registering a url route and handling the different possible http method calls, a developer might want to use a more ergonomic macro to handle all the setup. (e.g. @(, )
- For MVC Frameworks (Same thing for MVVM, MVCL, MV*, etc... frameworks): Making a Model, View and Controller Macro that takes a name and a function and hooks it up to the application.
- For standards implementations: Adding special/non-standard bounds checking that is only calculated during compile time and removed from runtime for performance purposes (e.g. This int can only be between the ranges of -12 378 and 10621 11012)
- For game design: This level can only be solved by following the specified sequence. During the compile/build step, a proofer is run that ensures that the conditions for solving the level still hold. That way if someone adds a teleport item later in development, it doesn't break earlier levels.
- For testing: To mark a test case for a function
Re: If Odin Had Macros
#19Re: If Odin Had Macros
#20Earlier quoted context omitted.
Rust shows that closures don't require automatic memory management, unless you consider Rust's static ownership analysis to be "automatic memory management", which I suppose you could, but it's all at compile-time, not runtime. Of course, it's fair if he doesn't want his language to have an ownership system, but ownership systems honestly aren't very complex, they're just different.
You really don't think ownership systems are that complex kibwen? I just watched a recent Polonius talk ( https://m.youtube.com/watch?v=uCN_LRcswts ) and came away very impressed with the difficulty of implementing (or even modeling) the borrow checker. Or maybe you're referring to something else?