[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

do-nothing macro generates nil nevertheless

Point 1:

I've been implementing some debug macros that only
generate code depending on what's in *features*.  If
the appropriate features are not enabled, I want my
macros to have no effect.  As if they weren't there.
This seems not to be possible.

Consider this macro:

  (defmacro mac1 () nil)

Now consider this form:


which returns nil.  (in MCL and CMU-CL)
This seems to me to be a misfeature.

A macro's job is to return a list to be compiled.
If it returns nil, I would have thought that would mean
that nothing should be compiled.  That would be useful.
If you need a macro to compile in the constant nil, you
can have it return 'nil.

  (defmacro mac2 () 'nil)


returns nil in MCL and CMU-CL.

Point 2:

While we're on the subject of debug printouts,
it would be nice if there were a way one could insert
a form after the last expression of a progn and have
it be transparent with respect to what the progn
returns.  Over-simplified example:

     (debug-print "ahah!")

You'd like the return value to be 3, as if you'd done this

       (debug-print "ahah!"))

which is even more invasive.  For debug forms like this
it would be nicer if they were defined to be usable
anywhere without worry as to their effect on return values.

This would require some sort of primitive like

  (return-value-transparent &body body)

which would leave the current return values undisturbed.
This primitive could stand on its own, or it could be
implemented using an even more useful primitive:

  (with-captured-return-values (var) &body body)

which could be useful in a macro that would expand thus:

     (with-captured-return-values (var)
       (debug-print "You're about to return ~S" var)
       (values-list var))

Has this been done before?

Isn't lisp great?

Dave Yost
    @    .com