Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
(defmacro alambda (parms &body body)
|
||||
`(labels ((self ,parms ,@body))
|
||||
#'self))
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(defun fib (n)
|
||||
(assert (>= n 0) nil "'~a' is a negative number" n)
|
||||
(funcall
|
||||
(alambda (n)
|
||||
(if (>= 1 n)
|
||||
n
|
||||
(+ (self (- n 1)) (self (- n 2)))))
|
||||
n))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
(defun fib (number)
|
||||
"Fibonacci sequence function."
|
||||
(if (< number 0)
|
||||
(error "Error. The number entered: ~A is negative" number)
|
||||
(labels ((fib (n a b)
|
||||
(if (= n 0)
|
||||
a
|
||||
(fib (- n 1) b (+ a b)))))
|
||||
(fib number 0 1))))
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(defun fib (number)
|
||||
"Fibonacci sequence function."
|
||||
(if (< number 0)
|
||||
(error "Error. The number entered: ~A is negative" number)
|
||||
(recursive ((n number) (a 0) (b 1))
|
||||
(if (= n 0)
|
||||
a
|
||||
(recurse (- n 1) b (+ a b))))))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(defmacro recursive ((&rest parm-init-pairs) &body body)
|
||||
(let ((hidden-name (gensym "RECURSIVE-")))
|
||||
`(macrolet ((recurse (&rest args) `(,',hidden-name ,@args)))
|
||||
(labels ((,hidden-name (,@(mapcar #'first parm-init-pairs)) ,@body))
|
||||
(,hidden-name ,@(mapcar #'second parm-init-pairs))))))
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
(setf (symbol-function '!) (symbol-function 'funcall)
|
||||
(symbol-function '!!) (symbol-function 'apply))
|
||||
|
||||
(defmacro ? (args &body body)
|
||||
`(lambda ,args ,@body))
|
||||
|
||||
(defstruct combinator
|
||||
(name nil :type symbol)
|
||||
(function nil :type function))
|
||||
|
||||
(defmethod print-object ((combinator combinator) stream)
|
||||
(print-unreadable-object (combinator stream :type t)
|
||||
(format stream "~A" (combinator-name combinator))))
|
||||
|
||||
(defconstant +y-combinator+
|
||||
(make-combinator
|
||||
:name 'y-combinator
|
||||
:function (? (f) (! (? (g) (! g g))
|
||||
(? (g) (! f (? (&rest a)
|
||||
(!! (! g g) a))))))))
|
||||
|
||||
(defconstant +z-combinator+
|
||||
(make-combinator
|
||||
:name 'z-combinator
|
||||
:function (? (f) (! (? (g) (! f (? (x) (! (! g g) x))))
|
||||
(? (g) (! f (? (x) (! (! g g) x))))))))
|
||||
|
||||
(defparameter *default-combinator* +y-combinator+)
|
||||
|
||||
(defmacro with-y-combinator (&body body)
|
||||
`(let ((*default-combinator* +y-combinator+))
|
||||
,@body))
|
||||
|
||||
(defmacro with-z-combinator (&body body)
|
||||
`(let ((*default-combinator* +z-combinator+))
|
||||
,@body))
|
||||
|
||||
(defun x-call (x-function &rest args)
|
||||
(apply (funcall (combinator-function *default-combinator*) x-function) args))
|
||||
|
||||
(defmacro x-function ((name &rest args) &body body)
|
||||
`(lambda (,name)
|
||||
(lambda ,args
|
||||
(macrolet ((,name (&rest args)
|
||||
`(funcall ,',name ,@args)))
|
||||
,@body))))
|
||||
|
||||
(defmacro x-defun (name args &body body)
|
||||
`(defun ,name ,args
|
||||
(x-call (x-function (,name ,@args) ,@body) ,@args)))
|
||||
|
||||
;;;; examples
|
||||
|
||||
(x-defun factorial (n)
|
||||
(if (zerop n)
|
||||
1
|
||||
(* n (factorial (1- n)))))
|
||||
|
||||
(x-defun fib (n)
|
||||
(case n
|
||||
(0 0)
|
||||
(1 1)
|
||||
(otherwise (+ (fib (- n 1))
|
||||
(fib (- n 2))))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue