


Part 2 Summer 2014 Web.pdf
Part_2_Summer_2014_Web.pdf
Showing 58 out of 53
Part 2 Summer 2014 Web.pdfPart II: Functional Pro...
Part_2_Summer_2014_Web.pdfPart II: Functional Programming with LISP
Part 2 Summer 2014 Web.pdfPart II:...
Part_2_Summer_2014_Web.pdfPart II: Functional Programming with LISP
Page 5
5
9
Expressions
•
LISP is an
expressionoriented language
. No
distinction is made between
"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
nary
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
,
spaceseparated 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 singlylinked list.
Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
Concordia University
Concordia_University
School:
Principles_Of_Programming_Lang
Course:
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
Students also viewed documents
lab 18.docx
lab_18.docx
Course
Course
3
Module5QuizSTA2023.d...
Module5QuizSTA2023.docx.docx
Course
Course
10
Week 7 Test Math302....
Week_7_Test_Math302.docx.docx
Course
Course
30
Chapter 1 Assigment ...
Chapter_1_Assigment_Questions.docx.docx
Course
Course
5
Week 4 tests.docx.do...
Week_4_tests.docx.docx
Course
Course
23
Week 6 tests.docx.do...
Week_6_tests.docx.docx
Course
Course
106