(in-package :type-calc) ;(require :alexandria) ;(load "type-calc.lisp") ;;You can change stuff and such in this file to see what happens. (defun prepare (expr) "Conveniantly composes type-calc and mac-expand" (type-calc (mac-expand expr))) ;Look it can do complicated stuff. (prepare '(funcall (named-lambda koekie (a b c d) (* a (/ b c) (+ d c))) (+ (* 5 5) 1 2) -1 (sqr 3) 6)) ;;-> ;(THE (CONSTANT -84) ; (FUNCALL ; (THE-FUNCTION KOEKIE (A B C D) ; ((FUNCTION--* A (FUNCTION--/ B C) (FUNCTION--+ D C))) ; (OR ; (FUNCTION ((CONSTANT 28) (CONSTANT -1) (CONSTANT 3) (CONSTANT 6)) ; (CONSTANT -84))) ; NIL) ; (THE (CONSTANT 28) ; (FUNCTION--+ (THE (CONSTANT 25) (FUNCTION--* 5 5)) 1 2)) ; -1 (THE (CONSTANT 3) (FUNCTION--SQR 3)) 6)) ;This is how you make a global function. (prepare '(setq-1 (function fa) (named-lambda fa (a) a 5))) ;-> (THE (OR (T)) FUNCTION--FA) the first time. ;Type handling should improve subsequent times, but still it disapoints me ;And this is how you use it. (prepare '(fa 6)) ;-> (THE (CONSTANT 5) (FUNCTION--FA 6)) ;Look the type (function ((const 7)) (const 5)) should be there. (print (prepare '#'fa)) ;-> (THE (OR (T) (FUNCTION ((CONSTANT 6)) (CONSTANT 5))) FUNCTION--FA) (defun reset-fa () (setf (get-var 'function--fa) nil)) ;Type (integer) overriding the effect of (const 5). (prepare '(+ (the (integer) 4) (the (integer) 5) 5)) ;-> (THE (INTEGER) (FUNCTION--+ (THE (INTEGER) 4) (THE (INTEGER) 5) 5)) ;You can call functions attached to local variables too: (prepare '(funcall (named-lambda a (fun x) (funcall fun (+ 5 x))) (named-lambda b (x) (* x x)) 1)) ;-> (THE (CONSTANT 36) ... ;A little differently, by putting fun into function-namespace there: (prepare '(funcall (named-lambda a ((function fun) x) (fun (+ 5 x))) (named-lambda b (x) (* x x)) 1)) ;-> (THE (CONSTANT 36) ...