SFTW120-LectureNotes-13

SFTW120-LectureNotes-13 - SFTW120 Programming Science...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 SFTW120 Programming Science Lecture Notes 13: Lisp: An Introduction © Robert P. Biuk-Aghai SFTW120 - Programming Science 2 Lecture Notes 13 The Lisp Language s Lisp ( Lis t P rocessing) was created in the late 1950s for programming in artificial intelligence s Different versions of Lisp exist; the most common one: ANSI Common Lisp s Lisp was designed to process lists of items s Lisp programs are made up of Lisp expressions , which mostly are lists too (therefore, program instructions and data have the same structure) s Lisp programs are evaluated by the read-eval-print loop (reads an expression, evaluates it, prints its value)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 SFTW120 - Programming Science 3 Lecture Notes 13 The Read-Eval-Print Loop s Read an expression: (+ 2 2) s Evaluate the expression: call function ‘ + ’ with operands 2 and 2 s Print the value of the expression: 4 s Lisp programs are usually interpreted (translated at run- time), and not compiled Read Eval Print SFTW120 - Programming Science 4 Lecture Notes 13 Lisp Data Types s Basic Lisp data types: b Atoms : sequences of characters (digits, letters, …) b Lists : sequences of (zero or more) atoms and/or lists s Fundamental types of atoms: b Numbers (integer, ratio, floating-point, complex number) b Strings b Symbols s Advanced Lisp data types: arrays, hash tables, bit vectors, etc.
Background image of page 2
3 SFTW120 - Programming Science 5 Lecture Notes 13 Examples of Lisp Data Atoms: s Numbers: 34 1/3 3.1415926535897931 s Strings: "John" "John Smith" "" s Symbols: a john c3po Lists: s Empty list: () s Simple lists: (a) (a john 34 c3po) s Nested list: ((john 34) a ((c3po))) SFTW120 - Programming Science 6 Lecture Notes 13 Expressions s Anything given to the Lisp interpreter is an expression s Rules for evaluation of expressions: b Numbers always evaluate to themselves b Strings always evaluate to themselves b Symbols evaluate to the value assigned to them; if no value has been assigned to a symbol it can’t be evaluated (producing an error) b Lists evaluate to the return value obtained by evaluating all the elements of the list (discussed later)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/04/2011 for the course SFST 120 taught by Professor Dr.robert during the Spring '11 term at University of Macau.

Page1 / 13

SFTW120-LectureNotes-13 - SFTW120 Programming Science...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online