Subject: [clisp-list] BUG?--DEFINE-COMPILER-MACRO

From: "Geoff Summerhayes" <[email-masked]>
Date: Thu Feb 28 14:30:50 2002

Are compiler macros being used by the compiler?

I tried
======================================================

(defun my-plus (&rest args)(apply #'+ args))

(define-compiler-macro my-plus (&whole form &rest args)
  (case (length args)
    (0 0)
    (1 (car args))
    (t (let ((total 0)
             (new-arg-list nil))
         (mapcar #'(lambda (arg) 
           (cond ((constantp arg)(incf total arg))
                  (t (push arg new-arg-list))))
           args)
         (cond ((null new-arg-list) total) 
               ((or (> (length args)
                    (+ 1 (length new-arg-list))))
                `(my-plus ,total ,@(nreverse new-arg-list)))
               (t form))))))

(defun foo() (my-plus 1 2 3 4 (my-plus 5 6 7) 8 9))

=======================================================

This works,

(funcall (compiler-macro-function 'my-plus)
         '(my-plus 1 2 3 (my-plus 4 5 6) 7 8 9) nil)
==> (MY-PLUS 30 (MY-PLUS 4 5 6))

but this

(compile 'foo) ==>

FOO ;
NIL ;
NIL

(disassemble #'foo) ==>

Disassembly of function FOO
(CONST 0) = 1
(CONST 1) = 2
(CONST 2) = 3
(CONST 3) = 4
(CONST 4) = 5
(CONST 5) = 6
(CONST 6) = 7
(CONST 7) = MY-PLUS
(CONST 8) = 8
(CONST 9) = 9
0 required arguments
0 optional arguments
No rest parameter
No keyword parameters
0     (CONST&PUSH 0)                      ; 1
1     (CONST&PUSH 1)                      ; 2
2     (CONST&PUSH 2)                      ; 3
3     (CONST&PUSH 3)                      ; 4
4     (CONST&PUSH 4)                      ; 5
5     (CONST&PUSH 5)                      ; 6
6     (CONST&PUSH 6)                      ; 7
7     (CALL&PUSH 3 7)                     ; MY-PLUS
10    (CONST&PUSH 8)                      ; 8
11    (CONST&PUSH 9)                      ; 9
12    (CALL 7 7)                          ; MY-PLUS
15    (SKIP&RET 1)
#<COMPILED-CLOSURE FOO>

show no optimization at all, did I miss something?

--------------
Geoff

---

From: "Thomas F. Burdick" <[email-masked]>
Date: Thu Feb 28 14:56:11 2002

> Are compiler macros being used by the compiler?

Well, they aren't, that's unfortunate, but completely conforming.  To
quote the spec §3.2.2.1.3 "When Compiler Macros Are Used":

  The presence of a compiler macro definition for a function or macro
  indicates that it is desirable for the compiler to use the expansion
  of the compiler macro instead of the original function form or macro
  form. However, no language processor (compiler, evaluator, or other
  code walker) is ever required to actually invoke compiler macro
  functions, or to make use of the resulting expansion if it does invoke
  a compiler macro function.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'

---

From: Sam Steingold <[email-masked]>
Date: Thu Feb 28 17:50:01 2002

> * In message <014f01c1c0a7$473b61f0$1965a8c0@geoffspc>
> * On the subject of "[clisp-list] BUG?--DEFINE-COMPILER-MACRO"
> * Sent on Thu, 28 Feb 2002 17:28:41 -0500
> * Honorable "Geoff Summerhayes" <[email-masked]> writes:
>

yes - since CLISP 2.26.

[your example uncovered a bug which I just fixed - thanks :-]

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.2 GNU/Linux
Keep Jerusalem united! <http://www.onejerusalem.org/Petition.asp>
Read, think and remember! <http://www.iris.org.il> <http://www.memri.org/>
Yeah, yeah, I love cats too... wonna trade recipes?