Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.lisp

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-26-2009, 07:59 AM
Sebastian Tennant
Guest
 
Posts: n/a
Default Two macros and a wrapper function

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
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 11-26-2009, 09:43 AM
Pascal J. Bourguignon
Guest
 
Posts: n/a
Default Re: Two macros and a wrapper function

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__
Reply With Quote
  #3 (permalink)  
Old 11-26-2009, 11:47 AM
Sebastian Tennant
Guest
 
Posts: n/a
Default Re: Two macros and a wrapper function

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
Reply With Quote
  #4 (permalink)  
Old 11-26-2009, 12:09 PM
Sebastian Tennant
Guest
 
Posts: n/a
Default Re: Two macros and a wrapper function

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
Reply With Quote
 
Reply

Popular Tags in the Forum
function, macros, wrapper

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wrapper function for ellipsis arg taking functions. sinbad Newsgroup comp.lang.c 6 11-03-2009 11:26 PM
Re: Coupling and cohesion in SAS macros toby dunn Newsgroup comp.soft-sys.sas 0 08-10-2009 02:53 PM
Re: RES: store site macros in sas folde Adriano Rodrigues Newsgroup comp.soft-sys.sas 0 07-17-2008 02:45 AM
RES: store site macros in sas folde Ian Whitlock Newsgroup comp.soft-sys.sas 0 07-17-2008 01:23 AM
Re: Pre compiled macros vs MAUTOSOURCE Peter Crawford Newsgroup comp.soft-sys.sas 1 02-12-2007 10:35 PM



All times are GMT. The time now is 04:27 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.