RE: Avoiding eval

From: An Metet (Use-Author-Address-Header_at_[127.1)
Date: 02/23/04


Date: Sun, 22 Feb 2004 22:37:25 -0500

NOTE: This message was sent thru a mail2news gateway.
No effort was made to verify the identity of the sender.
--------------------------------------------------------

>From: tar@sevak.isi.edu (Thomas A. Russ)

>> I had tried to use APPLY on my macro but it failed
>>
>> (dolist (args arg-list "done") (apply #'item-classm args));fails
>> But entering the arguments directly works.
>
>How did it fail?

The question suggests that you think it should work,
I was quite dissapointed when it didn't.

It Fails just like this

CL-USER 6 > (item-classm "testname")
#<STANDARD-CLASS |testname| 2067DD3C>

CL-USER 7 > (macroexpand-1 '(item-classm "testname"))
(DEFCLASS |testname| (COMMON |testname|) NIL)
T

CL-USER 8 > (dolist (args arg-list "done") (apply #'item-classm args))

Error: Call ((LAMBDA (#:%%MACROARG%% #:&ENVIRONMENT525 &AUX
(#:&WHOLE526 #:%%MACROARG%%) (#:\(CATEGORY\ ...\)527 #)
(#:CHECK-LAMBDA-LIST-TOP-LEVEL531 #) (#:CATEGORY #) (#:KEYS528 #)
(#:SUPPLIED-P529 #) (#:OPT-A #) (#:SUPPLIED-P530 #) (#:OPT-B #))
(DECLARE (SPECIAL:SOURCE #) (LAMBDA-LIST CATEGORY &KEY OPT-A OPT-B))
(BLOCK #:ITEM-CLASSM (LET # #))) "mollusc") has the wrong number of arguments.
  1 (abort) Return to level 0.
  2 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed, or :? for other options

CL-USER 9 : 1 >

The macro ITEM-CLASSM has optional keyword arguments and it apears to me
as if they are being treat as "REQUIRED" when using the macro in this way.

Below is the ITEM-CLASSM macro and code for the argument lists repeated

(defparameter *category-list*
  '( "mollusc" "fish" "insect" "mammal" "bird" "fish" "arachnid" "reptile" "amphibian"))
(defparameter *opt-a-list*
  '( "walking" "flying" "swimming" "crawling"))
(defparameter *opt-b-list*
  '("wild" "domesticated" "extinct"))
(pprint (setq arg-list
              (concatenate 'list
                           (mapcar #'list *category-list*)
                           (mapcan #'(lambda(X)
                                       (mapcar #'(lambda (Y)
                                                   (list X :opt-a Y ))
                                               *opt-a-list*))
                                   *category-list*)
                           (mapcan #'(lambda(X)
                                       (mapcar #'(lambda (Z)
                                                   (list X :opt-b Z ))
                                               *opt-b-list*))
                                   *category-list*)
                           (mapcaN #'(lambda(X)
                                       (mapcan #'(lambda(Y)
                                                   (mapcar #'(lambda (Z)
                                                               (list X :opt-a Y :opt-b Z ))
                                                           *opt-b-list*))
                                               *opt-a-list*))
                                   *category-list*))))

(defmacro Item-classm (category &key opt-a opt-b)
  (let ((sym-category (intern category))
         (sym-class nil))

    (cond ((and category opt-a opt-b)
           (let ((sym-opt-a (intern opt-a))
                 (sym-opt-b (INTERN opt-b)))
             (setf sym-class
                   (INTERN
                    (concatenate 'string category "-" opt-a "-" opt-b)))
             `(defclass ,sym-class (common ,sym-category ,sym-opt-a ,sym-opt-b )() )))

          ((and category opt-a )
           (let ((sym-opt-a (INTERN opt-a)))
             (setf sym-class (INTERN (concatenate 'string category "-" opt-a)))
             `(defclass ,sym-class (common ,sym-category ,sym-opt-a )() )))
             
          ((and category opt-b )
           (let ((sym-opt-b (INTERN opt-b)))
             (setf sym-class (INTERN (concatenate 'string category "-" opt-b)))
             `(defclass ,sym-class (common ,sym-category ,sym-opt-b )() )))
             
          (category
           (setf sym-class sym-category)
           `(defclass ,sym-class (common ,sym-category )() ))
           
          (T "Oopsies"))));learn about condition system

---
Try Anything Twice


Relevant Pages

  • Re: macro recorded in one document doesnt show up in a new docume
    ... If you fail ... Some company networks renew the normal template when you log in. ... Word MVP web site http://word.mvps.org ... Word 2007 and reopen it later, however, the Macro is no longer ...
    (microsoft.public.word.docmanagement)
  • Re: explicit extension DLL wreaking havok during AfxFreeLibrary
    ... RUNTIME_CLASS macro actually reaches into the class's private storage area to get the ... Defining "fail" would help, of course. ... Should we not free extension dlls that are explicitly linked? ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: 14 field query fails Output To Excel with "Too many fields def
    ... How does it fail: just doesn't produce an Excel file? ... Jerry Whittle, Microsoft Access MVP ... specified macro, or I simply open up the database and manually lauch ... during the output or during the nightly job? ...
    (microsoft.public.access.queries)
  • Re: Sort beginning one-line BELOW what should be
    ... The only ways I can get the macro to fail is to either enter the number ... in C6 with a leading apostrophe, which makes it a text entry, ... Prev by Date: ...
    (microsoft.public.excel.programming)