Name: Anonymous 2007-07-17 22:54 ID:JwJFsunX
I posted this in a blog in spanish with an explanation but I think you can figure out what this thing does. I wrote it in the back of a notebook, bored at a physics class.
(defun dup (f &rest rest)
(cons f (cons f rest)))
(defun swap (a b &rest rest)
(cons b (cons a rest)))
(defun fdrop (a &rest rest)
rest)
(defmacro if0 (test &body b)
`(if (= ,test 0) ,@b))
(defun fconnect (f &rest list)
(if0 (length list)
f
(lcompose (apply #'fconnect list) f)))
(defun lcompose (f g)
(lambda (&rest args)
(apply f (apply g args))))
(defmacro lisp-forth (lispf forthf comb length)
`(defun ,forthf (&rest list)
(,comb (apply #',lispf
(take ,length list))
(drop ,length list))))
(defun take (len list)
(loop for i from 1 to len
for e in list
collect e))
(defun drop (len list)
(if0 len
list
(drop (- len 1) (cdr list))))
(defmacro connect (&rest list)
`(fconnect ,@(mapcar #'asfunction list)))
(defun asfunction (e)
(cond ((symbolp e) `(function ,e))
((or (numberp e) (eq (car e) 'quote))
`(push-identity ,e))))
(defun push-identity (e)
(lambda (&rest list) (cons e list)))
(defmacro define-forth (f &rest definition)
`(defun ,f (&rest args)
(apply (connect ,@definition) args)))
(lisp-forth + f+ cons 2)
(lisp-forth - f- cons 2)
(define-forth lolfun dup f+ 2 f+ 3 swap f-)
(defun lolfun2 (n) (- (+ n n 2) 3))
(defun dup (f &rest rest)
(cons f (cons f rest)))
(defun swap (a b &rest rest)
(cons b (cons a rest)))
(defun fdrop (a &rest rest)
rest)
(defmacro if0 (test &body b)
`(if (= ,test 0) ,@b))
(defun fconnect (f &rest list)
(if0 (length list)
f
(lcompose (apply #'fconnect list) f)))
(defun lcompose (f g)
(lambda (&rest args)
(apply f (apply g args))))
(defmacro lisp-forth (lispf forthf comb length)
`(defun ,forthf (&rest list)
(,comb (apply #',lispf
(take ,length list))
(drop ,length list))))
(defun take (len list)
(loop for i from 1 to len
for e in list
collect e))
(defun drop (len list)
(if0 len
list
(drop (- len 1) (cdr list))))
(defmacro connect (&rest list)
`(fconnect ,@(mapcar #'asfunction list)))
(defun asfunction (e)
(cond ((symbolp e) `(function ,e))
((or (numberp e) (eq (car e) 'quote))
`(push-identity ,e))))
(defun push-identity (e)
(lambda (&rest list) (cons e list)))
(defmacro define-forth (f &rest definition)
`(defun ,f (&rest args)
(apply (connect ,@definition) args)))
(lisp-forth + f+ cons 2)
(lisp-forth - f- cons 2)
(define-forth lolfun dup f+ 2 f+ 3 swap f-)
(defun lolfun2 (n) (- (+ n n 2) 3))