97 points · by PaulHoule · 1y ago · 88 comments
I believe I saw someone demonstrate that almost nothing in a Lisp implementation was written as a "built-in" language feature that required the underlying interpreter to provide the functionality.
https://news.ycombinator.com/item?id=9699065
https://speakerdeck.com/nineties/creating-a-language-using-o...
I could imagine writing a very basic forth or lisp compiler in assembler, but even that would be quite the project.
The parser is very simple thanks to the s-expressions, and the only builtin special forms really needed are quote, cond and lambda, that’s pretty much it. The only data structure is a list, so functions are just lists, function calls are lists etc.
It does not need to be compiled to be a Lisp. It doesn't need arbitrary precision integers. It doesn't need hash tables. Garbage collection doesn't have to work; it can just run out of space and terminate. It can just crash on errors without a trace. It doesn't need to report the line number where a syntax error likely began. You get the picture.
Any memory management solution will run out of space and terminate unless there is literally infinite memory available.
But I guess hash tables is what people think about when thinking about what makes something a lisp or not.
See?
There you go, mrweasel; I think we hit the nail on the head.
quoting the submission verbatim:
The original paper of LISP by John McCarthy http://www-formal.stanford.edu/jmc/recursive.html
Or the more accessible explanation by Paul Graham http://www.paulgraham.com/rootsoflisp.html
Also I've moved it from Github to my own Forgejo instance: https://git.liten.app/krig/LISP
My impression of Odin is that it's a better C while still very much retaining the same flavor as C. It adds very little (no classes, no runtime) so porting from C is very straightforward, and it fixes a lot of the dark corners of C. It also seems to be pretty much finished as far as the language goes, so no big incompatible changes coming as far as I can tell.
I would say though that while the memory management story is vastly better than C^, it's still manual as fuck, so be prepared for that.
^: There's builtin test support, bounds checking and an optional leak detection allocator, plus as far as I know no UB.
https://git.liten.app/krig/LISP/src/branch/main/komplodin.od...
Andy Wingo has a good summary of how a very similar implementation works:
https://www.wingolog.org/archives/2022/12/10/a-simple-semi-s...
This mostly just ends up meaning that Odin's creator Ginger Bill will engage in pointless semantic arguments in which he defines away your problem.
There are places where C could reasonably have chosen to define what happens, or to make it Unspecified rather than Undefined, and so that's what Odin chooses, which is a meaningful benefit. However there are plenty of situations left in which what you've written would be UB in C and absolutely anything might happen, while in Odin absolutely anything might happen but Bill insists it isn't UB.
Are there two types of assignment?
p1[0] = 0
...
n := 0
What should this mean? The comma notation usually indicates a pair or left-to-right control flow (Python and C, respectively), but why (appear to) assign a pair to itself?
This probably means something else, but it reads odd. car, cdr := car, cdr
If Odin is so similar to C, what are the "dark corners" where it outshines it?>
> p1[0] = 0
> ...
> n := 0
>What should this mean? The comma notation usually indicates a pair or left-to-right control flow (Python >and C, respectively), but why (appear to) assign a pair to itself? This probably means something else, but it reads odd.
= is assignment and := is assignment and declaration.
x := 1 // create a new variable x with the value 1
x = 2 // assign 2 to x
y = 3 // error: y does not exist
You can explicitly give the variable a type by adding it before the = x : u8 = 1 // a one byte unsigned integer with the value 1
There is also :: for constants.> car, cdr := car, cdr
Odin has multiple assignment like Python, so this is a swap without temporary. edit: No, it isn't! Didn't read carefully. Swap would be
car, cdr = cdr, car
This one is because parameters are immutable in Odin, so to get a mutable copy in the function we have to declare it.> If Odin is so similar to C, what are the "dark corners" where it outshines it?
Off the top of my head:
- No undefined behaviour
- Builtin string type, dynamic array type, slices
- Builtin map type
- Excellent tooling for 3D math: swizzling, matrix math, array programming
- Bounds checking
- Tooling for memory management: leak detection, temp allocator, arena allocators
- Builtin unit test framework
- Tagged unions with exhaustiveness checked switch statement
- for ... in loop syntax
The function/struct definition in C could be placed in a header.
Glad he has helped you. Maybe he listened to me, maybe not, but last time (almost year ago?) I saw an interaction with him on GitHub, he was nothing short of an a**hole, and not in the sense of Linus or Theo. In fact, he was not educational, he was just like "Many problems. I could write this better, GTFO". I saw it on GitHub, so I am reluctant to submit a PR of any sort myself in before he tells me he can implement it better and rejects my PR with this reasoning as he did with someone else. Like yeah, of course you may be able to implement it better, whereas someone new to the language might not, even though I tried it (the rejected PR, which was supposed to end up in vendor/ not the core library, AFAIK) and it was fully functional (and without any leaks), and to my eyes it seemed fine as well, but maybe I do not know Odin enough. In fact, I probably do not know it as much as he does, but by his logic, everything should be implemented by him because he knows better. This experience (albeit not mine) was enough to put me off of Odin. The C3 lead developer, on the other hand, was extremely helpful here on HN and on GitHub as well.
I have a feeling he has helped you because of the article and some fame along with it. :)
So my comment reflects a negative publicity. I cannot find the GitHub link right now, but it is there as it cannot be deleted, AFAIK. Look around rejected PRs in / for vendor/, I think. I am not logged in to GitHub and I cannot do so at the moment.
Just my second-hand experience. Feel free to down-vote but please leave a comment afterwards. Not everyone and everything is sunshine and butterflies. The down-votes DO NOT invalidate anything. Or perhaps Bill's bots / fans are in play here. ;) God forbid someone voices negative experiences with a person. Only positives are allowed! I forgot...
"Please don't post insinuations about astroturfing, shilling, brigading, foreign agents, and the like. It degrades discussion and is usually mistaken. If you're worried about abuse, email hn@ycombinator.com and we'll look at the data." - https://news.ycombinator.com/newsguidelines.html
You half remember one blunt interaction that you conveniently can't find and you're dedicating your life to shitting on him and his project. How is that on-topic here?
Do you have any specifics?
I removed the link now.
But I’m also an old. If someone tells me my code is shit, 1) they are probably right, and 2) I don’t really care. I can probably look at their code and find flaws in it.
In the end, Odin is Bills project and he decides what goes into it, I’m fine with that.
> In the end, Odin is Bills project and he decides what goes into it, I’m fine with that.
Me too. I am just not going to contribute. No big deal.
> I haven’t had any such experience, quite the opposite.
Just to add some positive, too: I have had positive experiences with other contributors.
In any case, I follow the programming language's developers before I contribute, as you may have noticed.
[1] But then again, I do not know the language too well either. Those pointers would have helped me and many others.
Makes sense! Plenty of other languages and projects out there.
That explains why the C code is so neat. You don't see young'uns write such compact C code any more. Well done.
After years using higher-level languages, my C code has become verbose and clunky, when it doesn't necessarily have to be (and memory safety is no concern)
Of course, git cloning the ALE plugin (linter + languageserver) for VIM also fails as ALE has an .odin file in its repo.