Skip to main content

Chapter 10: Evaluation, Compilation, Control Flow

  • Chapter
Common Lisp Recipes
  • 2034 Accesses

Abstract

To be honest, I couldn’t find a better title for this chapter. It’s kind of a hodgepodge of various subjects, although many of them would probably indeed fit into the chapter called Evaluation and Compilation in the Common Lisp standard.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 79.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 99.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    See Recipe 3-4 for strings and characters. For numbers and you only need to be careful if you’re comparing rationals with floating-point numbers (see Recipe 4-10), which is questionable style anyway.

  2. 2.

    Yeah, other Lispers might give you different advice. But, hey, whose book is this? Also, rules are there to be broken once you’ve understood them…

  3. 3.

    Being always very careful with the wording, they are actually a bit pickier. Two objects can be the same object with respect to some specific predicate and if there’s no predicate mentioned, then EQL is implied. Whereas identical means “the same under the predicate EQ.”

  4. 4.

    If you want a comparison, it is as if a C programmer would rely on int always being 16 bits wide.

  5. 5.

    It is roughly equivalent to what == does in Java.

  6. 6.

    See http://www.sbcl.org/manual/#Defining-Constants .

  7. 7.

    See Recipe 18-4.

  8. 8.

    That’s the term used in the standard. As we will soon see, this doesn’t necessarily imply that this is a keyword in the sense of being a symbol from the KEYWORD package.

  9. 9.

    In Java, a similar concept would be that of a static member variable.

  10. 10.

    If not, you might want to read Chapter 6 of Practical Common Lisp.

  11. 11.

    You could, for example, bind the variable to NIL when the function is defined and in MY-COUNT check if it’s still NIL.

  12. 12.

    See 3.2.3.1 of the standard.

  13. 13.

    GET-INTERNAL-REAL-TIME is explained in Recipe 22-8.

  14. 14.

    Although implementations are technically not required to adhere to this.

  15. 15.

    Of course, the behavior is meticulously described in the standard.

  16. 16.

    This is explained in Chapter 16 of Practical Common Lisp, which is also available online at http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html .

  17. 17.

    And it has, by the way, also been a part of GNU Emacs since 1994.

  18. 18.

    Or rather only in the form of the auxiliary methods mentioned above.

  19. 19.

    See Recipe 10-8.

  20. 20.

    See Recipe 4-4 for an explanation of the "~@R" part.

  21. 21.

    In other words, this also works with DEFGENERIC and DEFMETHOD.

  22. 22.

    See more in Chapter 6 of Practical Common Lisp which is at http://www.gigamonkeys.com/book/variables.html .

  23. 23.

    If you want to follow along, ask your IDE to undefine (see Recipe 16-9) the function (SETF NUMBER-WORD) or start a new image and define only the hash table and the NUMBER-WORD function.

  24. 24.

    We wrapped the output of GETHASH with VALUES to get rid of the second return value, but that is only for cosmetic reasons.

  25. 25.

    For LDB and BYTE see Chapter 24 of Practical Common Lisp.

  26. 26.

    This also shows, by the way, that somewhere during the evaluation of this form both our update and our access form were used. Have a look at a possible setf expansion of LDB in the dictionary entry for DEFINE-SETF-EXPANDER if you’re wondering why this is so.

  27. 27.

    Note the use of the environment parameter (see Recipe 10-9).

  28. 28.

    In case you’re still somewhat unsure about how this macro should be used, its HyperSpec dictionary entry also contains some examples. And one more is following on page 293.

  29. 29.

    See http://www.lispworks.com/documentation/HyperSpec/Issues/iss174_w.htm . Before function names like (SETF FOO) were allowed, the only way to write setf accessors was with macros and for that DEFSETF was the more convenient variant. It probably was left in for backward compatibility.

  30. 30.

    Note that according to the standard it is implementation-dependent whether the expansion of a symbol macro is stored in the environment; which means that this example might not work the same with other Lisps.

  31. 31.

    We’ll use the terms environment and environment object interchangeably from now on, although technically there is a difference. An environment object is something like what was bound to ENV in our example, while there are usually several environments that are active at any given point in the execution of a program. The environment object can be used to query these environments.

  32. 32.

    See, for example, Recipe 17-3.

  33. 33.

    Available online at http://www.cs.cmu.edu/Groups/AI/html/cltl/cltl2.html .

  34. 34.

    And make sure to compile SLOW-AND-EXACTafter the compiler macro was defined or else it won’t have any effect.

  35. 35.

    The NOTINLINE declaration is in there to prevent the compiler macro from being called again and again on the same form.

  36. 36.

    Look up *READ-SUPPRESS* in the standard for details.

Author information

Authors and Affiliations

Authors

Electronic Supplementary Material

Below is the link to the electronic supplementary material.

chapter-10 (zip 4 kb)

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Edmund Weitz

About this chapter

Cite this chapter

Weitz, E. (2016). Chapter 10: Evaluation, Compilation, Control Flow. In: Common Lisp Recipes. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-1176-2_10

Download citation

Publish with us

Policies and ethics