# Functional programming in LISP

Size: px
Start display at page:

Transcription

1 Programming Languages Week 4 Functional programming in LISP College of Information Science and Engineering Ritsumeikan University

2 review of part 3 enumeration of dictionaries you receive a sequence of the keys easy to convert them to values or associations dictionary association list { a :1, b :2} [( a,1), ( b :2)] Python syntax for functional programming map(f, sequence) [f(x) for x in sequence] filter(f, sequence) [x for x in sequence if f(x)] multiple return values def nts(x): return x, x+x, x*x number, twice, squared = nts(10) print number, twice, squared #=> generators yield instead of return lazy evaluation compute values only when they are actually needed 2

3 a functional programming language 1948 first electronic computer, programmed in machine code (1 st -generation languages) 1949 programmers use assembly language (second-generation languages) 1952 first high-level language: Autocode (third-generation languages) 1954 John Backus invents FORTRAN, first widely-used high-level language 1955 Grace Hopper invented FLOW-MATIC, eventually leading to COBOL 1958 John McCarthy invents LISP, the LISt Processing language, and the first dynamically-typed, functional, symbolic language language to have automatic memory management (garbage collection) language able to extend its own syntax and semantics language useful for Artificial Intelligence given the historical context, the achievements of LISP were miraculous maybe largely due to it being based on mathematical principles 3

4 components of LISP programs atoms simple names and values numbers: e9 strings: "hello world" "abc" "" symbols: hello goodbye + -, &! #t #f #nil lists sequences of zero or more atoms or lists enclosed in parentheses the empty list: () one-dimensional list: ( 1 2 a b "last") two-dimensional (nested) list: ( 1 (2 a b) "last") 4

5 meaning of LISP programs an expression is either an atom, or a list of expressions all expressions are evaluated when they are encountered during program execution evaluating atoms: symbols name variables and evaluate to their currently bound value other atoms (numbers and strings) evaluate to themselves (they are literals) evaluating lists: a list is evaluated as a function call apply the value of their first element (a function) to the values of the remaining elements (the arguments) try these expressions now in Guile (press Enter at the end of each line): (+ 3 4) (+ 3 (* 4 5)) 5

6 some useful functions all the usual mathematical operators, including: + - * / < <= = >= > that work correctly, whenever possible, with any number of arguments try these: ( ) (* ) (display value) prints value in a friendly form; e.g., strings are not surrounded by " characters (write value) prints value in the same form you would use to write it as a literal note that neither write nor display print a newline (newline) prints a newline try these... (display "hello\n") (write "hello\n") 6

7 everything is an expression there are no statements in LISP (if #t 2 3) ; an if expression (if #f 2 3) the two values called #t and #f represent true and false when symbols are evaluated, they are treated as variable identifiers the value that they are bound to is looked up if they are not bound to a value, an unbound variable error occurs try this expression: kaboom 7

8 defining and setting variables variables (define name value) creates a new variable called name and binds value to it (set! name value) re-binds name to a new value conditionals and loops (if condition consequent alternate) if condition is #t then consequent is evaluated, otherwise alternate (while condition consequent1 consequent2...) repeatedly evaluates all the consequents as long as the condition remains #t for example: (define x 10) (while (> x 0) (display x) (newline) (set! x (- x 1))) 8

9 anonymous functions anonymous functions (closures) are created with lambda (lambda (parameters...) expressions...) creates a closure (anonymous function) which, when called, evaluates the expressions in a context where successive parameter symbols are bound to successive actual arguments try these: (lambda () 42) ; an anonymous function ((lambda () 42)) ; which can be called with zero arguments (lambda (x) (+ x x)) ; function of one argument ((lambda (x) (+ x x)) 21) ; called with one argument (define double (lambda (x) (+ x x))) ; same function, bound globally (double 21) 9

10 function definitions function definitions are so common that they have a shorthand syntax (define square (lambda (x) (* x x))) can be written (define (square x) ; written exactly the way it is called (* x x)) ; the lambda is implicit, but still there (square 8) ; => 64 10

11 literal data the quote function returns its argument unevaluated (quote value) returns value without evaluating it try these: (+ 3 4) (quote (+ 3 4)) quote is so useful that it has a shorthand notation using a single quote character (+ 3 4) (+ 3 4) ; same as (quote (+ 3 4)), which is... (+ 3 4) ;... easily proven ;-) 11

12 map, filter, reduce Guile has built-on map and filter (working like the Python ones) (define double (lambda (x) (+ x x))) (map double (1 2 3)) ; => (2 4 6) (define even? (lambda (x) (= 0 (remainder x 2)))) (filter even? ( )) ; => (0 2 4) there is no built-in reduce, but it is easy to define and most arithmetic operators accept any number of arguments 12

13 lists (car list) returns the head (first element) of list (cdr list) returns the tail (all elements after the first) of list (car (1 2 3)) ; => 1 (cdr (1 2 3)) ; => (2 3) (cadr (1 2 3)) ; => 2 - same as (car (cdr (1 2 3))) (cddr (1 2 3)) ; => (3) - same as (cdr (cdr (1 2 3))) etc... 13

14 lists (length list) returns the number of elements in list (append lists...) concatenates all the lists to make a new list (list values...) makes a new list containing all the values (length ()) ; => 0 (length (a b c d)) ; => 4 (append (a b) (c d)) ; => (a b c d) (append (a b) (list 1 2 3)) ; => (a b 1 2 3) 14

15 quasiquotation quoted data is exactly as written (+ 3 (* 4 5)) ; => (+ 3 (* 4 5)) using a backquote instead of a forward quote (+ 3 (* 4 5)) ; => (+ 3 (* 4 5)) turns evaluation back on for any elements in the list preceded by a comma (+ 3,(* 4 5)) ; => (+ 3 20) this is useful for writing mostly-literal data with some computed parts 15

16 metaprogramming a metaprogram is a program that manipulates programs this is especially easy in LISP, because programs and data are the same thing define-macro defines a function that is called immediately, while an expression is being read in does not evaluate its arguments when the function is called, the parameters are bound to the data structure representing the expression 16

17 metaprogramming a function that squares its argument: (define (squared x) (display "squaring ") (display x) (newline) (* x x)) (define (test n) (squared n)) (test 9) ; => squaring 9 ; => 81 the message "squaring 9" is printed when text is evaluated 17

18 metaprogramming a function that squares its argument: (define (squared x) (display "squaring ") (display x) (newline) (*,x,x)) (define (test n) (squared n)) (test 9) ; => squaring 9 ; => (* 9 9) the function now returns an expression to calculate the desired result 18

19 a macro that squares its argument: (define-macro (squared x) (display "squaring ") (display x) (newline) (*,x,x)) metaprogramming (define (test n) (squared n)) ; => squaring n (test 9) ; => (* 9 9) the macro is executed during the definition of test and the result (* n n) used in place of (squared n) the definition of test is actually (define (test n) (* n n)) define-macro lets the programmer invent new syntax, control constructs, etc. 19

20 metaprogramming example imagine (unless x y z) which works like if, except that y is evaluated if x is false z is evaluated if x is true (define-macro (unless x y z) (if (not,x),y,z)) (if #t 1 2) ; => 1 (unless #t 1 2) ; => 2 (unless #f 1 2) ; => 1 metaprogramming is used to create domain-specific mini-languages within LISP new control constructs, data types, etc. designed to be effective for a specific problem domain programming becomes a two-stage process: design an optimal language to solve your problem, and implement it in LISP solve your problem by writing a program in your optimal language this is called metalinguistic abstraction 20

21 local variables are introduced using let local variables and blocks (let ((a 3) (b 4)) ; create and initialise two local variables (display a) (newline) (display b) (newline) (+ a b)) ; => 7 grouping several expressions together (let () (display "hello\n") 42) ; => 42 which has its own shorthand notation (begin (display "hello\n") 42) ; => 42 that is useful, e.g., to provide multiple expressions in an if 21

22 functional programming resources Scheme (a modern dialect of Lisp) impure FP with an emphasis on metaprogramming and linguistic abstraction good for prototyping new language semantics the best book ever written about programming uses Scheme comes with a free, complete online course MIT Open Courseware Structure and Interpretation Of Computer Programs Spring-2005/CourseHome/index.htm many dialects, some popular ones include: Guile MIT Scheme Haskell pure FP that is a small step up from FP in Python syntax not too different from Python s list comprehension syntax overloaded functions through pattern matching good for your career: Haskell is quite widely used in industry aerospace, defense, finance, social web apps, hardware design,... 22

### 11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the

### Introduction to LISP. York University Department of Computer Science and Engineering. York University- CSE V.

Introduction to LISP York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 11_LISP 1 Introduction to LISP Evaluation and arguments S- expressions Lists Numbers

### Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are first-class values E.g., functions

### Functional Programming

Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used

### Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu

### COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

### Scheme: Expressions & Procedures

Scheme: Expressions & Procedures CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, March 31, 2017 Glenn G. Chappell Department of Computer Science University

### Functional Programming. Pure Functional Languages

Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

### Functional Programming. Big Picture. Design of Programming Languages

Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

### Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

### Functional Programming. Pure Functional Languages

Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

### FP Foundations, Scheme

FP Foundations, Scheme In Text: Chapter 15 1 Functional Programming -- Prelude We have been discussing imperative languages C/C++, Java, Fortran, Pascal etc. are imperative languages Imperative languages

### LECTURE 16. Functional Programming

LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

### Functional Programming. Pure Functional Programming

Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

### Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

CS 61A Scheme Spring 2018 Discussion 7: March 21, 2018 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme

### CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.

### SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

### SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

### Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)

Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology

### Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write

### Imperative languages

Imperative languages Von Neumann model: store with addressable locations machine code: effect achieved by changing contents of store locations instructions executed in sequence, flow of control altered

### Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

CS 6A Scheme Fall 207 Discussion 7: October 25, 207 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write

### functional programming in Python, part 2

Programming Languages Week 2 functional programming in Python, part 2 College of Information Science and Engineering Ritsumeikan University review of part 1 eliminating assignment makes programs easier

### Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is

### Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP)

Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology

### Modern Programming Languages. Lecture LISP Programming Language An Introduction

Modern Programming Languages Lecture 18-21 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation

### Chapter 15 Functional Programming Languages

Chapter 15 Functional Programming Languages Fundamentals of Functional Programming Languages Introduction to Scheme A programming paradigm treats computation as the evaluation of mathematical functions.

### SCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012

SCHEME COMPUTER SCIENCE 6A October 29th, 202 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs, we will eventually

### CPS 506 Comparative Programming Languages. Programming Language Paradigm

CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming

### LISP Programming. (23 (this is easy) hello 821)

LISP Programming LISP is one of the simplest computer languages in terms of syntax and semantics, and also one of the most powerful. It was developed in the mid-1950 s by John McCarthy at M.I.T. as a LISt

### Concepts of programming languages

Concepts of programming languages Lecture 7 Wouter Swierstra 1 Last time Relating evaluation and types How to handle variable binding in embedded languages? 2 DSLs: approaches A stand-alone DSL typically

### SOFTWARE ARCHITECTURE 6. LISP

1 SOFTWARE ARCHITECTURE 6. LISP Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ 2 Compiler vs Interpreter Compiler Translate programs into machine languages Compilers are

### Introduction. chapter Functions

chapter 1 Introduction In this chapter we set the stage for the rest of the book. We start by reviewing the notion of a function, then introduce the concept of functional programming, summarise the main

### Introduction to Scheme

How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free

### Macros & Streams Spring 2018 Discussion 9: April 11, Macros

CS 61A Macros & Streams Spring 2018 Discussion 9: April 11, 2018 1 Macros So far, we ve mostly explored similarities between the Python and Scheme languages. For example, the Scheme list data structure

### Functional Programming Languages (FPL)

Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional

### Documentation for LISP in BASIC

Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur Nunes-Harwitt LISP in BASIC is a LISP interpreter for a Scheme-like dialect of LISP, which happens to have

### Haskell: Lists. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, Glenn G.

Haskell: Lists CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks

### Functional Languages. Hwansoo Han

Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

### A Small Interpreted Language

A Small Interpreted Language What would you need to build a small computing language based on mathematical principles? The language should be simple, Turing equivalent (i.e.: it can compute anything that

### Programming Languages

Programming Languages Lambda Calculus and Scheme CSCI-GA.2110-003 Fall 2011 λ-calculus invented by Alonzo Church in 1932 as a model of computation basis for functional languages (e.g., Lisp, Scheme, ML,

### Fifth Generation CS 4100 LISP. What do we need? Example LISP Program 11/13/13. Chapter 9: List Processing: LISP. Central Idea: Function Application

Fifth Generation CS 4100 LISP From Principles of Programming Languages: Design, Evaluation, and Implementation (Third Edition, by Bruce J. MacLennan, Chapters 9, 10, 11, and based on slides by Istvan Jonyer

### COP4020 Programming Assignment 1 - Spring 2011

COP4020 Programming Assignment 1 - Spring 2011 In this programming assignment we design and implement a small imperative programming language Micro-PL. To execute Mirco-PL code we translate the code to

### ALISP interpreter in Awk

ALISP interpreter in Awk Roger Rohrbach 1592 Union St., #94 San Francisco, CA 94123 January 3, 1989 ABSTRACT This note describes a simple interpreter for the LISP programming language, written in awk.

### LISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits.

LISP Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. From one perspective, sequences of bits can be interpreted as a code for ordinary decimal digits,

### 15. Functional Programming

15. Functional Programming 15.1 Introduction The design of the imperative languages is based directly on the von Neumann architecture Efficiency is the primary concern, rather than the suitability of the

### CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages 3: Scheme Introduction Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg [1]

### Notes on Higher Order Programming in Scheme. by Alexander Stepanov

by Alexander Stepanov August 1986 INTRODUCTION Why Scheme? Because it allows us to deal with: 1. Data Abstraction - it allows us to implement ADT (abstact data types) in a very special way. The issue of

### Lecture 19: Functions, Types and Data Structures in Haskell

The University of North Carolina at Chapel Hill Spring 2002 Lecture 19: Functions, Types and Data Structures in Haskell Feb 25 1 Functions Functions are the most important kind of value in functional programming

### Chapter 15. Functional Programming Languages

Chapter 15 Functional Programming Languages Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: Lisp Introduction

### Introduction to lambda calculus Part 3

Introduction to lambda calculus Part 3 Antti-Juhani Kaijanaho 2017-01-27... 1 Untyped lambda calculus... 2 Typed lambda calculi In an untyped lambda calculus extended with integers, it is required that

### Artificial Intelligence Lecture 1

Artificial Intelligence Lecture 1 istrative Matters Webpage: www.aass.oru.se/~ali/ai2008 Teacher: Amy Loutfi Hours: Fridays 10 12 Lab Assistant: Marcello Cirillo 2 istrative Matters Course book: Alison

### Organization of Programming Languages CS3200/5200N. Lecture 11

Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages

### Lambda Calculus see notes on Lambda Calculus

Lambda Calculus see notes on Lambda Calculus Shakil M. Khan adapted from Gunnar Gotshalks recap so far: Lisp data structures basic Lisp programming bound/free variables, scope of variables Lisp symbols,

### Lecture #24: Programming Languages and Programs

Lecture #24: Programming Languages and Programs A programming language is a notation for describing computations or processes. These range from low-level notations, such as machine language or simple hardware

### A LISP Interpreter in ML

UNIVERSITY OF OSLO Department of Informatics A LISP Interpreter in ML Mandatory Assignment 1 INF3110 September 21, 2009 Contents 1 1 Introduction The purpose of this assignment is to write an interpreter,

### Concepts of Programming Languages

Concepts of Programming Languages Lecture 15 - Functional Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

### The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

### MIT Scheme Reference Manual

MIT Scheme Reference Manual Edition 1.95 for Scheme Release 7.6.0 26 November 2001 by Chris Hanson the MIT Scheme Team and a cast of thousands Copyright c 1988-2001 Massachusetts Institute of Technology

### CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Basics

1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Basics 2 Contents 1. Jump into Haskell: Using ghc and ghci (more detail) 2. Historical Background of Haskell 3. Lazy, Pure, and Functional

### 4/19/2018. Chapter 11 :: Functional Languages

Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken by Alan Turing, Alonzo Church, Stephen

### CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

### Example Scheme Function: equal

ICOM 4036 Programming Languages Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: LISP Introduction to

### INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing Common Lisp Fundamentals Stephan Oepen & Murhaf Fares Language Technology Group (LTG) August 30, 2017 Last Week: What is

### A Brief Introduction to Scheme (II)

A Brief Introduction to Scheme (II) Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Lists Scheme II p.1/29 Lists Aggregate data

### Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example.

Racket Next 2+ weeks will use the Racket language (not ML) and the DrRacket programming environment (not emacs) Installation / basic usage instructions on course website CSE34: Programming Languages Lecture

### FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE,

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti L I S P - Introduction L I S P

### SCHEME AND CALCULATOR 5b

SCHEME AND CALCULATOR 5b COMPUTER SCIENCE 6A July 25, 203 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

### CS 360 Programming Languages Interpreters

CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like

### Functional Programming Lecture 1: Introduction

Functional Programming Lecture 1: Introduction Viliam Lisý Artificial Intelligence Center Department of Computer Science FEE, Czech Technical University in Prague viliam.lisy@fel.cvut.cz Acknowledgements

### Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Scheme in Scheme: The Metacircular Evaluator Eval and Apply CS21b: Structure and Interpretation of Computer Programs Brandeis University Spring Term, 2015 The metacircular evaluator is A rendition of Scheme,

### Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003

Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 CS 314, LS, LTM: Functional Programming 1 Scheme A program is an expression to be evaluated (in

### CS 342 Lecture 6 Scheme Procedures and Closures By: Hridesh Rajan

CS 342 Lecture 6 Scheme Procedures and Closures By: Hridesh Rajan 1 Reading Little Schemer Chapter 8 SICP 1, 3.2 2 Lecture Overview In this lecture, we will cover scheme procedures in a bit more detail

### 6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

6.184 Lecture 4 Interpretation Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 1 Interpretation Parts of an interpreter Arithmetic calculator

### Scheme Quick Reference

Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete

### It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

Chapter 14 Functional Programming Programming Languages 2nd edition Tucker and Noonan It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

### Scheme: Strings Scheme: I/O

Scheme: Strings Scheme: I/O CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Wednesday, April 5, 2017 Glenn G. Chappell Department of Computer Science University of

### CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

CS 61A Spring 2019 Guerrilla Section 5: April 20, 2019 1 Interpreters 1.1 Determine the number of calls to scheme eval and the number of calls to scheme apply for the following expressions. > (+ 1 2) 3

### Intro. Scheme Basics. scm> 5 5. scm>

Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

### CS 242. Fundamentals. Reading: See last slide

CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

### Principles of Programming Languages 2017W, Functional Programming

Principles of Programming Languages 2017W, Functional Programming Assignment 3: Lisp Machine (16 points) Lisp is a language based on the lambda calculus with strict execution semantics and dynamic typing.

### Functional Programming Languages (FPL)

Functional Programming Languages (FPL) 1. Definitions... 3 2. Applications... 3 3. Examples... 4 4. FPL Characteristics:... 5 5. Lambda calculus (LC)... 6 5.1. LC expressions forms... 6 5.2. Semantic of

### Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

### Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

Functional Languages CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Historical Origins 2 The imperative and functional models grew out of work

### CS 11 Haskell track: lecture 1

CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of

### CSCI337 Organisation of Programming Languages LISP

Organisation of Programming Languages LISP Getting Started Starting Common Lisp \$ clisp 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

### Project 2: Scheme Interpreter

Project 2: Scheme Interpreter CSC 4101, Fall 2017 Due: 12 November 2017 For this project, you will implement a simple Scheme interpreter in C++ or Java. Your interpreter should be able to handle the same

### \n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

### 15 Unification and Embedded Languages in Lisp

15 Unification and Embedded Languages in Lisp Chapter Objectives Chapter Contents Pattern matching in Lisp: Database examples Full unification as required for Predicate Calculus problem solving Needed

### Scheme Quick Reference

Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries

### The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

### Introduction to Functional Programming and basic Lisp

Introduction to Functional Programming and basic Lisp Based on Slides by Yves Lespérance & Peter Roosen-Runge 1 Functional vs Declarative Programming declarative programming uses logical statements to

### Lambda Calculus. Gunnar Gotshalks LC-1

Lambda Calculus LC-1 l- Calculus History Developed by Alonzo Church during 1930 s-40 s One fundamental goal was to describe what can be computed. Full definition of l-calculus is equivalent in power to

### Principles of Programming Languages

Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Lesson 6 - Defining a Programming Language Bottom Up Collaboration and Management - Elements of Programming Dana Fisman 1 What we accomplished

### CSCE 314 Programming Languages

CSCE 314 Programming Languages Haskell 101 Dr. Hyunyoung Lee 1 Contents 1. Historical Background of Haskell 2. Lazy, Pure, and Functional Language 3. Using ghc and ghci 4. Functions 5. Haskell Scripts

### Week 2: The Clojure Language. Background Basic structure A few of the most useful facilities. A modernized Lisp. An insider's opinion

Week 2: The Clojure Language Background Basic structure A few of the most useful facilities A modernized Lisp Review of Lisp's origins and development Why did Lisp need to be modernized? Relationship to

### Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89

Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic expressions. Symbolic manipulation: you do it all the