While compiling the following code snippet (simplified) from cl-http I run
into the following warning
;While compiling test22
Warning: cond clause (T "wkjahakjsd") is unreachable
(defmacro algo-2 (string-or-whatever)
`(or ,string-or-whatever "dont care"))
(defun test-12(a)
(algo-2 a))
(defun test22 ()
(algo-2 "23"))
Obviously the compiler complains about the (or "23" "dont care") since the
macroexpansion of the or is
(LET ((#:G1000 "23")) (IF #:G1000 #:G1000 (COND (T "dont care"))))
Should I change the macro to detect whether a constant string is supplied?,
e.g.
(defmacro algo-1 (string-or-whatever)
(let ((temp string-or-whatever))
(if (stringp temp)
temp
`(or ,temp "dont care"))))
Karsten
In article <············@news.wanadoo.es>,
Karsten Poeck <······@terra.es> wrote:
>Should I change the macro to detect whether a constant string is supplied?,
>e.g.
>(defmacro algo-1 (string-or-whatever)
> (let ((temp string-or-whatever))
> (if (stringp temp)
> temp
> `(or ,temp "dont care"))))
There doesn't seem to be anything about this that requires it to be a macro
in the first place, since it has ordinary function semantics. If you're
doing it for the sake of optimization, use an INLINE declaration to achieve
that.
--
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
As I tried to explain, this is simplified code from JCMA's cl-http.
The original definition is:
;;; (c) Copyright 1994-96, John C. Mallery
;;; All Rights Reserved.
(define-action-type
html-with-enumeration
(:encapsulating
:class encapsulating-action-type
:documentation "An action that wraps the enumeration of items on STREAM
according to STYLE.
STYLE can be :ENUMERATE :ITEMIZE :PLAIN :MENU :DIRECTORY :DEFINITION")
(action activity url stream style)
(html:with-enumeration (stream style)
(call-next-action action url activity)))
with define-action-type defined as:
(define-macro define-action-type (name (type &key (class 'action-type)
documentation) lambda-list &body body)
#.(format nil "Defines a new type of action named NAME whose type is TYPE.
TYPE can be any of: ~{~A~^, ~}
LAMBDA-LIST is the set of arguments passed to the action function.
The lexical variables ACTION ACTIVITY URL are available within BODY.
When CLASS is a subtype of encapsulating-action-type, the continuation
that executes the encapsulated actions is invoked within the
action function with (call-next-action &optional action url activity).
Additionally, the first argument after the standard action arguments must be
the inferior actions during the allocation process." (action-types))
(let ((namestring (symbol-name name))
(arglist (%make-action-arglist lambda-list)))
`(progn
,(%define-action-function name class arglist body)
(multiple-value-bind (action-type new-p)
(intern-action-type ,namestring :if-does-not-exist :create :class
',class)
(unless (eq (type-of action-type) ',class)
(change-class action-type ',class))
(setf (action-type-instance-class action-type)
(%action-class-for-type ',type))
(setf (documentation-string action-type) (or ,documentation
"Undocumented."))
(update-action-function action-type ',arglist)
(values action-type new-p)))))
Please trust me that define-macro is a macro, to prove this I would have to
copy a lot more code
The problem is the line
(setf (documentation-string action-type) (or ,documentation
"Undocumented."))
In the macro call documentation may be a constant string -> compiler warns
or may be an expression -> no problem.
The question remains the same, should I change the macro so that the case of
a constant string is detected?
"Barry Margolin" <······@genuity.net> wrote in message
·····················@paloalto-snr2.gtei.net...
> In article <············@news.wanadoo.es>,
> Karsten Poeck <······@terra.es> wrote:
> >Should I change the macro to detect whether a constant string is
supplied?,
> >e.g.
> >(defmacro algo-1 (string-or-whatever)
> > (let ((temp string-or-whatever))
> > (if (stringp temp)
> > temp
> > `(or ,temp "dont care"))))
>
> There doesn't seem to be anything about this that requires it to be a
macro
> in the first place, since it has ordinary function semantics. If you're
> doing it for the sake of optimization, use an INLINE declaration to
achieve
> that.
>
> --
> Barry Margolin, ······@genuity.net
> Genuity, Woburn, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the
group.
In article <············@news.wanadoo.es>,
Karsten Poeck <······@terra.es> wrote:
> (setf (documentation-string action-type) (or ,documentation
>"Undocumented."))
Change the above to:
(setf (documentation-string action-type) ,(or documentation "Undocumented"))
This assumes that DOCUMENTATION is required to be a literal, so you can do
the OR at macro-expansion time rather than deferring it to run time.
--
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.