/
ITEC  380 Organization of programming languages ITEC  380 Organization of programming languages

ITEC 380 Organization of programming languages - PowerPoint Presentation

hadley
hadley . @hadley
Follow
66 views
Uploaded On 2023-09-19

ITEC 380 Organization of programming languages - PPT Presentation

Lecture 3 Functional Programming Review Grammars BNFEBNF How to write a parser why to do so Parse trees Types of parsers Objectives Intro to lisp Getting an interpreter working Loading programs ID: 1017810

ooooo list programming princ list ooooo princ programming bruno haible defparameter local lists functions type clisp sam missing steingold

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "ITEC 380 Organization of programming la..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. ITEC 380Organization of programming languagesLecture 3 – Functional Programming

2. ReviewGrammarsBNF/EBNFHow to write a parser, why to do soParse treesTypes of parsers

3. ObjectivesIntro to lispGetting an interpreter workingLoading programsBasic lists / operationsCombining / Parsing lists

4. LispDifferent evolutionary path than imperative / OO type programmingMuch more math focusedRemoves the focus on the state of a program from the equationWorks on lists of numbers / stringsCase insensitive language!!!

5. Getting it runningVisitOnce you run it, you get something like i i i i i i i ooooo o ooooooo ooooo ooooo I I I I I I I 8 8 8 8 8 o 8 8 I \ `+' / I 8 8 8 8 8 8 \ `-+-' / 8 8 8 ooooo 8oooo `-__|__-' 8 8 8 8 8 | 8 o 8 8 o 8 8 ------+------ ooooo 8oooooo ooo8ooo ooooo 8Welcome to GNU CLISP 2.49 (2010-07-07) <http://clisp.cons.org/>Copyright (c) Bruno Haible, Michael Stoll 1992, 1993Copyright (c) Bruno Haible, Marcus Daniels 1994-1997Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998Copyright (c) Bruno Haible, Sam Steingold 1999-2000Copyright (c) Sam Steingold, Bruno Haible 2001-2010http://www.clisp.org/

6. Ways to useCan pipe a program into itclisp < filename.txtCan type code straight into the shell(+ 3 2)Can load code from files(load “filename.txt”)Note: define functions in file, run by hand

7. Step 1Start with the most evil part of any programming language: Global variablesExample(defparameter *tiny* 1)(defparameter *large* 10)*tiny**large*Note:* Is just a stylistic convention

8. Step 2Create a function accomplish a taskExampleWhat does this print out?Does it matter where the )’s are(defparameter *small* 1)(defparameter *big* 10)(defun addtwo () (* (- *big* *small*) 2 ))

9. Local parametersLet = freedomWhat are the advantages of local versus global?Can create local functions with fletCan allow recursion with local functions with labels(defun localTest() (let ((a 5) (b 6)) (c(+ a b)) ))

10. Other wayssetq(setq Name ‘Me)list(list Name ‘You and a dog named boo)

11. DataNumbers4/6 => How would this be put into lisp?4.0/6 => Ditto?StringsEnclose in “ “ otherwise will be treated like a functionItems as a list‘(+ 2 1) versus (+ 2 1)

12. I/OInput data to a variableOutput a variable(let ((A "Hello")) (princ A)) (let ((A (read))) (princ A))

13. Working with listsThree basic functionsconsCombine lists togethercarAccess the first item in a listcdrReturn the second element to the end of a list

14. FlexibilityCan combine multiple car and cdrs togetherCan also cheat by usingFirst, second, third, fourth, etc…cadrcddrcadarApple Peach Mango Pear Strawberry Blueberry Pineapple(Apple (Red Yellow Pink Lady) Peach (Georgia California))

15. Inside listsHow to check if a number is in a list(member 5 ‘(3 4 5))How access a particular item in the list(find-if #’oddp ‘(1 2 4))

16. ConditionalsSimple to use(if (conditional) (then) (else) )Sometimes you will make a function call instead of the ‘(list data)Also have when and unless(if (> 5 3) (princ "Larger") (princ "Smaller"))

17. ConditionalsCan have multiple conditionalsExample(cond ((or (> 3 5) (>2 6) ) (princ “One”)) ((< 2 4) (princ “Two”)))

18. FunctionsWhat is out there?abs,sin, cos, tan, mod, round, min, max, expt, sqrtfirst,rest,last, lengthcons, append, list Type checkinglistp,numberp,integerp,stringp, evenp, oddpOthersnull, equal/eql/eq, and, or, notUse eq for symbols, equal for all others

19. Missing?Given what you know of existing programming languages, what is currently missing?How do we work around these missing features?

20. Next weekFunctional programming - Lisp