After having mastered my CLOS challenges I am now stumbling upon a
rather simple one with a macro ...
I have:
(defparameter *cello-style-registry*
'((:cnx-default-text-style
'cnx-text-style
:font :arial
:font-size 14
:font-slant :regular
:font-color +BLACK+)
(:cnx-default-label-style
'cnx-label-style
:font :arial
:font-size 12
:font-slant :italics
:font-color +BLACK+)))
This is meant to be a list of so-called style definitions where each
style definition is a list of
* the id of the style
* the class of the style
* a set of key-value pairs giving further class-specific initialization
args
In order to initialize the styles I have created a macro and a function
like so:
(defun make-style-from-style-spec (style-id style-class &rest style-kvps)
(make-instance style-class :md-name style-id style-kvps)
(defmacro mk-style-from-style-spec (style-id style-class &rest (style-kvps))
`(make-style-from-style-spec ,style-class ,style-id ,@style-kvps))
The problem occurs when compiling the following function:
(defun init-styles ()
(loop for style-definition in *cello-style-registry*
do
(if (and (listp style-definition)
(>= (length style-definition) 2))
(let* ((style-id (pop style-definition))
(style-class (pop style-definition))
(style (mk-style-from-style-spec style-id
style-class
style-definition)))
(add-style style))))
(if (> (hash-table-count *cello-styles-ht*) 0)
t
nil))
This results in the following error (at compile time):
Attempt to take the cdr of
#<Printer Error, obj=#x10000685: Received signal number 4 (Illegal instruction)>
[Condition of type TYPE-ERROR]
I'm on AllegroCL 8.1 Express Edition on Mac OS X.
Macro-expanding session transcript:
(mk-style-from-style-spec 'cnx-text-style :cnx-default-text-style)
=>
(MAKE-STYLE-FROM-STYLE-SPEC :CNX-DEFAULT-TEXT-STYLE 'CNX-TEXT-STYLE
:FONT-SIZE 14 :FONT-SLANT :REGULAR)
... Out of ideas ... Puzzled.
Thanks for any hints...
Frank
On 29 maio, 12:49, Frank GOENNINGER <······@googlemail.com> wrote:
> (defmacro mk-style-from-style-spec (style-id style-class &rest (style-kvps))
> `(make-style-from-style-spec ,style-class ,style-id ,@style-kvps))
These parenthesis after &rest are not doing what you think they are.
Anyway, there is no need for this macro. Take a look at the function
apply, I think it is what you are looking for.
On May 29, 12:09 pm, gugamilare <··········@gmail.com> wrote:
> On 29 maio, 12:49, Frank GOENNINGER <······@googlemail.com> wrote:
>
> > (defmacro mk-style-from-style-spec (style-id style-class &rest (style-kvps))
> > `(make-style-from-style-spec ,style-class ,style-id ,@style-kvps))
>
> These parenthesis after &rest are not doing what you think they are.
> Anyway, there is no need for this macro. Take a look at the function
> apply, I think it is what you are looking for.
Yeah, no need for a macro here.
(defun init-styles ()
(loop for style-definition in *cello-style-registry*
do
(if (and (listp style-definition)
(>= (length style-definition) 2))
(let ((style (apply #'make-style-from-style-spec style-
definition)))
(add-style style))))
(if (> (hash-table-count *cello-styles-ht*) 0)
t
nil))
I am also a little concerned that you are using pop on the 'registry'.
Might be safer to use first/second in situations like this (or car
cadr cddr).
(However I am not well versed in the intricacies of loop).
··················@gmail.com writes:
> On May 29, 12:09�pm, gugamilare <··········@gmail.com> wrote:
>> On 29 maio, 12:49, Frank GOENNINGER <······@googlemail.com> wrote:
>>
>> > (defmacro mk-style-from-style-spec (style-id style-class &rest (style-kvps))
>> > � `(make-style-from-style-spec ,style-class ,style-id ,@style-kvps))
>>
>> These parenthesis after &rest are not doing what you think they are.
>> Anyway, there is no need for this macro. Take a look at the function
>> apply, I think it is what you are looking for.
>
> Yeah, no need for a macro here.
>
> (defun init-styles ()
> (loop for style-definition in *cello-style-registry*
> do
> (if (and (listp style-definition)
> (>= (length style-definition) 2))
> (let ((style (apply #'make-style-from-style-spec style-
> definition)))
> (add-style style))))
> (if (> (hash-table-count *cello-styles-ht*) 0)
> t
> nil))
With
(defun make-style-from-style-spec (style-id style-class &rest initargs)
(apply #'make-instance style-class :md-name style-id initargs))
I almost get there:
No methods applicable for generic function
#<STANDARD-GENERIC-FUNCTION MAKE-INSTANCE> with args
('CNX-TEXT-STYLE :MD-NAME :CNX-DEFAULT-TEXT-STYLE :FONT :ARIAL
:FONT-SIZE 14 :FONT-SLANT :REGULAR :FONT-COLOR ...)
of classes
(CONS SYMBOL SYMBOL SYMBOL SYMBOL SYMBOL FIXNUM SYMBOL SYMBOL
SYMBOL ...)
[Condition of type PROGRAM-ERROR]
Hmm - why is 'CNX-TEXT-STYLE a CONS ?
Frank
From: Zach Beane
Subject: Re: Macro in a let assignment doesn't work for me ... AllegroCL 8.1 EE
Date:
Message-ID: <m3vdnjiveh.fsf@unnamed.xach.com>
Frank GOENNINGER <······@googlemail.com> writes:
> ··················@gmail.com writes:
>
>> On May 29, 12:09 pm, gugamilare <··········@gmail.com> wrote:
>>> On 29 maio, 12:49, Frank GOENNINGER <······@googlemail.com> wrote:
>>>
>>> > (defmacro mk-style-from-style-spec (style-id style-class &rest (style-kvps))
>>> > `(make-style-from-style-spec ,style-class ,style-id ,@style-kvps))
>>>
>>> These parenthesis after &rest are not doing what you think they are.
>>> Anyway, there is no need for this macro. Take a look at the function
>>> apply, I think it is what you are looking for.
>>
>> Yeah, no need for a macro here.
>>
>> (defun init-styles ()
>> (loop for style-definition in *cello-style-registry*
>> do
>> (if (and (listp style-definition)
>> (>= (length style-definition) 2))
>> (let ((style (apply #'make-style-from-style-spec style-
>> definition)))
>> (add-style style))))
>> (if (> (hash-table-count *cello-styles-ht*) 0)
>> t
>> nil))
>
> With
>
> (defun make-style-from-style-spec (style-id style-class &rest initargs)
> (apply #'make-instance style-class :md-name style-id initargs))
>
> I almost get there:
>
> No methods applicable for generic function
> #<STANDARD-GENERIC-FUNCTION MAKE-INSTANCE> with args
> ('CNX-TEXT-STYLE :MD-NAME :CNX-DEFAULT-TEXT-STYLE :FONT :ARIAL
> :FONT-SIZE 14 :FONT-SLANT :REGULAR :FONT-COLOR ...)
> of classes
> (CONS SYMBOL SYMBOL SYMBOL SYMBOL SYMBOL FIXNUM SYMBOL SYMBOL
> SYMBOL ...)
> [Condition of type PROGRAM-ERROR]
>
> Hmm - why is 'CNX-TEXT-STYLE a CONS ?
Pascal Bourguignon's Revenge!
That's the read syntax for (QUOTE CNX-TEXT-STYLE). But your original
list is already quoted, so the 'CNX-TEXT-SAMPLE within that list becomes
a list (QUOTE CNX-TEXT-SAMPLE) instead of the symbol CNX-TEXT-SAMPLE.
Zach
Zach Beane <····@xach.com> writes:
> Frank GOENNINGER <······@googlemail.com> writes:
>
>> ··················@gmail.com writes:
>>
>>> On May 29, 12:09�pm, gugamilare <··········@gmail.com> wrote:
>>>> On 29 maio, 12:49, Frank GOENNINGER <······@googlemail.com> wrote:
>>>>
>>>> > (defmacro mk-style-from-style-spec (style-id style-class &rest (style-kvps))
>>>> > � `(make-style-from-style-spec ,style-class ,style-id ,@style-kvps))
>>>>
>>>> These parenthesis after &rest are not doing what you think they are.
>>>> Anyway, there is no need for this macro. Take a look at the function
>>>> apply, I think it is what you are looking for.
>>>
>>> Yeah, no need for a macro here.
>>>
>>> (defun init-styles ()
>>> (loop for style-definition in *cello-style-registry*
>>> do
>>> (if (and (listp style-definition)
>>> (>= (length style-definition) 2))
>>> (let ((style (apply #'make-style-from-style-spec style-
>>> definition)))
>>> (add-style style))))
>>> (if (> (hash-table-count *cello-styles-ht*) 0)
>>> t
>>> nil))
>>
>> With
>>
>> (defun make-style-from-style-spec (style-id style-class &rest initargs)
>> (apply #'make-instance style-class :md-name style-id initargs))
>>
>> I almost get there:
>>
>> No methods applicable for generic function
>> #<STANDARD-GENERIC-FUNCTION MAKE-INSTANCE> with args
>> ('CNX-TEXT-STYLE :MD-NAME :CNX-DEFAULT-TEXT-STYLE :FONT :ARIAL
>> :FONT-SIZE 14 :FONT-SLANT :REGULAR :FONT-COLOR ...)
>> of classes
>> (CONS SYMBOL SYMBOL SYMBOL SYMBOL SYMBOL FIXNUM SYMBOL SYMBOL
>> SYMBOL ...)
>> [Condition of type PROGRAM-ERROR]
>>
>> Hmm - why is 'CNX-TEXT-STYLE a CONS ?
>
> Pascal Bourguignon's Revenge!
>
> That's the read syntax for (QUOTE CNX-TEXT-STYLE). But your original
> list is already quoted, so the 'CNX-TEXT-SAMPLE within that list becomes
> a list (QUOTE CNX-TEXT-SAMPLE) instead of the symbol CNX-TEXT-SAMPLE.
>
> Zach
*blushing* <g>
Forrest, trees, that kind of symptoms ...
Thanks. Works. Now.
Frank