CS135

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/38

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

39 Terms

1
New cards

What is Computation?

Have instructions that the computer has to complete

2
New cards

Imperative Design

Based on frequent changes to data

e.x, Java, C++, Python

3
New cards

Functional Design

Computation of new vales rather than the transformation of old ones

e.x, Excel formula, XSLT, LISP

4
New cards

Syntax

How things are supposed to be said

e.x, “?is This Sentence syntactically correct”

5
New cards

Semantics

What the actual meaning is

e.x, “Trombones fly hungrily”

6
New cards

Ambiguity

Valid programs have exactly one meaning

e.x, “Sally was given a book by Joce”

7
New cards

Values

Numbers or mathematical objects (5, 4/9, pi)

8
New cards

Expression

Combine values with operators and functions

E.x, (5+2)

9
New cards

Functions

Generalize similar expressions

E.x, f(x)= x²+4x+2

10
New cards

Different components of a function

  1. Name of function (g)

  2. Parameters (x y)

  3. Algebraic expression using parameters

11
New cards

Arguments

Supplies arguments for parameters

12
New cards

Infix

(+, -, et.c)

E.x, 3-2 = (- 3 2)

(6-4) / (5+7) = / ((- 6 4) (+ 5 7))

13
New cards

Yield Symbol

Each step is indicated using “Yield Symbol”

14
New cards

Ellipses

Use ellipses to show a pattern

(f v1 v2 v3) = V

15
New cards

Defining Functions

“Binds name to body”

(define(g x y) (+ x y))

16
New cards

Syntax Error

Reading an expression

17
New cards

Run-Time error

Evaluating an expression

25/0 cannot work

18
New cards

Substitution Rule

19
New cards

Identifiers

Functions named by identifiers (e.x, x-ray)

20
New cards

Observations

Parameter order matters

(define (g x y) (- x y)

DOES NOT =

(define (g y x) (- x y)

21
New cards

Constants

k=3, p=k²

(define k 3)

(define p (sqr k)) = ‘p’ gets bound to the new value

  • Are used in any expression (body of a function)

  • Don’t repeat a definition once its expression has been reduced to a value

22
New cards

Comments

;

;; Comments which use whole line

(+ 6 7) ; Comment after code (use one semi-colon

23
New cards

Block Comments

#|

(define (function-to-temporarily-remove x y)

(+ x y))

|#

24
New cards

Helper Function

Help implement another function

  • Helper used to define constants must be defined before

    - (define c (distance 1 1 3 9))

25
New cards

Check-expert

Form that we use to test function

(check-expert expr-test expr-expected)

  • expr-test = function application we are testing

  • expr-expected = expected result “correct answer”

26
New cards

Scope

Global & Function

  • The Scope of an identifier is where it has effect (in program)

    1. Smallest enclosing scope has priority

    2. Duplicate identifiers within the same scope will cause an error

(define f 3)

(define (fx)(sqr x))

*ERROR - WAS ALREADY DEFINED

27
New cards

Booleans

(< x 5)

T or F value

<, >, >=, <=, = [each produces a value]

  • Abbreviated Bool

28
New cards

Predicates

Function that produces a bool is a ‘predicate’

  • Usually has a ‘?’ at the end

  • (can-vote? age)

29
New cards

Combining Predicates

and, or, not all consume and produce Bool values

30
New cards

Substitution Rules (and)

(and false …) = false

(and true) = (and …)

(and) = true

31
New cards

Substitution Rules (or)

(or true …) = true

(or false …) = (or …)

(or) = false

32
New cards

Conditional expressions

Expressions should take one value under certain conditions (cond)

  • Question is Boolean

  • Answer is a possible value of the conditional expression

33
New cards

Short-Circuit Evaluation

Evaluates as many arguments of (and) & (or) that is necessary to find final result

34
New cards

else

If none of the conditions were satisfied, then we do something else

35
New cards

Nested Conditions

Nests one conditional expression inside another

36
New cards

Flattening Nested Conditions

Flats the condition to make it easier to read than nested

  • No cond with another cond inside (see notes for example)

[else (cond… *THIS HAS TO BE FLATTEND

37
New cards

Bounding Conditions

  • Cut off between passing and failing

38
New cards
<p>Intervals for testing </p>

Intervals for testing

39
New cards
<p>RULES OF SUBSITIUTION  </p>

RULES OF SUBSITIUTION