Tuesday, March 2, 2010

PostTwiceDaily2 03/02/2010 (a.m.)

  • tags: no_tag

    • Lisp offers all the data types we find in most other languages,
      along with several others that we don't. One data type we have
      used already is the integer, which is written as a series of digits:
      256. Another data type Lisp has in common with most other languages
      is the string, which is represented as a series of characters
      surrounded by double-quotes: "ora et labora". Integers and strings
      both evaluate to themselves.

      Two Lisp data types that we don't commonly find in other languages
      are symbols and lists. Symbols are words. Ordinarily they are
      converted to uppercase, regardless of how you type them:

      > 'Artichoke
      ARTICHOKE

      Symbols do not (usually) evaluate to themselves, so if you want to
      refer to a symbol, you should quote it, as above.

      Lists are represented as zero or more elements enclosed in parentheses.
      The elements can be of any type, including lists. You have to
      quote lists, or Lisp would take them for function calls:

      > '(my 3 "Sons")
      (MY 3 "Sons")
      > '(the list (a b c) has 3 elements)
      (THE LIST (A B C) HAS 3 ELEMENTS)

      Notice that one quote protects a whole expression, including
      expressions within it.

      You can build lists by calling list. Since list is a function,
      its arguments are evaluated. Here we see a call to + within a call
      to list:

      > (list 'my (+ 2 1) "Sons")
      (MY 3 "Sons")
    • Two Lisp data types that we don't commonly find in other languages
      are symbols and lists. Symbols are words. Ordinarily they are
      converted to uppercase, regardless of how you type them:

      > 'Artichoke
      ARTICHOKE

      Symbols do not (usually) evaluate to themselves, so if you want to
      refer to a symbol, you should quote it, as above.

      Lists are represented as zero or more elements enclosed in parentheses.
      The elements can be of any type, including lists. You have to
      quote lists, or Lisp would take them for function calls:

      > '(my 3 "Sons")
      (MY 3 "Sons")
      > '(the list (a b c) has 3 elements)
      (THE LIST (A B C) HAS 3 ELEMENTS)

      Notice that one quote protects a whole expression, including
      expressions within it.

      You can build lists by calling list. Since list is a function,
      its arguments are evaluated. Here we see a call to + within a call
      to list:

      > (list 'my (+ 2 1) "Sons")
      (MY 3 "Sons")
    • This is why we
      need the quote. If a list is quoted, evaluation returns the list
      itself; if it is not quoted, the list is treated as code, and
      evaluation returns its value:

      > (list '(+ 2 1) (+ 2 1))
      ((+ 2 1) 3)

      Here the first argument is quoted, and so yields a list. The second
      argument is not quoted, and is treated as a function call, yielding
      a number.

Posted from Diigo. The rest of my favorite links are here.