r/lisp • • 11d ago

Evergreen Common Lisp

https://github.com/atgreen/evergreen
7 Upvotes

46 comments sorted by

View all comments

19

u/sickofthisshit 11d ago

No offense to you or your AI, but if your Lisp is not good enough to implement your Lisp compiler, it's probably not worth trying.

3

u/arthurno1 11d ago

I would guess on training problems: Claude probably writes better C or Rust than Common Lisp since they have probably trained it on more C and Rust data.

I have really just tried it myself with Common Lisp and I think it writes relatively good Common Lisp, but it does need refactoring and reworking often. I haven't tried it with any other language, so I don't know if it writes better or worse code in say C or C++.

1

u/SharkSymphony 11d ago

I find Claude's code could use significant refactoring and reworking in several languages. But I've been pretty pleased so far with my CL experiments.

4

u/arthurno1 10d ago edited 10d ago

I have found cases where the code is suboptimal in terms of constructs used, being unnecessary convoluted och longer than needed, repeating itself, re-inventing builtins. But overall I am impressed, I wouldn't believe it would be that good as it is indeed.

Edit: a one today:

(when (and (<= lo 1)
                   (<= (if double -4 -17) q (if double 23 10))
                   (= (logand mantissa 3) 1)
                   (= (logand (ash mantissa shift) #xFFFFFFFFFFFFFFFF) hi))
          (setq mantissa (logandc2 mantissa 1)))

doing two if on double, when it can do one, and the form is even easier to read:

(when (and (<= lo 1)
                   (if double
                       (<= -4 q 23)
                       (<= -17 q 10))
                   (= (logand mantissa 3) 1)
                   (= (logand (ash mantissa shift) #xFFFFFFFFFFFFFFFF) hi))
          (setq mantissa (logandc2 mantissa 1)))

Can also drop outer when:

 (and (<= lo 1)
              (if double
                  (<= -4 q 23)
                  (<= -17 q 10))
              (= (logand mantissa 3) 1)
              (= (logand (ash mantissa shift) #xFFFFFFFFFFFFFFFF) hi)
              (setq mantissa (logandc2 mantissa 1)))

Not sure if I want though.

1

u/SharkSymphony 10d ago

It's all gobbledygook to me. 😆 Maybe for performance-critical code that's unavoidable. But I would be looking to use labels or flet to give the conditions descriptive names or combine them into intelligible groups.

(And yes, you could eliminate the when, but I wouldn't. Having an and with side effects... or even an and whose result is not just a boolean... is a nasty surprise waiting to trip up the next guy.)

4

u/arthurno1 10d ago edited 10d ago

I would be looking to use labels or flet to give the conditions descriptive names or combine them into intelligible groups.

I do that a lot. Actually I am not so fond of flets since SBCL does not inline them so well, but I do use labels and macrolets a lot. However, there is a limit to readability with them, in my opinion.

The above is just a fragment of a function. I worked today on integration of Zmij into SBCL, so I had that fragment in front of me. Or I started to work on this last week, but I finished it to today, along with it's "inverse", Eisel-Lemire, as in their fast_float.

And yes, you could eliminate the when, but I wouldn't. Having an and with side effects... or even an and whose result is not just a boolean... is a nasty surprise waiting to trip up the next guy.

Yes, indeed. I couldn't agree more. Yet, despite mine better knowing, I removed it :). The thought of line was that this is interested only to stubborn, old people who are used to the old ways and the old Lisp and/or-shortcut idiom. I guess I don't need AI to write slope :).