Programming Languages Exam 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

thunks

"shell" procedures

Lambda special form

(Creates a function) with the specified formal parameters and a body of code to be evaluated when the function is applied.

Qualities of functional program languages

- All procedures are functions that distinguish incoming values (parameters) from outgoing values (results) - In pure functional programming, there are no assignments - In pure functional programming, there are no loops - Value of a function depends only on its parameters, not on order of evaluation or execution path- Functions are first-class data values

Applicative order evaluation

- All subexpressions are evaluated first - A corresponding expression tree is evaluated from leaves to root

value of a function (as an object) in Scheme

- Function is represented by the first expression in an application - Function call is surrounded by parentheses

elements of small talk

- Message - Receiver - Method - Sender - Mutators - Message passing - Interface - Selector

Why are functional languages not mainstream?

- Programmers learn imperative or object-oriented languages first - OO languages provide a strong organizing principle for structuring code that mirrors the everyday experience of real objects

Functional Programming

- Provides a uniform view of programs as functions - Treats functions as data - Provides prevention of side effects

quote special form

- Scheme will try to evaluate a list of numbers as a function call - Must prevent this and consider it to be a list literal, using the _ _ _

What makes functional programming attractive?

- They lend themselves very well to parallel execution - May be more efficient than imperative languages on multicore hardware architectures - Have mature application libraries

features in Lisp

- Uniform representation of programs and data using a single general structure: the list - Definition of the language using an interpreter written in the same language (metacircular interpreter) - Automatic memory management by the runtime system

variables in functional programming

- takes a mathematical approach - Variables are bound to values, not memory locations - A variable's value cannot change, which eliminates assignment as an available operation

type class

-A set of types that all define certain functions -Specifies the names and types (called signatures) of the functions that every type belonging to it must define Similar to Java interfaces

shared inheritance

-Example: object of class D has one copy of class A

first-class data values

-Functions can be computed by other functions -Functions can be parameters to other functions

four basic kinds of polymorphism

-Parametric polymorphism: type parameters remain unspecified in declarations -Overloading (ad hoc polymorphism): different function or method declarations share the same name but have different types of parameters in each -Subtype polymorphism: all operations of one type can be applied to another type -Inheritance: a kind of subtype polymorphism

_1_ function applications use pass by value, while special forms in _1_ and _2_ use delayed evaluation

1. Scheme ; 2. Lisp

Extended Backus-Naur Form

A text-based metalanguage for the definition of the syntax of a programming language

special form

An expression starting with a keyword

reference semantics

Behavior where variables actually store the address of an object in memory

Box and pointer notation

Black rectangle in the end box stands for the empty list ( )

type class inheritance

Many type classes themselves are defined to be part of other type classes

repeated inheritance

Multiple inheritance ordinarily creates separate copies of each class on an inheritance path -Example: object of class D has two copies of class A

design issues in object-oriented programming

Object-oriented features represent dynamic rather than static capabilities • Other issues for object-oriented languages are the proper organization of the runtime environment and the ability of a translator to discover optimizations • Design of the program itself is important to gain maximum advantage of an object-oriented language

Lambda abstraction

The essential construct of lambda calculus

functional application

a call to a defined function using actual parameters, or the values that the formal parameters assume for a particular computation

Application Framework

a collection of related software resources (usually in object-oriented form) for developer use -Examples: Microsoft Foundation Classes in C++ and Swing windowing toolkit in Java

Pure virtual declaration

a function declared with a 0 and the keyword virtual

currying

a process in which a function of multiple parameters is viewed as a higher-order function of a single parameter that returns a function of the remaining parameters

nonstrict

a property of a function in which delayed evaluation leads to a well-defined result, even though subexpressions or parameters may be undefined

parenthesized expression

a sequence of zero or more expressions separated by spaces and surrounded by parentheses

environment in Scheme

a symbol table that associates identifiers with values

free variable

a variable referenced within a function that is not also a formal parameter to that function and is not bound within a nested function

bound variable

a variable within a function that is also a formal parameter to that function

car

accesses the head of the list

cons

adds a new head to an existing list

destructors

are used to destruct instances of classes; no garbage collection in C++

garbage collection

automatic memory management technique to return memory used by functions

list

basic data structure in Scheme

Collections

containers whose elements are organized in a specific manner -Organization types include linear, sorted, hierarchical, graph, and unordered

instance definition

contains the actual working definitions for each of the required functions

define special form

creates a global binding of a variable visible in the top-level environment

Lisp

first language that contained many of the features of modern functional languages

pure function

function which has no side effects; only operate on their parameters

Higher-order functions

functions that take other functions as parameters and functions that return functions as values

Double-dispatch (or multi-dispatch) problem

inheritance and overloading do not account for binary (or n-ary) methods that may need overloading based on class membership in two or more parameters

Member functions with implementations in a class are assumed to be _

inline

Most functional languages were originally _ instead of _

interpreted; compiled

Lambda calculus

invented by Alonzo Church in the 1930s -A mathematical formalism for expressing computation by functions -Can be used as a model for purely functional programming languages

letrec

let but allows recursive functions

Atoms

like literal constants and identifiers of an imperative language

Lack of _ _ in functional programming makes it opposite of OO programming

local state

multimethods

more than one object can be the target of a method call

Functional programming (loops/no loops)

no loops

static binding

process of determining at compile time which implementation of a method to use by determining the object's actual class

Functional programming is useful for...

rapid prototyping, artificial intelligence, mathematical proof systems, and logic applications

Scheme relies on _ to perform loops and other repetitive operations

recursion

Name some functional methods

recursion, functional abstraction, and higher-order functions

cdr

returns the tail of the list (minus the head)

Member functions can be implemented outside the declaration by using the _

scope resolution name

value semantics

semantics in which names are associated only to values, not memory locations

map, filter, and reduce methods Java

static methods in Java

pure functional program

takes a strictly mathematical approach to variables

static scope

the area of a program in which a variable declaration is visible; lexical scope

metalinguistic power

the capacity to build, manipulate, and transform lists of symbols that are then evaluated as programs

backing store

the collection object on which the iterator object is operating

dynamic scope

the meaning depends on the runtime context

evaluation rule

the meaning of a Scheme expression

referential transparency

the property whereby a function's value depends only on the values of its variables (and nonlocal variables)

A referentially transparent function with no parameters must always return the same value (T/F)

true

Neither the if nor the cond special form obey the standard evaluation rule (T/F)

true

template classes

used to define generic collections in C++

functions are

viewed as values/general level objects

tail recursive

when the recursive steps are the last steps in any function

Java

• Originally intended as a programming language for systems embedded in appliances • Programs compile to machine-independent byte code • Provides conventional syntax, a large set of libraries, and support for compile-time type checking not available in Smalltalk

binding list

First expression in a let. let: binds a variable to a value within an expression.

delay special form

delays evaluation of its arguments and returns an object like a lambda "shell" or promise to evaluate its arguments

functional definition

describes how a value is to be computed using formal parameters

Scheme's semantics include _ or _ type checking

dynamic; latent


Conjuntos de estudio relacionados

The Nervous System: Spinal Nerves

View Set

child, older adult and intimate partner violence questions

View Set

Gross: Naso- & Oropharynx, Larynx II (BB_134)

View Set

Chapter 3 Quiz Organizational Behavior

View Set