PowerPoint Presentation
CS 345: Programming Language Paradigms
Today
Paradigms
What is functional programming?
Contrast: Imperative programming
Intro to functional programming in Racket
Expressions and expression evaluation
Defining simple functions
Heads up: Participation Quiz
Paradigm, in the context of programming languages:
A pattern that serves as a school of thought for programming of computers
A programming technique
All the ways a language supports this technique
An ideal. (Sometimes, programming purely in one paradigm is not as practical as mixing approaches)
Imperative Code Sample
Imperative Paradigm
Imperative programming is programming by means of changing state.
State means all the parts of a program that can change over the course of the programs execution because they are assigned and re-assigned new values.
Formal Definition
Imperative languages are characterized as having state that is modified (mutated or side-effected) by commands in the source language.As a result, such languages generally have a notion of sequencing of commands to permit precise and deterministic control over the state.The assignment of state is a very common command, since its effect is to alter the underlying store.
Functional Programming
Whats the difference between an expression and a statement?
x + 7
x = x + 7;
Expression
7
x + 7
x * (y + 8)
myfunc(a)
A simple object, like a number or a named variable, or, an operator or a pure function applied to an argument or arguments
Always returns a new value
We say an expression is evaluated
Statement
X = 7
x = x + 7
print Hello world
if x < 7 { x = 10 }A command that carries out an actionA unit of execution that doesnt return anything, rather only has a side-effect (has an observable interaction on the programs state)We say a statement is executedFunctional vs ImperativePure functional programming is programming exclusively with expressionsImperative programming is programming with statements (which often include expressions)LispSchemeRacketLispInvented by John McCarthy (1927-2011) in 1958.Used by artificial intelligence researchers.Second oldest programming language.Functional programming paradigm.Simple syntax and semanticsEasy to parse and interpretEasy to learn (although very deep)SchemeDialect of LispElegantSyntaxSmallnessInvented by Jerry Sussman and Guy Steele in 1975Racket/docProps/thumbnail.jpeg
Reviews
There are no reviews yet.