Re: portable way of strict type checking in defun



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.

I 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.

But compiled versions of the function with declare statement has
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.
.



Relevant Pages

  • Re: Declaring Objects
    ... What this is saying is set the Colors variable to refer to the Colors sheet, ... > that I need to declare my objects and know that I would prefer to declare ... > Below is my first attempt to writing a macro, ... > Sub FindAndReplace() ...
    (microsoft.public.excel.programming)
  • Re: Converting C to Delphi
    ... macro and a million constants. ... Can this be imported into delphi or do I ... > Perform those calculations yourself and declare the constants with the ... One is temp, ...
    (alt.comp.lang.borland-delphi)
  • Re: Loop problem
    ... (declare (special a b)) ... will need a macro to type in the nest of dolists for you. ... The macroexpander will say "Oh I'm not finished yet." ...
    (comp.lang.lisp)
  • Re: VBA Word 2003 File Close
    ... It would be better to declare a variable as a Document and set that variable to the document that you are opening rather than rely on the active document. ... In a Word 2003 template document I have a macro triggered by a CheckBox ... document and then is supposed to close that second document. ... I get a run-time error 4198 "Command Failed" at the line that ...
    (microsoft.public.word.vba.general)
  • Re: one simple question
    ... You'll most likely find a macro called NULL in one of the Visual C++ ... this doesn't declare a function. ... Empty brackets would be equivalent to replacing the "null" with "void", ... also making this a function declaration. ...
    (comp.lang.cpp)