Difference between compile-time and runtime? 
Author Message
 Difference between compile-time and runtime?

I have been trying to understand how to write macros in LISP (not very
successfully) for some time now.  Very often I see an author mentioning
compile-time and runtime issue related to macros, however, I haven't seen a
clear explanation of that yet.  If somebody can point me to a good source or
provide a simple example here that clarifies the issue, it would be much
appreciated.

Thanks
Vin



Wed, 17 Mar 2004 00:45:20 GMT  
 Difference between compile-time and runtime?
Hi Vin,

IMO one of the best sources on how to write macros is
"On Lisp" by Paul Graham, published by Prentice-Hall Inc.
ISBN 0-13-030552-9.

HTH.

Frank



Wed, 17 Mar 2004 01:52:55 GMT  
 Difference between compile-time and runtime?

Well, here is a bit of an example.  The key idea is that when you write
a macro, what you are doing is writing a program or function that is
executed at macro-expansion time.  This function returns code which
conceptually replaces the macro invocation in the source code.  The
resulting source code is then processed (compiled or executed) normally.

In the example below, one print statement will execute at macro
expansion time and the other at run time.  The trace comes from ACL
5.0.1 under Sparc/Solaris.  Other Lisp systems may differ a bit in
details.

    USER +> (defmacro example ()
              (print "Macro-expansion time")
              '(progn (print "Run time") t))
    EXAMPLE

    USER +> (example)

    "Macro-expansion time"
    "Run time"
    T
If you just invoke the macro at top level, it is macro-expanded and then
executed.  The results follow directly on one another.

    USER +> (defun foo () (example))
    FOO
If you use the macro in a function definition, then the exact behavior
you will see depends on details of your implementation.  In Allegro CL5,
the function is interpreted, so nothing happend during the definition.

In other lisps, for example LispWorks 4, the macro is expanded when
processing the defintion.  In such a lisp you would see:

    LW +> (defun foo () (example))

    "Macro-expansion time"
    FOO
which indicates that the macro was expanded while processing the
definition.  This is also true of lisps like MCL which automatically
compile definitions.  But returning the ACL:

    USER +> (foo)

    "Macro-expansion time"
    "Run time"
    T

    USER +> (foo)

    "Macro-expansion time"
    "Run time"
    T
Each time the interpreted function is called, the macro is expanded, and
then the resulting code is executed.

    USER +> (compile 'foo)

    "Macro-expansion time"
    FOO
    ()
    ()
Compiling the function forces the macro to be expanded by the compiler.
The message is seen when that expansion takes place.

    USER +> (foo)

    "Run time"
    T
Running the compiled function only produces the run-time result, because
the expansion has already been done during the compilation stage.  Note
that in a lisp that expands macros while processing definitions (or one
that compiles all definitions) you would see this behavior for the calls
before calling the compiler as well.

--



Wed, 17 Mar 2004 02:33:43 GMT  
 Difference between compile-time and runtime?
Fantastic book but unfortunately out of print...
Dave
Quote:

> Hi Vin,

> IMO one of the best sources on how to write macros is
> "On Lisp" by Paul Graham, published by Prentice-Hall Inc.
> ISBN 0-13-030552-9.

> HTH.

> Frank



Wed, 17 Mar 2004 09:38:47 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Warnings at compile time for possible runtime pattern matching failure

2. setting TK_NO_SECURITY at compile time (why not runtime?)

3. Differences between development and runtime?

4. compile-time-too/not-compile-time

5. Compile-time vs Run-time

6. Doing run-time checks at compile-time

7. Date Time Difference Calculations

8. Difference in calculation time.

9. HELP: Need Difference between two DATE/TIME stamps

10. differences between ALPHA and VAX compiler in case of run time error

11. Run Time Check difference

12. Weird timing differences on K62

 

 
Powered by phpBB® Forum Software