Skip to content

Instantly share code, notes, and snippets.

View daniel-cussen's full-sized avatar

Daniel Cussen daniel-cussen

  • Bay Area
View GitHub Profile
@daniel-cussen
daniel-cussen / gist:836384
Created February 20, 2011 22:35
Arithmetic on linked lists
(defun plus1. (lst)
(cond ((null. lst) (cons '1 '()))
((eq (car lst) '1)
(cons '0 (plus1. (cdr lst))))
('t (cons '1 (cdr lst)))))
(defun minus1. (lst)
(cond ((null. lst) '())
((and. (null. (cdr lst)) (eq (car lst) '1)) '())
((eq (car lst) '0)
@daniel-cussen
daniel-cussen / gist:840791
Created February 23, 2011 17:43
Logical operations to implement Lisp in Lisp
(defun null. (x)
(eq x '()))
(defun and. (x y)
(cond (x
(cond (y 't)
('t '())))
('t '())))
(defun or. (x y)
@daniel-cussen
daniel-cussen / gist:840807
Created February 23, 2011 17:50
Golomb forests
(defun fullness. (tree size)
(cond ((null. size)
'(1))
((null. (cdr tree))
(fullness. (car tree) (minus1. size)))
('t (+. (ash+. '(1) (minus1. size)) (fullness. (cdr tree) (minus1. size))))))
(defun length. (glf size)
(cond ((null. glf) '())
((or. (null. (cdr glf))
@daniel-cussen
daniel-cussen / gist:840810
Created February 23, 2011 17:52
Other functions (I think for "writing" to the memory)
(defun assoc. (atom a x)
(cond ((eq atom (car (g-nth. x a '())))
(cdr (g-nth. x a '())))
('t (assoc. atom a (minus1. x)))))
(defun append. (glf1 glf2 x)
(cond ((eqnum. x (length. glf2 '()))
glf1)
('t (append. (g-add. (g-nth. x glf2 '()) glf1 '() (length. glf1 '())) glf2 (plus1. x)))))
@daniel-cussen
daniel-cussen / gist:840812
Created February 23, 2011 17:53
#'eval., #'evcon., and #'evlis.
(defun eval. (e a)
(cond
((atom e) (assoc. e a (minus1. (length. a '()))))
((atom (car e))
(cond
((eq (car e) 'quote) (caadr e))
((eq (car e) 'atom) (atom (eval. (caadr e) a)))
((eq (car e) 'eq) (eq (eval. (caadr e) a)
(eval. (cdadr e) a)))
((eq (car e) 'car) (car (eval. (caadr e) a)))
@daniel-cussen
daniel-cussen / gist:840817
Created February 23, 2011 17:55
Test module
(defun trellis (&rest args)
(if (and (oddp (length args)) (null (car (last args))))
(sentinel-change. (trellis-1 0 args))
(trellis-1 0 args)))
(defun trellis-1 (size lst)
(cond ((null lst) nil)
((= size 0) (cons (car lst) (trellis-1 1 (cdr lst))))
(t (let ((siz (expt 2 size)))
(if (> siz (length lst))
@daniel-cussen
daniel-cussen / gist:840821
Created February 23, 2011 17:56
Traditional syntax for #'cond
(cond ((eq 'a 'a) 't)
('t '()))
@daniel-cussen
daniel-cussen / gist:840827
Created February 23, 2011 17:57
Alternative syntax for #'cond
(cond (eq 'a 'a) 't
't '())
@daniel-cussen
daniel-cussen / gist:840832
Created February 23, 2011 17:59
Syntax for #'label
((label conser (lambda (x) (cons x x))) '1)
@daniel-cussen
daniel-cussen / gist:840835
Created February 23, 2011 18:01
Behavior of quote in golomb forest lisp repl
> (cdr '(1 2 3))
((2 . 3) . NIL)