auto doc generation

This commit is contained in:
Felix Brendel
2019-06-11 01:17:36 +02:00
parent d01269aa13
commit 6f5ecc87b0
22 changed files with 2375 additions and 229 deletions
+4
View File
@@ -0,0 +1,4 @@
(import "oo.slime")
(import "math.slime")
(generate-docs "../manual/built-in-docs.org")
+41 -38
View File
@@ -2,56 +2,59 @@
(define-package math
(define pi 3.14159265)
(define pi
"Tha famous circle constant."
3.14159265)
(define (abs x)
"Accepts one argument and returns the absoulte value of it"
(if (> x 0) x (- x)))
(define (sqrt x)
"Accepts one argument and returns the square root of it"
(** x 0.5))
;; (define-class vector3 (x y z)
;; (define (get-x) x)
;; (define (get-y) y)
;; (define (get-z) z)
(define-class (vector3 x y z)
(define (set-x new-x) (mutate x new-x))
(define (set-y new-y) (mutate y new-y))
(define (set-z new-z) (mutate z new-z))
;; (define (set-x new-x) (mutate x new-x))
;; (define (set-y new-y) (mutate y new-y))
;; (define (set-z new-z) (mutate z new-z))
(define (length)
(** (+ (* x x) (* y y) (* z z)) 0.5))
;; (define (length)
;; (** (+ (* x x) (* y y) (* z z)) 0.5))
(define (scale fac)
(mutate x (* fac x))
(mutate y (* fac y))
(mutate z (* fac z))
fac)
;; (define (scale fac)
;; (mutate x (* fac x))
;; (mutate y (* fac y))
;; (mutate z (* fac z))
;; fac)
(define (add other)
(make-vector3
(+ (-> other x) x)
(+ (-> other y) y)
(+ (-> other z) z)))
;; (define (add other)
;; (make-vector3
;; (+ x (other get-x))
;; (+ y (other get-y))
;; (+ z (other get-z))))
(define (subtract other)
(make-vector3
(- (-> other x) x)
(- (-> other y) y)
(- (-> other z) z)))
;; (define (subtract other)
;; (make-vector3
;; (- x (other get-x))
;; (- y (other get-y))
;; (- z (other get-z))))
(define (equal? other)
(and (= (-> other x) x)
(= (-> other y) y)
(= (-> other z) z)))
;; (define (scalar-product other)
;; (+ (* x (other get-x))
;; (* y (other get-y))
;; (* z (other get-z))))
(define (scalar-product other)
(+ (* (-> other x) x)
(* (-> other y) y)
(* (-> other z) z)))
;; (define (cross-product other)
;; (make-vector3
;; (- (* y (other get-z)) (* z (other get-y)))
;; (- (* z (other get-x)) (* x (other get-z)))
;; (- (* x (other get-y)) (* y (other get-x)))))
(define (cross-product other)
(make-vector3
(- (* (-> other z) y) (* (-> other y) z))
(- (* (-> other x) z) (* (-> other z) x))
(- (* (-> other y) x) (* (-> other x) y))))
;; (define (print)
;; (printf :sep "" "[vector3] (" x y z ")"))
;; )
)
(define (print)
(printf :sep "" "[vector3] (" x " " y " " z ")"))))
+14 -10
View File
@@ -2,22 +2,26 @@
"Macro for creating simple classes."
(let ((name (first name-and-members))
(members (rest name-and-members)))
`(define
;; The function definition
(,(string->symbol (concat-strings "make-" (symbol->string name))) @members)
;; The docstring
,(concat-strings "This is the handle to an object of the class " (symbol->string name))
;; the body
(let ,(zip members members)
@body
(set-type
`(set-type
(define
;; The function definition
(,(string->symbol (concat-strings "make-" (symbol->string name))) @members)
;; The docstring
,(concat-strings "This is the handle to an object of the class " (symbol->string name))
;; the body
@body
(let ,(zip members members)
(set-type
(lambda (:rest args)
"This is the docs for the handle"
(let ((op (eval (first args))))
(if (callable? op)
(eval args)
(eval (first args)))))
,(symbol->keyword name))))))
,(symbol->keyword name))))
:constructor)))
(define-syntax (-> obj meth :rest args)
`(,obj ',meth @args))
+16 -27
View File
@@ -107,14 +107,14 @@ ithe sequence as arguemens."
(special-lambda (:rest args)
(let ((op (first args))
(args (rest args)))
(cond ((= op 'pi) 3.14159265)
(else (try (apply op args)
(error "The package does not contain this operation"))))))
(if (callable? (eval op))
(apply op args)
(eval op))))
:package)))))
(define (nil? x)
"Checks if the argument is nil."
"Checks if the argument is =nil=."
(= x nil))
(define (number? x)
@@ -141,8 +141,12 @@ ithe sequence as arguemens."
"Checks if the argument is a function."
(= (type x) :lambda))
(define (special-lambda? x)
(define (macro? x)
"Checks if the argument is a macro."
(= (type x) :macro))
(define (special-lambda? x)
"Checks if the argument is a special-lambda."
(= (type x) :dynamic-macro))
(define (built-in-function? x)
@@ -152,6 +156,7 @@ ithe sequence as arguemens."
(define (callable? x)
(or (lambda? x)
(special-lambda? x)
(macro? x)
(built-in-function? x)))
(define (end seq)
@@ -204,25 +209,9 @@ with (pair elem nil)."
"Subtracts one from the argument."
(- val 1))
;; (defmacro for (@symbol @from @to :rest @for-body)
;; "Designed to resemble a C style for loop. It takes a symbol as
;; well as its starting number and end number and executes the
;; @for-body with the defined symbol for all numbers between @from
;; to @to, where @to is exclusive."
;; (if (< (eval @from) (eval @to))
;; (macro-define @op incr)
;; (if (> (eval @from) (eval @to))
;; (macro-define @op decr)
;; (macro-define @op nil)))
;; (when @op
;; (macro-define (eval @symbol) (eval @from))
;; (eval (pair begin @for-body))
;; (eval (extend (list for @symbol (@op @from) @to) @for-body))))
(define (range :keys from :defaults-to 0 to)
"Returns a sequence of numbers starting with the number defined
by the key 'from' and ends with the number defined in 'to'."
"Returns a sequence of numbers starting with the number defined by the
key =from= and ends with the number defined in =to=."
(when (< from to)
(pair from (range :from (+ 1 from) :to to))))
@@ -249,10 +238,10 @@ elemens as argument to that function."
(map fun (rest seq)))))
(define (reduce fun seq)
"Takes a function and a sequence as arguments and applies the
function to the argument sequence. This only works correctly if
the given function accepts a variable amount of parameters. If
your funciton is limited to two arguments, use `reduce-binary'
"Takes a function and a sequence as arguments and applies the
function to the argument sequence. This only works correctly if the
given function accepts a variable amount of parameters. If your
funciton is limited to two arguments, use [[=reduce-binary=]]
instead."
(apply fun seq))
+11 -9
View File
@@ -1,4 +1,4 @@
(define (nil? x) "Checks if the argument is nil." (= x nil))
(define (nil? x) "Checks if the argument is =nil=." (= x nil))
(define (number? x) "Checks if the argument is a number." (= (type x) :number))
@@ -12,11 +12,13 @@
(define (lambda? x) "Checks if the argument is a function." (= (type x) :lambda))
(define (special-lambda? x) "Checks if the argument is a macro." (= (type x) :dynamic-macro))
(define (macro? x) "Checks if the argument is a macro." (= (type x) :macro))
(define (special-lambda? x) "Checks if the argument is a special-lambda." (= (type x) :dynamic-macro))
(define (built-in-function? x) "Checks if the argument is a built-in function." (= (type x) :built-in-function))
(define (callable? x) (or (lambda? x) (special-lambda? x) (built-in-function? x)))
(define (callable? x) (or (lambda? x) (special-lambda? x) (macro? x) (built-in-function? x)))
(define (end seq) "Returns the last pair in the sqeuence." (if (or (nil? seq) (not (pair? (rest seq)))) seq (end (rest seq))))
@@ -37,8 +39,8 @@ with (pair elem nil)." (extend seq (pair elem ())))
(define (decrement val) "Subtracts one from the argument." (- val 1))
(define (range :keys from :defaults-to 0 to) "Returns a sequence of numbers starting with the number defined
by the key 'from' and ends with the number defined in 'to'." (when (< from to) (pair from (range :from (+ 1 from) :to to))))
(define (range :keys from :defaults-to 0 to) "Returns a sequence of numbers starting with the number defined by the
key =from= and ends with the number defined in =to=." (when (< from to) (pair from (range :from (+ 1 from) :to to))))
(define (range-while :keys from :defaults-to 0 to) "Returns a sequence of numbers starting with the number defined
by the key 'from' and ends with the number defined in 'to'." (define result (list (copy from))) (define head result) (mutate from (increment from)) (while (< from to) (begin (mutate head (pair (first head) (pair (copy from) nil))) (define head (rest head)) (mutate from (increment from)))) result)
@@ -47,10 +49,10 @@ by the key 'from' and ends with the number defined in 'to'." (define result (lis
sequence which contains the results of using the first sequences
elemens as argument to that function." (if (nil? seq) seq (pair (fun (first seq)) (map fun (rest seq)))))
(define (reduce fun seq) "Takes a function and a sequence as arguments and applies the
function to the argument sequence. This only works correctly if
the given function accepts a variable amount of parameters. If
your funciton is limited to two arguments, use `reduce-binary'
(define (reduce fun seq) "Takes a function and a sequence as arguments and applies the
function to the argument sequence. This only works correctly if the
given function accepts a variable amount of parameters. If your
funciton is limited to two arguments, use [[=reduce-binary=]]
instead." (apply fun seq))
(define (reduce-binary fun seq) "Takes a function and a sequence as arguments and applies the
+21 -17
View File
@@ -1,10 +1,6 @@
(import "oo.slime")
(define-class (vector3 x y z)
(define (get-x) x)
(define (get-y) y)
(define (get-z) z)
(define (set-x new-x) (mutate x new-x))
(define (set-y new-y) (mutate y new-y))
(define (set-z new-z) (mutate z new-z))
@@ -20,26 +16,31 @@
(define (add other)
(make-vector3
(+ x (other 'get-x))
(+ y (other 'get-y))
(+ z (other 'get-z))))
(+ (-> other x) x)
(+ (-> other y) y)
(+ (-> other z) z)))
(define (subtract other)
(make-vector3
(- x (other 'get-x))
(- y (other 'get-y))
(- z (other 'get-z))))
(- (-> other x) x)
(- (-> other y) y)
(- (-> other z) z)))
(define (equal? other)
(and (= (-> other x) x)
(= (-> other y) y)
(= (-> other z) z)))
(define (scalar-product other)
(+ (* x (other 'get-x))
(* y (other 'get-y))
(* z (other 'get-z))))
(+ (* (-> other x) x)
(* (-> other y) y)
(* (-> other z) z)))
(define (cross-product other)
(make-vector3
(- (* y (other 'get-z)) (* z (other 'get-y)))
(- (* z (other 'get-x)) (* x (other 'get-z)))
(- (* x (other 'get-y)) (* y (other 'get-x)))))
(- (* (-> other z) y) (* (-> other y) z))
(- (* (-> other x) z) (* (-> other z) x))
(- (* (-> other y) x) (* (-> other x) y))))
(define (print)
(printf :sep " " "[vector3] (" x y z ")"))
@@ -49,4 +50,7 @@
(define v2 (make-vector3 3 2 1))
(assert (= (type v1) (type v2) :vector3))
;; (assert (= (v1 'scalar-product v2) 10))
(assert (= (v1 'scalar-product v2) 10))
(assert (-> (-> v1 cross-product v2)
equal?
(make-vector3 -4 8 -4)))
+5 -1
View File
@@ -1,6 +1,6 @@
(import "oo.slime")
(define-class (vector3 x y z) (define (get-x) x) (define (get-y) y) (define (get-z) z) (define (set-x new-x) (mutate x new-x)) (define (set-y new-y) (mutate y new-y)) (define (set-z new-z) (mutate z new-z)) (define (length) (** (+ (* x x) (* y y) (* z z)) 0.500000)) (define (scale fac) (mutate x (* fac x)) (mutate y (* fac y)) (mutate z (* fac z)) fac) (define (add other) (make-vector3 (+ x (other 'get-x)) (+ y (other 'get-y)) (+ z (other 'get-z)))) (define (subtract other) (make-vector3 (- x (other 'get-x)) (- y (other 'get-y)) (- z (other 'get-z)))) (define (scalar-product other) (+ (* x (other 'get-x)) (* y (other 'get-y)) (* z (other 'get-z)))) (define (cross-product other) (make-vector3 (- (* y (other 'get-z)) (* z (other 'get-y))) (- (* z (other 'get-x)) (* x (other 'get-z))) (- (* x (other 'get-y)) (* y (other 'get-x))))) (define (print) (printf :sep " " "[vector3] (" x y z ")")))
(define-class (vector3 x y z) (define (set-x new-x) (mutate x new-x)) (define (set-y new-y) (mutate y new-y)) (define (set-z new-z) (mutate z new-z)) (define (length) (** (+ (* x x) (* y y) (* z z)) 0.500000)) (define (scale fac) (mutate x (* fac x)) (mutate y (* fac y)) (mutate z (* fac z)) fac) (define (add other) (make-vector3 (+ (-> other x) x) (+ (-> other y) y) (+ (-> other z) z))) (define (subtract other) (make-vector3 (- (-> other x) x) (- (-> other y) y) (- (-> other z) z))) (define (equal? other) (and (= (-> other x) x) (= (-> other y) y) (= (-> other z) z))) (define (scalar-product other) (+ (* (-> other x) x) (* (-> other y) y) (* (-> other z) z))) (define (cross-product other) (make-vector3 (- (* (-> other z) y) (* (-> other y) z)) (- (* (-> other x) z) (* (-> other z) x)) (- (* (-> other y) x) (* (-> other x) y)))) (define (print) (printf :sep " " "[vector3] (" x y z ")")))
(define v1 (make-vector3 1 2 3))
@@ -8,3 +8,7 @@
(assert (= (type v1) (type v2) :vector3))
(assert (= (v1 'scalar-product v2) 10))
(assert (-> (-> v1 cross-product v2) equal? (make-vector3 -4 8 -4)))