== Quick Intro ==
- Why learn other languages?
- Defer to reading:
paradigms, and an example lang of each.
functional
procedural
O.O.
scripting
declarative
== some terms to be careful with ==
- value : a valid answer to a question. can be returned, passed ("a piece of information represented")
- expression : [syntax] code that evaluates to a value (hence the word "evaluate")
Every value is trivially an expression (in most languages; but not e.g. SQL tables, grrr).
- variable : an associating between a name (identifier) and a value.
The association can change(vary) over time.
- type : a set of values (er, a name for that set).
*Both* variables and values have associated types.
And while we're at it:
- statement : [syntax] code that, when executed, *does* something -- changes the state (define a variable, ...)
== racket intro ==
sqrt(25) (sqrt 25)
2^30 (expt 2 30)
2+3 (+ 2 3)
2+3*4 (+ 2 (* 3 4))
2 + (3 * 4 + 5) * 6 (+ 2 (* (+ (* 3 4) 5) 6))
2 + 3 + 4 + 5 (+ 2 3 4 5)
2
Trade-offs, of prefix vs infix?
(You can construct these top-down, or bottom up;
when evaluating / figuring out what some epxression returns,
work bottom-up, a.k.a. from the innermost-parens outward)
Note that
sqrt : number -> number
expt : number, number -> number
+ : number, number -> number
sqrt(max(5,7)) + 2 (+ (sqrt (max 5 7)) 2)
Some string-handling functions:
string-append : string, string -> string
substring : string, number, number -> string
string=? : string, string -> boolean
A note on numbers:
(sqrt 2) -- inexact
Cf. (both Java and racket:)
(/ 2 300)
(* (/ 7 25) 25)
(sqrt -4)
Inexacts, in Java:
*must* be 32-bit arithmetic; if you do 'better' you're not Java.
(if your 2billion + 2billion = 4billion in Java, it's not Java.)
Portability considered more important than incrementally increasing accuracy.
I. define
(define a 2)
(define b 8)
(define c 42)
; quadratic expression
II. define a function
(define (root1 a b c)
...)
III. practice: string functions
blend : string, string -> string
IIIa: expected results
IIIb: write
IIIc: expected results w/ 'string=?'; expected results w/ check-expect