Search Results

Found 1 results for "6c1eef56e0034ba5a6da27d32dbc9725" across all boards searching md5.

Anonymous /g/105527756#105531281
6/9/2025, 12:27:34 AM
>>105527496
>>105527550
You could implement addition using minimal primitives a few ways (the chars 0-9 can just be symbols):

;; peano
> (+ (quote (1 1 1)) (quote (1)))
(1 1 1 1)
;; binary
> (+ (quote (1 1 0 0)) (quote (1 0 0 0)) 0)
(0 0 1 0)
;; decimal
> (+ (quote (1 3)) (quote (1 1)))
(2 4)

Binary addition would look like (from wikipedia's truth table):

(set (quote +)
(lambda (a b c)
...
(if (and (eq (car a) 0) (eq (car b) 1) (eq c 1))
(cons 1 (+ (cdr a) (cdr b) 0))
...

If you're curious my lisp interpreter uses 93 lines of C to implement these primitives:

Pair *env =
...
intern("lambda"),
intern("if"),
intern("<"),
intern("+"),
intern("quote"),
intern("macro"),
intern("cons"),
intern("car"),
intern("cdr"),
intern("set"),
intern("null?"),
intern("pair?"),
intern("eq?"),
intern("not"),
intern("="),
intern("-"),
intern("string-length"),
intern("string-ref"),
intern("eval"),
intern("apply"),
intern("load"),
intern("display"),
intern("newline"),
intern("expand"),
intern("inspect"),
intern("radix"),
intern("environment"),
intern("symbols"),
intern("memory"),
intern("clear"),
intern("exit"),
...

and these derived forms in 337 lines of lisp:

t nil list caar cadr cdar cddr append splice cond quasiquote qq qq-list define define-macro map begin let letrec for assoc length filter reduce nth reverse when unless member union intersection > <= >= != and or abs * / quotient remainder min max iota ! modulo even? odd? for-each zero? negative? positive? assoc-let zip format-internal format

< and = is enough to implement > <= >= != min max even? odd? zero? negative? positive?
+ and - is enough implement * / abs quotient remainder iota ! (and expt, which i forgot)
so if you add a few more primitives your Lisp can be pretty featureful while keeping the implementation minimal, gl anon