SlideServe
Menu
Préférences
© SlideServe · v2026

Introduction to Functional Programming with Scheme

pakuna avatar
19 diapositives · 340 Views · Sep 24, 2014

Dive into the world of functional programming using Scheme with Carl Reynolds' insightful guide. This resource covers essential components such as expressions, data types, and the Read-Eval-Print Loop (REPL), offering practical examples. Learn about atoms, lists, and various data manipulations including list creation, recursion, and function definitions. Each concept is illustrated with clear REPL demonstrations making it accessible for beginners. By the end, you'll have a solid understanding of how to work with Scheme to solve problems functionally.

Introduction to Functional Programming with Scheme - slide 1
01 / 19Introduction to Functional Programming with Scheme
1 / 17

Télécharger la présentation

Introduction to Functional Programming with Scheme
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Introduction to Functional Programming with Scheme Carl Reynolds Carl Reynolds 2006

  2. Expressions • Atoms • Numbers like 5 or 6.79 • Symbols like x, /, +, or find-parents • Strings like “Bach” or “Carl” • Lists • ( enclosed within parentheses ) • () null list Carl Reynolds 2006

  3. Data Types • Variables do not have type • A variable can hold any type of data • Values have type • Integer • Floating point • String • List Carl Reynolds 2006

  4. Read-Eval-Print Loop--REPL • Number evaluates to itself • String evaluates to itself • Symbol evaluates to the value of the variable • List • First element is evaluated as a function, and following elements as arguments to the function Carl Reynolds 2006

  5. REPL examples > 4 4 > "Carl" "Carl" > (define x 17) > x 17 > Carl Reynolds 2006

  6. REPL examples (cont.) > (+ x 8) 25 > (define y (- x 3)) > y 14 > Carl Reynolds 2006

  7. quote > x 17 > (quote x) ;don’t evaluate x x > 'x ;alternate syntax x > x 17 > Carl Reynolds 2006

  8. Lists > (list 8 9 2) ;make a list (8 9 2) > (list 8 x y 88 x) (8 17 14 88 17) > (list a b c d) [Repl(15)] Error: variable d is not bound. Type (debug) to enter the debugger. > (list 'a 'b 'c 'd) (a b c d) > Carl Reynolds 2006

  9. Lists of lists > (define car-list (list 'ford 'vw 'nissan)) > (define drivers (list 'carl 'david 'chris)) > (define rides (list drivers car-list)) > rides ((carl david chris) (ford vw nissan)) >drivers (carl david chris) > car-list (ford vw nissan) > Carl Reynolds 2006

  10. car > rides ((carl david chris) (ford vw nissan)) > > (car rides) (carl david chris) > (car (car rides)) carl > (caar rides) carl > Carl Reynolds 2006

  11. cdr (“coulder”) > (car rides) (carl david chris) > (cdr (car rides)) (david chris) > (car (cdr rides)) (ford vw nissan) > (cdr (car (cdr rides))) (vw nissan) > (cdr rides) ((ford vw nissan)) > (cdr (cdr rides)) () > (cdadr rides) (vw nissan) > Carl Reynolds 2006

  12. cons > (cons 'honda car-list) (honda ford vw nissan) > car-list (ford vw nissan) > (define car-list (cons 'honda car-list)) > car-list (honda ford vw nissan) > (cons 'bmw car-list) (bmw honda ford vw nissan) > Carl Reynolds 2006

  13. cons (cont.) > (define violations () ) > violations () > (cons 'my-first-ticket violations) (my-first-ticket) > Carl Reynolds 2006

  14. append > (define more-cars (list 'chevy 'buick 'saab)) > (append car-list more-cars) (honda ford vw nissan chevy buick saab) > car-list (honda ford vw nissan) > more-cars (chevy buick saab) > Carl Reynolds 2006

  15. Writing your own functions( lambda (params) (body) ) >(define square (lambda ( x ) (* x x) ) ) > (square 8) 64 Carl Reynolds 2006

  16. Functions (cont.) > (define second (lambda (myList) (cadr myList)) ) > (second drivers) david > drivers (carl david chris) > Carl Reynolds 2006

  17. if > (define bigger (lambda (a b) (if (> a b) a b)) ) > (bigger 6 7) 7 > (bigger 5 2) 5 > Carl Reynolds 2006

  18. cond (define how-hot-is-it (lambda ( degrees ) (cond ( ( < degrees 32 ) 'freezing ) ( ( and (> degrees 68 ) (< degrees 80) ) 'comfortable ) ( ( >= degrees 90 ) 'too-hot ) ( #t 'hard-to-say ) ) ) ) > (how-hot-is-it 77) comfortable > (how-hot-is-it 44) hard-to-say > Carl Reynolds 2006

  19. Recursion (define listSum (lambda (n) (cond ((null? n) 0) ((null? (cdr n)) (car n) ) ( else (+ (car n) (listSum2 (cdr n)))) ))) > (listsum '(3 6 12 3)) 24 > (listsum '(4)) 4 > (listsum '() ) 0 > Carl Reynolds 2006