Part 2 Summer 2014 Web.pdf-Part II: Func...
Part_2_Summer_2014_Web.pdf-Part II: Functional Programming with LISP
Showing 5-8 out of 53
Part 2 Summer 2014 Web.pdf-Part II:...
Part_2_Summer_2014_Web.pdf-Part II: Functional Programming with LISP
##### Page 5
5
9
Expressions
LISP is an
expression-oriented language
. No
"expressions"
and
"statements"
; all code and data are written as
expressions.
When an expression is evaluated, it produces a
value (or list of values), which then can be
embedded into other expressions.
10
Prefix Notation
Expressions are written as
lists
, using
prefix notation
.
Prefix notation is a form of notation for logic, arithmetic,
and algebra.
It places operators to the left of their operands.
For example,
the expression
5-(6 + 7)
is written as:
(- 5 (+ 6 7))

##### Page 6
6
11
Evaluation
The first element in an
expression list
is the name of
a form (i.e., a function) and the remainder of the list
are the arguments:
(<function_name> <arguments>)
e.g.
(+ 3 (* 4 5))
The LISP evaluation rule:
– Arguments are evaluated from left to right. The
values of the arguments are then passed to the
function named by the operator.
12
For constant objects (e.g. strings, numbers) the object itself is
the value.
Expressions which specify the application of arithmetic
procedures + - * / to a set of arguments are called
procedure
applications
.
How to distinguish between a list of objects
(obj1, obj2,
..)
and a procedure application
(procedure arg..)
?
The subexpressions of a procedure application are evaluated,
whereas the subexpressions of a quoted expression are not.
(/ (* 2 6) 3) =>
4
‘(/ (* 2 6) 3)
=>
(/ (* 2 6) 3)
Evaluation

##### Page 7
7
13
Arity Property of Functions
The term arity is used to describe the number of arguments or
operands that a function takes.
– An
unary
function (arity 1) takes one argument.
–A
binary
function (arity 2) takes two arguments.
–A
ternary
function (arity 3) takes three arguments.
– An
n-ary
function takes n arguments.
Variable arity functions:
Can take any number of arguments.
Examples are: +, *, <
(+ 1 2 3 4)
; returns 10.
(* 2 4 3)
; returns 24
(< 1 3 2)
; nil
14
Data
Every programming language has
data types
and ways of combining and abstracting them.
For any data type, we are concerned with:
– The values of the type.
– The operations on that type.
– How the values are represented.

##### Page 8
8
15
Simple Data Types
Simple types (
atoms
): An atom is a number or a
symbol.
Boolean
t, nil
Number
integers, floating point numbers,
ratios, complex numbers, etc.
Symbol
character sequences.
16
Composite Data Types
•A
list
is a
parenthesized
,
space-separated finite
ordered sequence of elements
, where each
element is in itself either an
atom
or a
list
.
((1 2)(3 4))
(138 abcde 54 18)
(sometimes (parentheses (get))
complicated)
()
A list is a singly-linked list.

Browse thousands of Study Materials & Solutions from your Favorite Schools
Concordia University
Concordia_University
School:
Principles_Of_Programming_Lang
Course:
Great resource for chem class. Had all the past labs and assignments
Leland P.
Santa Clara University
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades