Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7986373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:50:18+00:00 2026-06-04T11:50:18+00:00

After reading a lot of documentation regarding Lisp eval-when operator I still can’t understand

  • 0

After reading a lot of documentation regarding Lisp eval-when operator I still can’t understand its uses, I know with this operator I can control the evaluation time of my expressions but I can’t figure out any example where this may be applicable ?

Best Regards,
utxeee.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:50:19+00:00Added an answer on June 4, 2026 at 11:50 am

    Compilation of a Lisp file

    Take for example the compilation of a Lisp file. The Lisp compiler processes the top-level forms. These can be arbitrary Lisp forms, DEFUNs, DEFMACROS, DEFCLASS, function calls,…

    The whole story how the file compiler works is too complex to explain here, but a few things:

    • the file compiler generates code for a (DEFUN foo () ) form. But it does not execute the defun form. Thus during compilation it is known that there is a function FOO, but the code of ˋFOOˋ is not available during the compilation. The compiler generates the code for the compiled file, but does not keep it in memory. You can’t call such a function at compile time.

    • for macros this works slightly different: (DEFMACRO BAZ ...). The file compiler will not only compile the macro and note that it is there, but it will also make the macro available at compilation time. It is loaded into the compiler environment.

    Thus imagine the sequence of forms in a file:

    (defmacro baz ...)
    
    (defun foo () (baz ...))
    

    This works because the file compiler knows the macro BAZ and when it compiles the code for FOO, then it can expand the macro form.

    Now let’s look at the following example:

    (defun bar (form) ...)
    
    (defmacro baz (form) (bar form))
    
    (defun foo () (baz ...))
    

    Above will not work. Now the macro BAZ uses the function BAR by calling it. When the compiler tries to compile the function FOO, it can’t expand the BAZ macro, because BAR can’t be called, because the code of BAR is not loaded into the compile-time environment.

    There are two solutions to this:

    1. compile and load BAR earlier using a separate file.
    2. Use EVAL-WHEN

    Example for EVAL-WHEN:

     (eval-when (:compile-toplevel :execute :load-toplevel)
       (defun bar (form) ...)
     )
    
     (defmacro baz (form) (bar form))
    
     (defun foo () (baz ...))
    

    Now the EVAL-WHEN instructs the file compiler to actually run the DEFUN form during compilation. The effect of this is: the file compiler now knows the definition of BAR at compile time. Thus it is available later, when the file compiler need to call BAR during macro expansion of the usage of BAZ.

    One could use only :compile-toplevel, when the function would not be needed after the compilation of the file. If it is used later, then we need to make sure that it gets loaded.

    So EVAL-WHEN allows to specify if a particular piece of code should be run

    • during compilation of a file
    • during loading of a file
    • during execution

    EVAL-WHEN is not used that often in user code. If you use it, then you should ask yourself if you really need it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading MSDN-XAML Namespaces and MSDN-Understanding XAML Namespaces , I still do not understand
After reading a lot of on the subject I'm still in the dark about
After reading a lot of interesting articles, I decided to try out Lisp. But,
After reading here a lot of answers about C-style casting in C++ I still
After reading a lot about AES, JCE and its unlimited strength policy files for
After reading monkeytalk faq from http://www.gorillalogic.com/testing-tools/monkeytalk/documentation/monkeytalk-faq : How does it all work? MonkeyTalk is
after reading the cookbook and various Q&A here I am still a bit confused
After reading jQuery's CSS documentation , it doesn't look like it offers any advantages
After reading a lot of articles and many answers related to the above subject,
Recently, after reading a lot of tutorials around the Internet, I've noticed that some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.