Skip to content(if available)orjump to list(if available)

Typed Lisp, a Primer

Typed Lisp, a Primer

67 comments

·May 4, 2025

breadchris

I have really fallen in love with LISP recently, specifically clojure. A strong type system is really needed for it to make me feel like I can confidently develop with it.

vindarel

just get Common Lisp with this new Clojure collection and sequence API! https://github.com/dtenny/clj-coll

nextos

A modern CL that borrows ideas from Clojure, and with a strongly typed language (Coalton) also available is indeed very appealing!

vosper

Have you (or anyone else reading this) used Coalton? What's your experience been like? Seems quite appealing to me.

lucyjojo

there is typed clojure out there if you want

https://typedclojure.org/

jodleif

You could also consider getting into pre/post conditions and specs - helps a lot especially at points with user/data input

bmitc

There is Typed Racket.

codr7

The main issue I have with CLs type checking is the clunky syntax and the fact that it looks different in different contexts.

I made an attempt to fix that for eli: https://github.com/codr7/eli#type-checking

norman784

I don't particularly like the syntax for the types, but I can't also think of a better way to implement it without adding a special case in the parser/compiler for it, right now with your syntax I believe, correct me if I'm wrong, it can be implemented with a macro in any Lisp

recursivecaveat

Are those compile-time type checks or runtime assertions?

codr7

Mix, similar to CL but slightly more runtime atm.

rjsw

Your eli looks clunky to me.

codr7

Well, use something else.

And maybe ask yourself why you felt saying so was important to you.

null

[deleted]

dokyun

    (the number (+ 35 7))
is a lot less clunky than

    (+ 35 7)@Numeric

eggy

You should check out Shen[1]. It is a portable functional programming language. Optional type checking and it solves my affair with Lisp and Haskell. It is a Lisp.

[1] https://shenlanguage.org/

klibertp

It needs a lot more good tutorials about its type system. Lacking the background in whatever subfield of math that would help here, I couldn't type my way out of a wet paper bag in it. I'd love a concise, down-to-earth, exposition of the type system "for the working programmer". It's just so different than anything else I know (from Haskell to Prolog) that I had a really hard time understanding Shen's type system.

eggy

You're right: Shen's mathematical underpinnings (sequent calculus, dependent type theory) can intimidate programmers without a formal logic background. I bought the "The Book of Shen" (TBOS) revision 1 and revision 3. Revision 4 is available on the website. It's a great book with some CS history, logic, and development of Shen from Qi as well as how everything works in Shen including the type system.

Shen uses a dependently typed Sequent-Calculus based Type System (SCTS). It uses type rules vs. type classes, and type checking is optional, you can turn it on or off. Haskell's type inference makes things a bit simpler, and is a battle-tested static type system with excellent type inference which lends itself better for functional programming and large-scale software engineering (for the moment). Shen's TC is more expressive, but requires more effort.

Aditya Siram has some old but goody YT videos on Shen.

klibertp

I wanted to buy it - I don't remember exactly, but I think I couldn't find an e-book version, and the paper one was expensive and didn't even ship to my country :( I hope to be wrong on that, though, do you know if there's an ebook available from somewhere?

droideqa

I had such high hopes for Shen but the licensing shenanigans at the beginning prevented it from having a great, large open source community.

eggy

It's resolved. I helped support it for a brief time for the SP version, which is now integrated into the latest version. You're right though, that this put many people off.

wizzard0

of all things, this is the most beautifully formatted and organized LISP guide i've ever met.

NikkiA

praising 'loop' in the same post as describing lisp as 'elegant' shakes head

codr7

Some people seem to like it, and be very effective using it.

The problem is it's a walled garden, with its own quirky syntax; nothing that happens inside of loop is applicable outside, and the other way around.

kagevf

My opinion of LOOP started to change when I read (the much maligned) "Land of Lisp" and went over that "periodic" diagram in TFA. Seeing the elements of LOOP broken down like that went a long way to get me to overcome my original aversion to it.

Jach

Who is maligning Land of Lisp?

shawn_w

I feel bad for people who haven't discovered ITERATE yet.

Jach

I'll never understand the love for iterate. Look at these comparisons: https://github.com/sabracrolleton/sabracrolleton.github.io/b... For almost all of them, it's the same guy, just more parens. Nothing to love/hate for one or the other, it's just preference, though one is built-in.

BoingBoomTschak

The big plus for me is that the ad-hoc if/when/do are removed in favour of the standard operators, without the horrible then/else/end/and dance.

Then you got all the life-improving goodies (in-{sequence,string,file,stream}, index-of-*, previous, etc...) that really add up to something.

shawn_w

Looks more lispy because the parens. Plus it's extendable unlike LOOP, so you can make it work with your own data types. And a few other nice features like being able to collect into a vector or other sequence, not just lists.

Jtsummers

ITERATE still breaks when you use `count` inside it, the built-in CL function. If they ever address that problem I'll get back to use it but having a time bomb in my programs isn't something I like.

Trivial example of breakage:

  (iter (for i from 1 to 10)
    (print (count i some-sequence)))

shawn_w

Breaks how? I'm on my phone, not a computer right now and can't test, but that should call the CL function - ITERATE uses `counting` for that particular operation to avoid conflicts; see https://iterate.common-lisp.dev/doc/Gathering-Clauses.html

Or is the documentation wrong?

BoingBoomTschak

It's been marked as deprecated for some time, but still needs manual removal as of now: https://gitlab.common-lisp.net/iterate/iterate/-/blob/master... (removing https://gitlab.common-lisp.net/iterate/iterate/-/blob/master... should work, I think).

Still better than the loop abomination, IMO.

gitroom

honestly i kinda love when deep dives like this pop up, makes me rethink stuff i thought i'd settled on - you think things ever get simple with lisp or it always stays quirky no matter how you do it