declaring an element of a defstruct fixnum

Discussion of Common Lisp
Post Reply
imba
Posts: 35
Joined: Sun Nov 21, 2010 2:13 pm

declaring an element of a defstruct fixnum

Post by imba » Sat Nov 27, 2010 8:37 am

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.
Last edited by imba on Sat Nov 27, 2010 9:33 am, edited 1 time in total.

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: declaring an element of a defstruct fixnum

Post by ramarren » Sat Nov 27, 2010 9:32 am

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

imba
Posts: 35
Joined: Sun Nov 21, 2010 2:13 pm

Re: declaring an element of a defstruct fixnum

Post by imba » Sat Nov 27, 2010 9:42 am

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?

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: declaring an element of a defstruct fixnum

Post by ramarren » Sat Nov 27, 2010 11:14 am

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.

imba
Posts: 35
Joined: Sun Nov 21, 2010 2:13 pm

Re: declaring an element of a defstruct fixnum

Post by imba » Sat Nov 27, 2010 11:30 am

Thanks.

Post Reply