Chapter 15 Flashcards
What is imperative language design based on?
von Neumann architecture with efficiency as primary concern
What is functional language design based on?
Mathematical functions
What are functional side effects?
When a function changes a parameter or a global variable
What is the problem with functional side effects?
Unpredictable, Concurrency issues
How to solve functional side effects?
1) No 2 way parameters, No non-local references in functions. but it is very inflexible
2) Demand fixed operand evaluation order. limits some complier optimizations
When does a program have referential transparency?
Any 2 expressions that are equivalent can be substituted for one another and it doesn’t affect the action.
There are no functional side effects
What is the advantage of referential transparency?
semantics are easier to understand
Are Pure Functional Languages referentially transparent? and why?
Yes. No global variables. parameter values are constants. functions cannot have state, value of function depends only on parameters
What is the objective of functional language designs?
mimic math functions as closely as possible
What are the LISP Data Objects and Structures?
Only consists of atoms and lists
2 types of atoms (symbols and numeric literals)
List = sequence of atoms or sublists
What does Scheme and Lisp have in common?
They use the same atoms and lists
What is Scheme interpreter interactive mode?
Mode that allows you to type code in line by line rahter than programming in an editor
Scheme interpreter is just a Scheme function?
Yes
How are functions evaluated?
Parameters (in no order)
values of parameters substituted into the function body
Value of last expression evaluated in the body is the value that the function defines
What are the Primitive Numeric Functions
+,-,*,/,abs,sqrt,remainder,min,max
Which primitive numeric functions cannot accept multiple parameters?
abs,sqrt,remainder
What are lambda functions used for?
Nameless functions
how many parameters can lambda functions have?
any number of parameters
how do you bind names to lambda expressions?
(define (square x) (* x x))
how do you bind a name to the value of an expression
(define pi 3.142) or (define two_pi (* 2 pi))