1a: BSL Expressions Evaluation Strings and Images Flashcards

1
Q

What is the benefit of using Beginning student language (BSL)?

A

BSL is small and simple. It allows us to spend more time on learning the design method (which is the real focus of the course). Second BSL forms the core of nearly every other language you will ever use, and will help you adopt what you learn here to other programming languages. No single language will ever be enough to learn because there are so many popular programming languages. It has 9 total evaluation rules that allow us to write programs of arbitrary (preferential) complexity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the learning goals of this module?

A

Learning Goals
Be able to write expressions that operate on primitive data including numbers, strings, images and booleans.
Be able to write constant and function definitions.
Be able to write out the step-by-step evaluation of simple expressions including function calls.
Be able to use the stepper to automatically step through the evaluation of an expression.
Be able to use the Dr Racket help desk to discover new primitives.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does Racket work?

A

( …)
We give it expressions: Open Parentheses, the name of a primitive operator like +, followed by any number of expressions that can also be values. You can also comment out using semicolons ;. (sqr 3) or (sqrt 16).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write the expression that gives the third side of a right angle triangle if the first two sides are 3 and 4.

A

(sqrt (+ (sqr 3) (sqr 4))

What is the problem: I need to square 3 square 4 add together and square root the whole thing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What makes a design process good and what are the three challenges of good programming?

A

GOOD DESIGN PROCESS: means having programs that are formed of nice pieces that fit together well, are well tested, and easy to modify.

(1) Figuring out exactly what we want the program to do.
(2) Managing complexity by breaking down the program into well-chosen smaller pieces.
(3) Make it easy to read and easy to modify.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which of the following are expressions as part of the operation?

A

Expressions are either a value or of the form ( …). So (+ 2 3) and 1 are epxressions. sqr and + are primitives but not expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What do we need to understand big programs, like 10 million lines of code written for the Chevy Volt?

A

To understand big programs we need to understand the detailed rules by which expressions get evaluated. We don’t always need to think in terms of those rules but do need o have them to fall back on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does Racket evaluate expressions to produce values? (+ 2 (* 3 4))

A

(1) All of the operands need to be reduced to values. The + is an operator, 2 & (* 3 4) are operands. (* 3 4) needs to be reduced to 12.
(2) Apply the primitive to the values.
Left to right, inside to outside intuition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a primitive call rule (call to a primitive)?

A

A call to a primitive (primitive call) is when a primitive operation follows the open parentheses. (+ 2 (* 3 4)).

In a primitive call the + is the operator and all of the expressions that follow the call are the operands. And inside the next expression which is a primitive call we have * as the operator and 3 & 4 as the operands.

Numbers are not the only primitives, strings and images. Calls to string and image primitives work the same way as calls to number primitives.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you number characters in a string? (substring “Caribou” 2 4). Zero based indexing.

A

123 is not the same as “123”. ri. (substring “012345” 2 4) gives us 23 (stop before 4). 0 is number 0,. (substring “Caribou” 0 3) gives me Car.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are somethings we can do with strings?

A

(1) We can put strings together (string-append “Ada” “ “ “Lovelace”) = Ada Lovelace (wrote the first program for computers in the 1840s)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What do we need to type to use image functions in Dr Racket?

A

(require 2htdp/image) = USE the image functions from the 2nd edition of the how to design programs book.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the function for a circle and rectangle? What is the above, beside, overlay primitives? (CONSTANTS)

A

(circle 10 “solid” “red”) (rectangle 30 60 “outline” “ blue”) (text “hello” 24 “orange”). (above (circle 10 “solid” “red”) (circle 20 “solid” “yellow”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly