Page 1 of 1

declaring an element of a defstruct fixnum

Posted: Sat Nov 27, 2010 8:37 am
by imba
Hi,

Code: Select all

(defstruct structure
 struct-member)
I want that in all functions accessing to struct-member they treat struct-member as a fixnum.

But

Code: Select all

(defstruct structure
 struct-member (declare (type fixnum struct-member))
does not work. How do I implement this?


Another question: How do I make make-structur, structure-p structure-struct-member inline? (declaim (inline ...)) does not work for them.

Re: declaring an element of a defstruct fixnum

Posted: Sat Nov 27, 2010 9:32 am
by ramarren
Rather than guessing the syntax, you should read the specification. Reading BNF-like syntax descriptions is a useful skill for programming in general. And Hyperspec usually provides examples, search for "slot-type".

Re: declaring an element of a defstruct fixnum

Posted: Sat Nov 27, 2010 9:42 am
by imba
Thanks!

I have added another question above. This should be possible: "defstruct defines readers for the slots and arranges for setf to work properly on such reader functions. Also, unless overridden, it defines a predicate named name-p, defines a constructor function named make-constructor-name, and defines a copier function named copy-constructor-name. All names of automatically created functions might automatically be declared inline (at the discretion of the implementation). " But how?

Re: declaring an element of a defstruct fixnum

Posted: Sat Nov 27, 2010 11:14 am
by ramarren
imba wrote:But how?
How what? If you mean the automatic inline declaration, it is "at the discretion of the implementation", which means that the implementation does it or it does not, without programmer choice. For SBCL see manual. Other implementations probably act in a similar way.

Re: declaring an element of a defstruct fixnum

Posted: Sat Nov 27, 2010 11:30 am
by imba
Thanks.