News for hackers. Stuff that matters.
Re:7 lines of code, 3 minutes: Implement a programming langu... by anthk on Monday May 11, 2026 @11:23AM (#48096234)
Simpler? Obfuscated? Lisp can be self-defining:

https://www.t3x.org/zsp/index.html

Half of CS and discrete math (sets, permutation...) becames self-evident with simple code.

From TCL/Tk I had nightmares with simple code with upvar.

See this book? https://discrete.openmathbooks.org/dmoi3/dmoi.html

With Zenlisp or any other you could basically do all the exercises as if it were a walk, making the definition of the functions self-evident as if they were bricks.

A classical factorial example in Zenlisp, as numbers are not actual 'numbers' but Lisp lists:

    (require 'rmath)

    (define (fac n)
      (fi '#1 '#1 n))

    (define  (fi a b n)
      (or (and (> b n) a)
       (fi
        (* a b)
        (+ b '#1)
        n)))

     (fac '#10)
     '#3628800
Here '#3628800 it's just (3 6 2 8 8 0 0), as Zenlisp it's written almost from the ground up to teach you how everything can be built from Peano axioms or very close (set theory and the like).

After tracing the 'fi' function, this is how it works on recursive basis:

    + (fi #1 #1 #10)
    + (fi #1 #2 #10)
    + (fi #2 #3 #10)
    + (fi #6 #4 #10)
    + (fi #24 #5 #10)
    + (fi #120 #6 #10)
    + (fi #720 #7 #10)
    + (fi #5040 #8 #10)
    + (fi #40320 #9 #10)
    + (fi #362880 #10 #10)
   + (fi #3628800 #11 #10)

In every iteration, the input values for fi are:

a = a * b

b = b +1

n = always 10.

When b hits 11, 11 is bigger than 10, so it returns 'a'. So, the factorial function: 10! = 109!, 109*8!... and so on.

There are no comments on this comment yet.