I am reading the book Object-Oriented Programming in Common Lisp by Sonja Keene.
In Chapter 9, the author presents the following example:
(defclass window ()
((x :initarg :x-position :accessor x-position)
(y :initarg :y-position :accessor y-position)
(height :initarg :height :accessor window-height)
(width :initarg :width :accessor window-width)
(exposed-p :initform nil :accessor exposed-p))
(:documentation "Foundation of all windows"))
I know the use of :
, ::
or its absence goes beyond pure notation in Common Lisp when talking about packages. There is a logic behind its use!
However, I cannot see a logic behind the use of :
on slot options/specifiers. For instance, consider the example above.
Look at the first slot, the x
. There is the slot option :initarg
associated with :x-position
. OK, both include :
.
Now, on the same slot, look to the :accessor
slot option. It includes the double dot :
. However, the x-position
associated with it does not include the :
.
Is there some logic behind this syntax?
The best hypothesis I have is that the syntax design is used to reflect the difference of moments when dealing with the instances. Thus, the absence of the double-dot would indicate an use related to pos-initialization and the inclusion of the double would be related to the on-going initialization process:
CL-USER> (x-position (make-instance 'window :x-position 3))
3
Is there something else? Did I miss something? Is it pure syntax convention and what I said is just a coincidence?
Thanks