53 points by PaulHoule 3 days ago | 5 comments
mrweasel 41 minutes ago
Is there something inherent to Lisp that allows it to be implemented in so little code?

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.

krig 24 minutes ago
First off, you wouldn’t write an actual interpreter for lisp like this if you wanted to use it for anything serious, it’s very slow.

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.

jll29 55 minutes ago
Thanks for sharing. Not knowing Odin's syntax yet, having had a quick look at the code, a few things are strange:

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?
krig 35 minutes ago
> 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.

= 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

krig 3 hours ago
This is my project! I made the Odin version to learn the language, not to create a 1:1 comparison. I 100% prefer Odin over C and will use it wherever I can where I would have otherwise used C.

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.

krig 2 hours ago
Maybe the most interesting part is the semi-space garbage collector. The whole thing fits in a single screen:

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...

psychoslave 1 hour ago
Does it get ride of undefined behavior and the tradition of obfuscating the code with monoletter identifiers?
krig 1 hour ago
Yes. There is no undefined behavior in Odin (afaik), and I haven’t seen many monoletter identifiers. There is a slice type and a for … in loop statement so that gets rid of most i:s and j:s.
tialaramex 26 minutes ago
> There is no undefined behavior in Odin

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.

krig 20 minutes ago
Well, without concrete examples this just sounds childish TBH.

But I haven’t looked very closely at it myself, hence the afaik qualifier.

gritzko 4 hours ago
It lacks a conclusion, except I can see that 750>500
fithisux 3 hours ago
At first look the Odin version seems less verbose.

The function/struct definition in C could be placed in a header.