From: Johan Kullstam
Subject: help with compilation
Date: 
Message-ID: <ulnd9n15u.fsf@res.raytheon.com>
i am having a bit of difficulty with compilation.

basically, i have a lisp file which looks like this

(defun fun1 ....)

(defmacro mac1 .... (fun1 ...) ....)

(defun fun2 ..... (mac1 ...) ....)

i define FUN1, use it in a macro MAC1 and apply that macro later on in
FUN3.  when i bring up a fresh lisp and use COMPILE-FILE, i get
complaints about FUN1 not being defined.  if i use LOAD instead,
there's no trouble.  how is this normally done?

-- 
johan kullstam

From: Barry Margolin
Subject: Re: help with compilation
Date: 
Message-ID: <U1sc3.856$KM3.220108@burlma1-snr2>
In article <·············@res.raytheon.com>,
Johan Kullstam  <········@ne.mediaone.net> wrote:
>
>i am having a bit of difficulty with compilation.
>
>basically, i have a lisp file which looks like this
>
>(defun fun1 ....)
>
>(defmacro mac1 .... (fun1 ...) ....)
>
>(defun fun2 ..... (mac1 ...) ....)
>
>i define FUN1, use it in a macro MAC1 and apply that macro later on in
>FUN3.  when i bring up a fresh lisp and use COMPILE-FILE, i get
>complaints about FUN1 not being defined.  if i use LOAD instead,
>there's no trouble.  how is this normally done?

You need to use EVAL-WHEN to get fun1 defined into the compilation
environment, so that it can be used when macros run at compile time.

(eval-when (:compile-toplevel :execute)
  (defun fun1 ...))

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, 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.
From: Pierre R. Mai
Subject: Re: help with compilation
Date: 
Message-ID: <87vhcd39w3.fsf@orion.dent.isdn.cs.tu-berlin.de>
Johan Kullstam <········@ne.mediaone.net> writes:

> basically, i have a lisp file which looks like this
> 
> (defun fun1 ....)
> 
> (defmacro mac1 .... (fun1 ...) ....)
> 
> (defun fun2 ..... (mac1 ...) ....)
> 
> i define FUN1, use it in a macro MAC1 and apply that macro later on in

Which way do you use it in MAC1?  From the problems you seem to be
encountering, I'm guessing you use it to produce the macro-expansion
(and not just in the macro-expansion), right?

Also, since macros can't be applied, I'm guessing you are just using
the macro MAC1 in FUN2.

> FUN3.  when i bring up a fresh lisp and use COMPILE-FILE, i get
> complaints about FUN1 not being defined.  if i use LOAD instead,

Which would be correct, since the compiler has only compiled fun1, and 
not loaded it, so when expanding the use of MAC1 in FUN2, it needs to
call fun1, which of course isn't there yet.

> there's no trouble.  how is this normally done?

Either put fun2 in a different file, and arrange for file1 (with fun1
and mac1) to be compiled _and_ loaded before file2 (with fun2) is
loaded (most likely via any of the defsystems out there),  or wrap an
eval-when (:compile-toplevel :load-toplevel) around the defun of fun1.

On the whole I'd prefer splitting this up into different files...

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]
From: Johan Kullstam
Subject: Re: help with compilation
Date: 
Message-ID: <m2aetp8e71.fsf@sophia.axel.nom>
····@acm.org (Pierre R. Mai) writes:

> Johan Kullstam <········@ne.mediaone.net> writes:
> 
> > basically, i have a lisp file which looks like this
> > 
> > (defun fun1 ....)
> > 
> > (defmacro mac1 .... (fun1 ...) ....)
> > 
> > (defun fun2 ..... (mac1 ...) ....)
> > 
> > i define FUN1, use it in a macro MAC1 and apply that macro later on in
> 
> Which way do you use it in MAC1?  From the problems you seem to be
> encountering, I'm guessing you use it to produce the macro-expansion
> (and not just in the macro-expansion), right?

yes.

> Also, since macros can't be applied, I'm guessing you are just using
> the macro MAC1 in FUN2.

yes.  i meant it in the figurative sense, as opposed to passing it
APPLY.

> > FUN3.  when i bring up a fresh lisp and use COMPILE-FILE, i get
> > complaints about FUN1 not being defined.  if i use LOAD instead,
> 
> Which would be correct, since the compiler has only compiled fun1, and 
> not loaded it, so when expanding the use of MAC1 in FUN2, it needs to
> call fun1, which of course isn't there yet.
> 
> > there's no trouble.  how is this normally done?
> 
> Either put fun2 in a different file, and arrange for file1 (with fun1
> and mac1) to be compiled _and_ loaded before file2 (with fun2) is
> loaded (most likely via any of the defsystems out there),  or wrap an
> eval-when (:compile-toplevel :load-toplevel) around the defun of
> fun1.

ok will do.

> On the whole I'd prefer splitting this up into different files...

that would kind of defeat the purpose as the function was made
specifically for use in processing args to that macro.

-- 
J o h a n  K u l l s t a m
[········@ne.mediaone.net]
Don't Fear the Penguin!
From: Steve Gonedes
Subject: Re: help with compilation
Date: 
Message-ID: <m2ogi5awc3.fsf@KludgeUnix.com>
Johan Kullstam <········@ne.mediaone.net> writes:

< > Either put fun2 in a different file, and arrange for file1 (with fun1
< > and mac1) to be compiled _and_ loaded before file2 (with fun2) is
< > loaded (most likely via any of the defsystems out there),  or wrap an
< > eval-when (:compile-toplevel :load-toplevel) around the defun of
< > fun1.
< 
< ok will do.
< 
< > On the whole I'd prefer splitting this up into different files...
< 
< that would kind of defeat the purpose as the function was made
< specifically for use in processing args to that macro.

Have you tried using a flet?

(defmacro define-this (var val)
  (flet ((value-thing (value) (+ value 3)))
    `(defvar ,var ,(value-thing val))))


(define-this *x* 0)

Also, you might be able to do the following. 

(flet ((common-local-fn (value) (* value 3)))

  (defmacro define-that? (var val)
    `(defvar ,var ,(common-local-fn val))))

(define-that? *y* 1)

I am not sure if this is conforming or not; just seems like it should
work, like a macrolet I'd think. The spec says the macro function is
defined in the lexical environment that the `defmacro' appears. I
think that the compiler might be allowed to not save the local
function in the fasl file, which seems ok because it's only used
during compilation. I think your best bet would probably be to use
eval-when, but just thought I would mention this anyhow.
From: Johan Kullstam
Subject: Re: help with compilation
Date: 
Message-ID: <uhfnwjufw.fsf@res.raytheon.com>
Steve Gonedes <········@worldnet.att.net> writes:

> Johan Kullstam <········@ne.mediaone.net> writes:
> I am not sure if this is conforming or not; just seems like it should
> work, like a macrolet I'd think. The spec says the macro function is
> defined in the lexical environment that the `defmacro' appears. I
> think that the compiler might be allowed to not save the local
> function in the fasl file, which seems ok because it's only used
> during compilation. I think your best bet would probably be to use
> eval-when, but just thought I would mention this anyhow.

thanks.  i was wondering about MACROLET (and SYMBOL-MACROLET) and how
to use them.  during development of the function and macro thing, i
had two macros

(defmacro mac1 ....)

(defmacro mac0 .... (mac1 ...) ....)

now, mac1 is only used inside mac0.  i figured i'd like to make it
local to mac0.

(defmacro mac0 (..)
  (macrolet ((mac1 (..) ....))
    (...
       (mac1 ...)
    ...)))

but this construction didn't seem to work right.  paul graham's _on
lisp_ doesn't shed enough light.  hyperspec indicates that MACROLET is
used inside function definitions.  the examples in _on lisp_ use
SYMBOL-MACROLET within a macro definition.  is that the way it works?

-- 
johan kullstam
From: Barry Margolin
Subject: Re: help with compilation
Date: 
Message-ID: <ffMc3.898$KM3.226667@burlma1-snr2>
In article <·············@res.raytheon.com>,
Johan Kullstam  <········@ne.mediaone.net> wrote:
>thanks.  i was wondering about MACROLET (and SYMBOL-MACROLET) and how
>to use them.  during development of the function and macro thing, i
>had two macros
>
>(defmacro mac1 ....)
>
>(defmacro mac0 .... (mac1 ...) ....)
>
>now, mac1 is only used inside mac0.  i figured i'd like to make it
>local to mac0.
>
>(defmacro mac0 (..)
>  (macrolet ((mac1 (..) ....))
>    (...
>       (mac1 ...)
>    ...)))
>
>but this construction didn't seem to work right.  paul graham's _on
>lisp_ doesn't shed enough light.  hyperspec indicates that MACROLET is
>used inside function definitions.  the examples in _on lisp_ use
>SYMBOL-MACROLET within a macro definition.  is that the way it works?

You should be able to do this if MAC0 uses MAC1, but not if the use of MAC1
appears in the expanstion.  This is because the expansion simply replaces
the macro invocation, and is executed in the lexical environment of the
invocation.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, 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.
From: Thomas A. Russ
Subject: Re: help with compilation
Date: 
Message-ID: <ymi6747ex9n.fsf@sevak.isi.edu>
Johan Kullstam <········@ne.mediaone.net> writes:

> 
> 
> i am having a bit of difficulty with compilation.
> 
> basically, i have a lisp file which looks like this
> 

(eval-when (:load-toplevel :compile-toplevel :execute)

> (defun fun1 ....)

 )
 
>
> (defmacro mac1 .... (fun1 ...) ....)
> 
> (defun fun2 ..... (mac1 ...) ....)
> 
> i define FUN1, use it in a macro MAC1 and apply that macro later on in
> FUN3.  when i bring up a fresh lisp and use COMPILE-FILE, i get
> complaints about FUN1 not being defined.  if i use LOAD instead,
> there's no trouble.  how is this normally done?

The problem is that FUN1 is not defined in the compilation time
environment.  You need to use EVAL-WHEN to force evaluation in the
compile time environment.

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu