From: ······@gmail.com
Subject: Macro compilation problem with Allegro
Date: 
Message-ID: <1173009147.234949.125170@h3g2000cwc.googlegroups.com>
Greetings,

I am  trying to move to allegro in os-x, and haven't managed to
compile code that I've had working for years (sbcl in linux and
lispworks in windows). It seems to ignore the declaration of with-
gensyms, and later treats it as an undefined function.  A file
containing this code, copied from Paul Graham, compiles without
warnings in sbcl, but fails to compile in Allegro with an "attempt to
call `WITH-GENSYMS' which is an undefined function" error:

(defmacro with-gensyms (syms &body body)
  `(let ,(mapcar #'(lambda (s)
                     `(,s (gensym)))
                 syms)
     ,@body))

(defmacro bind (&rest args)
  `(multiple-value-bind ,@args))

(defmacro in-case-error (expr err)
  (with-gensyms (val cond)
    `(bind (,val ,cond) (ignore-errors ,expr)
           (if (typep ,cond 'error)
               (progn
                 ,err
                 (error ,cond))
               ,val))))

(defun copy-file (from to)
  (with-open-file (in from :direction :input :element-type 'unsigned-
byte)
    (in-case-error
     (with-open-file (out to :direction :output :element-type
'unsigned-byte)
       (do ((i (read-byte in nil -1) (read-byte in nil -1)))
           ((minusp i))
         (declare (fixnum i))
         (write-byte i out)))
     (format *error-output* "Error writing to ~s.~%" to))))

Any hint on what could be going on will be greatly appreciated.

Best,

jm

From: Willem Broekema
Subject: Re: Macro compilation problem with Allegro
Date: 
Message-ID: <1173016478.658792.90610@s48g2000cws.googlegroups.com>
On Mar 4, 12:52 pm, ·······@gmail.com" <······@gmail.com> wrote:
> It seems to ignore the declaration of with-gensyms, and later
> treats it as an undefined function.  A file containing this
> code, copied from Paul Graham, compiles without warnings in
> sbcl, but fails to compile in Allegro with an "attempt to
> call `WITH-GENSYMS' which is an undefined function" error:

There was an insightful discussion about exactly this issue:

"Question about compilation/evaluation environments"
http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/170d01370010f113/a922a8753d950068?#a922a8753d950068

In short, your code is relying on explicitly "unspecified" behaviour,
and Allegro behaves different from some other implementations at this
point.

- Willem
From: Rainer Joswig
Subject: Re: Macro compilation problem with Allegro
Date: 
Message-ID: <joswig-6F78D4.13100604032007@news-europe.giganews.com>
In article <························@h3g2000cwc.googlegroups.com>,
 ·······@gmail.com" <······@gmail.com> wrote:

> Greetings,
> 
> I am  trying to move to allegro in os-x, and haven't managed to
> compile code that I've had working for years (sbcl in linux and
> lispworks in windows). It seems to ignore the declaration of with-
> gensyms, and later treats it as an undefined function.  A file
> containing this code, copied from Paul Graham, compiles without
> warnings in sbcl, but fails to compile in Allegro with an "attempt to
> call `WITH-GENSYMS' which is an undefined function" error:
> 
> (defmacro with-gensyms (syms &body body)
>   `(let ,(mapcar #'(lambda (s)
>                      `(,s (gensym)))
>                  syms)
>      ,@body))
> 
> (defmacro bind (&rest args)
>   `(multiple-value-bind ,@args))
> 
> (defmacro in-case-error (expr err)
>   (with-gensyms (val cond)
>     `(bind (,val ,cond) (ignore-errors ,expr)
>            (if (typep ,cond 'error)
>                (progn
>                  ,err
>                  (error ,cond))
>                ,val))))
> 
> (defun copy-file (from to)
>   (with-open-file (in from :direction :input :element-type 'unsigned-
> byte)
>     (in-case-error
>      (with-open-file (out to :direction :output :element-type
> 'unsigned-byte)
>        (do ((i (read-byte in nil -1) (read-byte in nil -1)))
>            ((minusp i))
>          (declare (fixnum i))
>          (write-byte i out)))
>      (format *error-output* "Error writing to ~s.~%" to))))
> 
> Any hint on what could be going on will be greatly appreciated.
> 
> Best,
> 
> jm

I guess its a tricky question whether it should work.
Contact the support from Franz.

We are talking here about compile time effects.

The macro WITH-GENSYMS is seen by the compiler at compile-time,
and can be used to expand code.

Same for IN-CASE-ERROR.


BUT:

You are using WITH-GENSYM inside IN-CASE-ERROR not
as an expansion (like BIND), but as a macro.

So the compiler needs to use the WITH-GENSYM macro
at compile time inside a compile-time macro.
Is that understandable? I'm not sure if that
should work, one would need to ask a compiler expert.
consult the ANSI CL standard and/or sacrifice a chicken
to get the answer.


So I guess you would need to make WITH-GENSYMS available to the compiler.
Define it in another file that you load before or
use EVAL-WHEN.
From: ······@gmail.com
Subject: Re: Macro compilation problem with Allegro
Date: 
Message-ID: <1173014201.608830.301790@p10g2000cwp.googlegroups.com>
On Mar 4, 1:10 pm, Rainer Joswig <······@lisp.de> wrote:
> So the compiler needs to use the WITH-GENSYM macro
> at compile time inside a compile-time macro.
> Is that understandable? I'm not sure if that
> should work, one would need to ask a compiler expert.
> consult the ANSI CL standard and/or sacrifice a chicken
> to get the answer.

Understood, thanks.

> So I guess you would need to make WITH-GENSYMS available to the compiler.
> Define it in another file that you load before or
> use EVAL-WHEN.

I put it in a file that loads first and it works nicely.  I'll save
the chicken for next time.  Thanks a lot.

jm
From: ······@gmail.com
Subject: Re: Macro compilation problem with Allegro
Date: 
Message-ID: <1173014239.552808.270030@v33g2000cwv.googlegroups.com>
On Mar 4, 1:10 pm, Rainer Joswig <······@lisp.de> wrote:
> So the compiler needs to use the WITH-GENSYM macro
> at compile time inside a compile-time macro.
> Is that understandable? I'm not sure if that
> should work, one would need to ask a compiler expert.
> consult the ANSI CL standard and/or sacrifice a chicken
> to get the answer.

Understood, thanks.

> So I guess you would need to make WITH-GENSYMS available to the compiler.
> Define it in another file that you load before or
> use EVAL-WHEN.

I put it in a file that loads first and it works nicely.  I'll save
the chicken for next time.  Thanks a lot.

jm
From: Alex Mizrahi
Subject: Re: Macro compilation problem with Allegro
Date: 
Message-ID: <45ead0b1$0$90262$14726298@news.sunsite.dk>
(message (Hello 'Rainer)
(you :wrote  :on '(Sun, 04 Mar 2007 13:10:06 +0100))
(

 RJ> You are using WITH-GENSYM inside IN-CASE-ERROR not
 RJ> as an expansion (like BIND), but as a macro.

how is this different?

in standard i see:
--
If a defmacro form appears as a top level form, the compiler must store the 
macro definition at compile time, so that occurrences of the macro later on 
in the file can be expanded correctly.
--

you see, it says that _all_ occurences of macro later on in the file can be 
expanded _correctly_, it doesn't say that if that occurence is within macro 
itself, it should break.

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"�� ���� ������� �����") 
From: Rainer Joswig
Subject: Re: Macro compilation problem with Allegro
Date: 
Message-ID: <joswig-2A9DC0.15171504032007@news-europe.giganews.com>
In article <·························@news.sunsite.dk>,
 "Alex Mizrahi" <········@users.sourceforge.net> wrote:

> (message (Hello 'Rainer)
> (you :wrote  :on '(Sun, 04 Mar 2007 13:10:06 +0100))
> (
> 
>  RJ> You are using WITH-GENSYM inside IN-CASE-ERROR not
>  RJ> as an expansion (like BIND), but as a macro.
> 
> how is this different?
> 
> in standard i see:
> --
> If a defmacro form appears as a top level form, the compiler must store the 
> macro definition at compile time, so that occurrences of the macro later on 
> in the file can be expanded correctly.
> --
> 
> you see, it says that _all_ occurences of macro later on in the file can be 
> expanded _correctly_, it doesn't say that if that occurence is within macro 
> itself, it should break.
> 
> )
> (With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
> "�� ���� ������� �����") 

See the post by Willem Broekema in this thread.

The question is where the macro definition is available?
There is an 'environment' used for compiling the file.
It has these macro definitions available for expansion
of the code. But it might not be the same environment
which you need to expand code in these macros at compile time.
From: Vassil Nikolov
Subject: Re: Macro compilation problem with Allegro
Date: 
Message-ID: <yy8vr6s4w7oi.fsf@eskimo.com>
On Sun, 04 Mar 2007 15:17:15 +0100, Rainer Joswig <······@lisp.de> said:
| ...
| See the post by Willem Broekema in this thread.
|
| The question is where the macro definition is available?
| There is an 'environment' used for compiling the file.
| It has these macro definitions available for expansion
| of the code. But it might not be the same environment
| which you need to expand code in these macros at compile time.

  As far as I know (and not speaking for Franz in any way), Allegro is
  one of the few Common Lisp implementations (if not the only one)
  that actually separate the compilation environment from the
  evaluation environment, and that sometimes exposes subtle unwarranted
  assumptions that may otherwise go unnoticed for a long time.  (To me,
  that is a good thing.)

  By the way, I think I'd prefer wrapping the macro definition in
  question in an EVAL-WHEN form to moving it to a separate file,
  in order to make the code less prone to bootstrapping problems.

  ---Vassil.


-- 
Is your code free of side defects?
From: Ken Tilton
Subject: Re: Macro compilation problem with Allegro
Date: 
Message-ID: <n7PGh.6215$%I4.5398@newsfe12.lga>
Vassil Nikolov wrote:
> On Sun, 04 Mar 2007 15:17:15 +0100, Rainer Joswig <······@lisp.de> said:
> | ...
> | See the post by Willem Broekema in this thread.
> |
> | The question is where the macro definition is available?
> | There is an 'environment' used for compiling the file.
> | It has these macro definitions available for expansion
> | of the code. But it might not be the same environment
> | which you need to expand code in these macros at compile time.
> 
>   As far as I know (and not speaking for Franz in any way), Allegro is
>   one of the few Common Lisp implementations (if not the only one)
>   that actually separate the compilation environment from the
>   evaluation environment, and that sometimes exposes subtle unwarranted
>   assumptions that may otherwise go unnoticed for a long time.  (To me,
>   that is a good thing.)

I know what you mean and have no opinion on this particular issue 
because, as a simple application programmer, this is way over my head, 
but I have the same feeling about Lispworks: it is kind of an ANSI CL 
enforcer in that a port from my usual ACL platform to LW always involves 
a couple of headscratchers that invariably turn out to be cases where LW 
hewed to the standard where ACL (in ways helpful) did not.

It has even occurred to me that, should I ever find myself hopelessly 
stuck, I should port the thing to LW to unearth unstandard code that 
might be confusing ACL in ways that did provoked its runtime but not its 
compiler.

kzo

-- 
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
                                   -- Elwood P. Dowd

In this world, you must be oh so smart or oh so pleasant.
                                   -- Elwood's Mom