Re: portable way of strict type checking in defun
- From: Don Geddis <don@xxxxxxxxxx>
- Date: Tue, 13 Oct 2009 20:50:20 -0700
alex_sv <avshabanov@xxxxxxxxx> wrote on Mon, 12 Oct 2009:
I thought I can do it using eval machinery, I mean make macro that
produces something like that:
(eval '(progn (check-type a fixnum) (check-type b symbol)))
If you want to make a macro, then why add the EVAL? Just make a macro
that returns the PROGN form you wrote above, and it should work just fine.
No need for any EVAL.
[...]But compiled versions of the function with declare statement hasI believe that declare is more optimal in case of sbcl - it looks like the
compiler generates more optimal code for functions with declare statement
inside.
shorter
E.g. compiled version of (defun foo (a b) (declare (fixnum a b)) (list
a b)) takes 41 assembly statements, compiled version of (defun foo (a
b) (check-type a fixnum) (check-type b fixnum) (list a b)) takes 86
assembly statements - though there are many NOPs there. These
measurements was made using sbcl 1.0.29 for linux-x86_64, without any
optimization turned on - I just entered function on just-launched sbcl
and invoked disassemble.
Have you considered that maybe the assembly code with CHECK-TYPE is actually
checking the types of the arguments? And maybe the assembly code from the
DECLARE form is missing those type checks?
You claimed, in your original post, that you wanted each function to check
the types of the arguments you pass in.
If the DECLARE version doesn't do that, then even if it's shorter, it isn't
really a solution to your problem, is it?
I didn't analyze the assembly because of lack of knowledges of x64
assembly, but shorter version made me believe that declare is worth
using on sbcl instead of more verbose check-type.
Perhaps the algorithms aren't the same.
-- Don
_______________________________________________________________________________
Don Geddis http://don.geddis.org/ don@xxxxxxxxxx
Well done. You'll make an exemplary FOOD ANIMAL.
.
- Follow-Ups:
- Re: portable way of strict type checking in defun
- From: Tobias C. Rittweiler
- Re: portable way of strict type checking in defun
- References:
- portable way of strict type checking in defun
- From: alex_sv
- Re: portable way of strict type checking in defun
- From: Rob Warnock
- Re: portable way of strict type checking in defun
- From: Giovanni Gigante
- Re: portable way of strict type checking in defun
- From: alex_sv
- Re: portable way of strict type checking in defun
- From: Don Geddis
- Re: portable way of strict type checking in defun
- From: alex_sv
- portable way of strict type checking in defun
- Prev by Date: Re: FAQ: Random numbers
- Next by Date: Re: FAQ: Random numbers
- Previous by thread: Re: portable way of strict type checking in defun
- Next by thread: Re: portable way of strict type checking in defun
- Index(es):
Relevant Pages
|