Dwarf Fortress’ graphical upgrade provides a new way into a wildly wonky game


throwaway81523 11d
This is nice, I didn't know about named-let being usable for tail recursion. I have always liked the idea of a purescript back end for Emacs Lisp and having tail recursion makes it easier. Purescript is a typed functional language that is sort of a modernized Haskell with strict evaluation, originally written to give a typed language that compiles to Javascript, but now it has more backends while Typescript seems to have occupied the "typed JS" niche that Purescript had hoped to fill. (www.purescript.org for more info).
gigatexal 11d
I want to get my head wrapped around lisp but I just see code like this and my head hurts
kazinator 11d
That ela/apply function is actually reduce.

You cannot call the function multiple calls with funcall to implement apply; there has to be only one call to funcall.

Basically you have to ways:

Switch on different argument list lengths, to one of many funcall expressions that has a matching arity:

  (pcase args
    (() (funcall fn))
    (`(,a1) (funcall fn a1))
    (`(,a1 ,a2) (funcall fn a1 a2))
    (`(,a1 ,a2 ,a3) (funcall fn a1 a2 a3))
Or build the funcall dynamically and eval it:

  (eval `(funcall ,fn ,@args))
Lisp newbiews who don't know about apply sometimes end up simulating it like this.
djaouen 11d
Now this is the kind of content I come to HN for!
hddqsb 11d
First time I'm hearing about `named-let` and tail call optimisation in Emacs, thanks for sharing!

A clarification: Tail call optimisation in Emacs is not tied specifically to `named-let`, but it is tied to `cl-labels` (which `named-let` uses internally). Normal functions declared using `defun` don't currently support tail call optimisation.