Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE240 Lecture 20

CSE240 Lecture 20

Introduction to Programming Languages
Programming with LISP
(202010)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

January 20, 2017
Tweet

Transcript

  1. jgs CSE 240 Introduction to Programming Languages Lecture 20: Programming

    with LISP Javier Gonzalez-Sanchez javiergs@asu.edu PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 11 jgs

    Functional Paradigm
  3. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 12 jgs

    Semantic Functional Paradigm Key idea: Focus on higher level of abstraction (free from programming details) Features: Simpler semantic: no data types, and a simpler syntax
  4. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 13 jgs

    Syntax § Uniform representation of instructions and data using a single general format– a list. (functionId param1 param2 param3 ...) • (+ 3 2 7 9) ; add 3+2+7+9 and return the result 21 • (* 4 2.3) ; multiply 4 by 2.3 and return the result 9.2 • (subseq "Hello, World" 2 9) "llo, Wo"
  5. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 14 jgs

    Functional Programming § Language: we will use LISP (LISt Processing). § It uses an interpreter. § Automatic management of memory.
  6. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 15 jgs

    You need an Interpreter § LispWork Personal Edition – http://www.lispworks.com/downloads/index.html § Compile Lisp Online – http://rextester.com/l/common_lisp_online_compiler § Steel Bank Common Lisp – http://www.sbcl.org/platform-table.html
  7. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 16 jgs

    Functional Programming § A program is a set of lists and they are enclosed with parenthesis. § We use lists to represent functions; in a function the first element of the list is the id of the function and the rest are parameter(s) § Whitespace separate function id and parameters § Examples: ( print "Hello World" ) ( + 2 2 ) ( sqrt 2 )
  8. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 17 jgs

    Important Notice !
  9. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 18 jgs

    Everything is a List § A function ID (symbol) is a series of characters other than whitespace, parentheses ( ), pound ( # ), quote ( ' ), double-quote ( " ), period ( . ), or back quote ( ` ). § A function ID (symbol) may not take the form of numbers. § It's very common for symbols to have hyphens ( - ) or asterisks ( * ) in them. § There are NOT operators! only functions § Symbols (function ID) are case-INSENSITIVE.
  10. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 19 jgs

    Atomic Expressions § -3 § 2.43 § 123342303923412323411323234012923492341231230234923410239234412 § #C(3.2 2) ; the complex number 3.2 + 2i § 2/3 ; the fraction 2/3. It is NOT divide 2 by 3 § -3.2e25 ; the number -3.2 x 10^25 § #\g ; characters starts with #\ § #\{ § #\\ ; the character '\' § #\tab
 § #\newline § 
#\space
 § #\backspace
 § #\escape
  11. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 20 jgs

    Atomic Expressions § "Hello, World!" § "It's a glorious day." § "He said \"No Way!\" and then he left." § "I think I need a backslash here: \\ Ah, that was better." § t ; true § nil ; false
  12. jgs CSE 240 Introduction to Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu

    Spring 2018 Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.