Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Lisp > Re: Type infere...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 7 Topic 13121 of 13573
Post > Topic >>

Re: Type inferencing code for CL

by 84jkdl202@[EMAIL PROTECTED] Jul 25, 2008 at 03:03 PM

Pascal J. Bourguignon wrote:
> dc <david_creelman@[EMAIL PROTECTED]
> writes:
>
> >
> > ...without having to say what type j and k are from the lisp code, ie.
>
> Yes, that's called type inference.
>
> (defun infer-types (program)
>   (if (atom program)
>       (list (list :result (type-of program)))
>       (ecase (car program)
>          ((progn)
>               (loop
>                  :with var-types = nil
>                  :with result-type = nil
>                  :for form in (cdr program)
>                  :do (let ((types (infer-types form)))
>                        (setf result-type (assoc :result types)
>                              types (remove :result types :key (function
car)))
>                        (when types (setf var-types (nconc types
var-types))))
>                  :finally (return (cons result-type var-types))))
>          ((pasvar) nil)
>          ((setv) (list (list (cadr program) (type-of (caddr program)))
>                        (list :result (type-of (caddr program))))))))
>
> (infer-types '(progn (pasvar j)
>                      (setv j "hello")
>                      (pasvar k)
>                      (setv k 123)))
> -->
> ((:RESULT (INTEGER 0 16777215)) (K (INTEGER 0 16777215)) (J
(SIMPLE-BASE-STRING 5)))
>

Maybe now I can get rid of all those DECLARE forms in my code without
losing the speed. ;-)
 




 7 Posts in Topic:
Type inferencing code for CL
dc <david_creelman@[EM  2008-07-22 20:05:42 
Re: Type inferencing code for CL
pjb@[EMAIL PROTECTED] (P  2008-07-23 08:39:49 
Re: Type inferencing code for CL
84jkdl202@[EMAIL PROTECTE  2008-07-25 15:03:33 
Re: Type inferencing code for CL
dc <david_creelman@[EM  2008-07-28 18:46:08 
Re: Type inferencing code for CL
pjb@[EMAIL PROTECTED] (P  2008-07-29 07:41:40 
Re: Type inferencing code for CL
Mark Tarver <dr.mtarve  2008-07-29 00:09:19 
Re: Type inferencing code for CL
dc <creelman.david@[EM  2008-08-15 06:29:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 11:08:11 CDT 2008.