Hacker News new | ask | show | jobs
by maleldil 9 days ago
> You don’t program in Lisp, do you?

Not anymore. I started with Racket and went through the Little Schemer. I did Clojure for a while. I even used Babashka to write all my scripts, then later rewrote them in other languages.

I gave it a good try. Maybe it wasn't enough to properly "get it"?

2 comments

Aw man I love babashka. I will say the lack of static types in clojure is pretty brutal for me. Especially when combined with the obtuse error messages. But I still love babashka and the whole REPL driven world.

What did you end up rewriting your bb scripts in?

Python, Go, or Rust, depending on the complexity. Python (with strict typing) for the simplest ones, or those where startup time wasn't a concern, Go for the medium-complexity ones that I could do with only the standard library, and Rust for everything else. Besides lisps in general still feeling alien to me, I also really like static types.
If there's one thing that I sometimes wish Lisp had, it's types. Most of the time, I don't need or even want them. But when you're doing a big refactor or changing the shape of your primary data structure, it would be nice to have the compiler be able to assist you in detecting locations where you've cross-wired something. But other than that, I don't care. And yes, Clojure's error messages could be better, but they have been getting better over time.
> If there's one thing that I sometimes wish Lisp had, it's types.

Let's write some very silly code to turn an integer into a list of digits in Common Lisp:

  (deftype Digit ()
    "A non-negative integer smaller than 10."
    '(Mod 10))

  (defun integer->digits (integer)
    "Turns a given INTEGER into a list of digits."
    (declare (type Integer integer))
    (labels ((digit-loop (integer digits)
                (declare (type Integer integer)
                         (type List digits))
                (if (< integer 10)
                    (list* integer digits)
                    (multiple-value-bind (quotient remainder)
                        (truncate integer 10)
                      (declare (type Integer quotient)
                               (type Digit remainder))
                      (digit-loop quotient
                                  (list* remainder digits))))))
      (declare (ftype (Function (Integer List) List) digit-loop))
      (digit-loop (abs integer)
                  nil)))

  (digit-loop 2026) ; => (2 0 2 6)

  (digit-loop "2026")
  ; The value
  ;     "2026"
  ; is not of type
  ;     INTEGER
  ; when binding INTEGER
  ;
  ; Type HELP for debugger help, or (SB-EXIT:EXIT) to exit from SBCL.
  ;
  ; Restarts:
  ;   0: [ABORT] Exit debugger, returning to top level.
Yep, I know, but most Lisps do not have those declarations available and even in CL they aren’t used very often. But yes, they would help in CL.
That's a very reasonable try. Your statements are not unfounded. If I may ask, what's your daily driver now and why do you favor it over Lisps?
Python (with types), Go or Rust, depending on the complexity. I really missed static types in Clojure. I think no Lisp does static typing well. I guess there's Coalton, but it's too niche.