Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

3. Exploring the Syntax of Lisp Code > How Lisp Distinguishes Between Code and ...

How Lisp Distinguishes Between Code and Data

When we write our Lisp program, how does Lisp decide which parts of our program consist of code (stuff to be executed) and which parts are just data? The syntax of Lisp has a special way of distinguishing between the two.

Common Lisp uses two modes when it reads your code: a code mode and a data mode. You can switch between these two modes when writing Lisp code.

Code Mode

Whenever you type something into the Lisp REPL, the compiler assumes that you’re entering a command you want to execute. In other words, Lisp always assumes that you’re writing code and defaults to code mode.

As we’ve already discussed, Lisp will expect Lisp code to be entered as a list. However, the code should be in a special type of list: a form. So when you’re in code mode, as you are when you start typing into the REPL, the commands you enter need to be structured as forms:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint