|
|||
|
Hi all,
There are two macros I've written here: http://paste.lisp.org/display/91129 which bind annonymous search functions to dynamically generated names using (setf (fdefinition NAME) (lambda (x) ...)) forms. The problem I'm experiencing happens at load time, i.e., although the macros compile fine on their own (and expand as intended) they seem to be preventing the function that wraps them from compiling at all. Hence the error I get is this: (defun make-indexed-slot-query-tools (pclass psubclasses indexed-slots) (if (null psubclasses) (%make-single-query-tools (list pclass) indexed-slots t) (progn (%make-single-query-tools (append pclass psubclasses) indexed-slots) (%make-multi-query-tools (append pclass psubclasses) indexed-slots)))) => value INDEXED-SLOTS is not of the expected type LIST. [Condition of type TYPE-ERROR] Any suggestions as to why this is happening very much appreciated. Regards, Seb -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap |
|
|
||||
|
||||
|
|
|
|||
|
Sebastian Tennant <sebyte@smolny.plus.com> writes:
> Hi all, > > There are two macros I've written here: > > http://paste.lisp.org/display/91129 > > which bind annonymous search functions to dynamically generated names using > (setf (fdefinition NAME) (lambda (x) ...)) forms. > > ;;; In this simple example we can see how the arguments to wrapper > ;;; function FOOW are appended to form a single list which is then > ;;; passed to the macro FOO. Delete this comment, it is misleading. Nothing gets appended when passed to FOO. > (defmacro foo (arg) > `(mapcar (lambda (x) (1+ (1+ x))) ,arg)) > ;;; => FOO There is no reason to make it a macro. Use defun here: (defun foo (arg) (mapcar (lambda (x) (1+ (1+ x))) arg)) > (defun foow (a b) > (foo (append a b))) > ;;; => FOOW You need revise the way arguments are passed to macros: they ARE NOT evaluated. C/USER[248]> (defmacro foo (arg) (format t "arg = ~S~%" arg) (let ((result `(mapcar (lambda (x) (1+ (1+ x))) ,arg))) (format t "result = ~S~%" result) result)) FOO C/USER[249]> (defun foow (a b) (foo (append a b))) arg = (APPEND A B) result = (MAPCAR (LAMBDA (X) (1+ (1+ X))) (APPEND A B)) FOOW C/USER[250]> (foow '(1) '(2)) (3 4) C/USER[251]> > The problem I'm experiencing happens at load time, i.e., although the macros > compile fine on their own (and expand as intended) Why do you lie to us? They do not expand as intended! C/USER[254]> (macroexpand '(%make-single-query-tools (list pclass) indexed-slots t)) *** - MAPC: A proper list must not end with INDEXED-SLOTS > they seem to be preventing > the function that wraps them from compiling at all. Hence the error I get is > this: > > (defun make-indexed-slot-query-tools (pclass psubclasses indexed-slots) > (if (null psubclasses) > (%make-single-query-tools (list pclass) indexed-slots t) > (progn (%make-single-query-tools (append pclass psubclasses) indexed-slots) > (%make-multi-query-tools (append pclass psubclasses) indexed-slots)))) > > => value INDEXED-SLOTS is not of the expected type LIST. > [Condition of type TYPE-ERROR] > > Any suggestions as to why this is happening very much appreciated. Indeed, INDEXED-SLOTS is not a list, it is a symbol. Try to write something like: (defun make-indexed-slot-query-tools (pclass psubclasses indexed-slots) (if (null psubclasses) (%make-single-query-tools (list pclass) (a b c d) t) (progn (%make-single-query-tools (append pclass psubclasses) (a b c d)) (%make-multi-query-tools (append pclass psubclasses) (a b c d))))) instead. -- __Pascal Bourguignon__ |
|
|||
|
Quoth pjb@informatimago.com (Pascal J. Bourguignon):
> Delete this comment, it is misleading. Nothing gets appended when passed to > FOO. [...] You need to revise the way arguments are passed to macros: they > ARE NOT evaluated. That's what I firmly believed, but then my example of foo and foow made me doubt myself. Your version of foo makes things a lot clearer and the penny has finally dropped. '(append a b)' happens to satisfy mapcar's final argument type requirement (a list) whereas the symbol 'indexed-slots' doesn't. Thanks a lot. Seb -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap |
|
|||
|
Quoth Sebastian Tennant <sebyte@smolny.plus.com>:
> That's what I firmly believed, but then my example of foo and foow made me > doubt myself. Your version of foo makes things a lot clearer and the penny has > finally dropped. '(append a b)' happens to satisfy mapcar's final argument type > requirement (a list) whereas the symbol 'indexed-slots' doesn't. No need to correct my flawed explanation above. Two pennies have dropped. The first one got stuck half but a second penny came along and dislodged it. I fully understand how it all ties together now. Seb -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap |
|
|
|
|
![]() |
| Popular Tags in the Forum |
| function, macros, wrapper |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| wrapper function for ellipsis arg taking functions. | sinbad | Newsgroup comp.lang.c | 6 | 11-04-2009 12:26 AM |
| Re: Coupling and cohesion in SAS macros | toby dunn | Newsgroup comp.soft-sys.sas | 0 | 08-10-2009 03:53 PM |
| Re: RES: store site macros in sas folde | Adriano Rodrigues | Newsgroup comp.soft-sys.sas | 0 | 07-17-2008 03:45 AM |
| RES: store site macros in sas folde | Ian Whitlock | Newsgroup comp.soft-sys.sas | 0 | 07-17-2008 02:23 AM |
| Re: Pre compiled macros vs MAUTOSOURCE | Peter Crawford | Newsgroup comp.soft-sys.sas | 1 | 02-12-2007 11:35 PM |