CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
#cs450-news-2 (Discord)#cs450-2 (Discord)CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
| A | A- | B+ | B | B- | C+ | C | C- | D+ | D | D- | F |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 100..95 | 94..90 | 89..85 | 84..80 | 79..75 | 74..70 | 69..60 | 59..55 | 54..50 | 49..45 | 44..40 | 39..0 |
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
racket-lang.org#cs450-lounge-2 (invitation link in the GitLab page)hw1.rkt (invitation by email)Please, register using your UMB email address, otherwise you won't be able to submit your first homework.
The deadline of homework assignment n is last class of module n plus 1 week
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
I postponed this discussion, because I felt that you are now better suited to understand and relate to the points being made.
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
Is it because C is "close to the metal?" That is, is C fast because its semantics matches the processor's semantics?
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
Is it because C is "close to the metal?" That is, is C fast because its semantics matches the processor's semantics? No!
The facts above make C quite successful in High Performance Computing (large scale scientific codes).
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
Avoid running compute-bound parallel codes in Python. Maybe choose C?
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
We solve the equation
SEND+MORE=MONEYwhere each letter represents a digit in Prolog using a constraint language programming module:
sendmore(Digits) :- % Source: https://en.wikipedia.org/wiki/Constraint_programming
Digits = [S,E,N,D,M,O,R,E], % Create variables
Digits ins 0..9, % Associate domains to variables
S #\= 0, % Constraint: S must be different from 0
M #\= 0,
all_different(Digits), % all the elements must take different values
1000*S + 100*E + 10*N + D % Other constraints
+ 1000*M + 100*O + 10*R + E
#= 10000*M + 1000*O + 100*N + 10*E + Y,
label(Digits). % Start the search
Some problems are more amenable to certain programming languages.
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
Learn at least one new language every year.
Source: The Pragmatic Programmer. Andrew Hunt and David Thomas. 1999.
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
immutable.js for JavaScript by Facebookvavr, PCollections, the Scala runtime, and the Clojure runtime for Javaimmer for C++CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
Most programming language features started out in functional programming languages.
lambda expressions in C++, C#, Java, Python) introduced in LISP (1959) and in ISWIM (1966)auto in C++, var in C# (Hindley-Milner-Damas)CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
Many new interesting programming languages
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
on designing programming language features
We will focus mainly on functional and object-oriented programming.
on semi-formal specification
We will drive our course with precise mathematical notations and tests.
on programming patterns
We will characterize patterns and study abstractions of these patterns.
on purely functional programming
We will approach programming without using assignment (mutation).
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
We introduce one language feature at a time
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
In this class, we focus on the semantics of programming languages. We define the semantics of some programming language features.
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
In Racket, everything evaluates down to or is a value. A Racket program consists of a preamble followed by zero or more expressions:
program = #lang racket expression*
For space-constraint reasons, code listings might omit the preamble.
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
expression = value | $\cdots$
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
All numbers are complex numbers. Some of them are real numbers, and all of the real numbers that can be represented are also rational numbers, except for
+inf.0(positive infinity),+inf.f(single-precision variant),-inf.0(negative infinity),-inf.f(single-precision variant),+nan.0(not-a-number), and+nan.f(single-precision variant). Among the rational numbers, some are integers, because round applied to the number produces the same number.
Source: Racket Manual, Section 4.2
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
#lang racket
10 ; A positive number
+10 ; The plus sign is optional
-10 ; A negative number
0+1i ; A complex number
1/3 ; A rational number
0.33 ; A floating-point number
$ racket nums.rkt
10
10
-10
0+1i
1/3
0.33
Note: a semi-colon (
;) initiates a comment section, which is ignored in Racket. A semi-colon is not an end-of-line marker, like in C-like languages.
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
These two programs are equal:
#lang racket
10
+10
-10
0+1i
1/3
0.33
#lang racket
10 +10 -10 0+1i 1/3 0.33
Caveats:
-1 is different than - 1 (notice the white space in between both characters). The former is the negative one, the latter is the expression - and the value 1. Similarly, 1/3 is a single rational number, whereas 1 / 3 are three expressions.
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
Delimited by parentheses and its constituents are separated by white-space characters. The first expression must evaluate to a function, the remaining expressions are the arguments. Each expression is evaluated to a value from left-to-right before applying the function.
expression = value | variable | function-call | $\cdots$
function-call = ( expression-func expression-arg* )
For instance, function call (expt 2 3), for exponentiation, returns 2 raised to the power of 3. Function sin computes the sine function of its sole argument.
#lang racket
(expt 2 3)
(sin (expt 2 3))
$ racket nums-func.rkt
8
0.9893582466233818
Note: Function calls can be compounded, as the parameters of a function are arguments too.
CS450 ☽ Course info, arithmetic in Racket, evaluation ☽ Lecture 1 ☽ Tiago Cogumbreiro
There is NO INFIX NOTATION for arithmetic operations (unlike most languages).
The usual arithmetic operations are all just variables: addition +, subtraction -, multiplication *, division /.
Example:
( * 3.14159 ( * 10 10))
| | | | | | |-> Number
| | | | | |-> Number
| | | | |-> Variable
| | | |-> Function call
| | |-> Number
| |-> Variable
|-> Function call
Note: In Racket parentheses represent function application. Contrasted with most C-like languages where parentheses in expressions are optional and only there to help the reader.