Create ten questions and answers on topics we have explored in the
past week (e.g., procedures, including lambda, composition, and sectioning; basic types, including numbers, strings, and lists.).
Title your email CSC 151.01 Flashcards for week 3 (YOUR NAME).
Include your questions and answers in the body of the email.
Submitted questions
Here you can find some of the questions and answers that have been
submitted so far (at least those that Sam had time to add).
Big-picture questions
What are the seven basic parts of an algorithm?
Built-in values and operations, sequencing, variables, subroutines, conditionals, repetition, and input/output.
What is subroutine?
It is also referred as procedure, an algorithm made to avoid repeating the same instructions over and over again, like the procedure robust-average, instead of writing add all the numbers, then delete the max and min, then so on.
What are the five questions to ask when encountering a data type?
1. What is the type’s name? 2. What is the purpose of the type? 3. How do you express values of the type? 4. How does the computer display values of the type? 5. What operations are available for values in the type?
What acronym do we use for those questions?
NPEDO (well, some students seem to use it)
What is the visual difference between a string, name, symbol, and expression?
To use the letter “a” as an example, to to express a as a string, you would place it in quotes, "a", to express it as a name, it would be just the character, a, to express it as a symbol, you would place a tick before the character, 'a, and to put it as an expression, it would be formatted as #.
What are the 6 Ps? (Don’t list them; describe their purpose.)
A way to document procedures.
Numbers
What are six different types of numbers in DrRacket?
The six different types are exact integers, inexact integers, exact real/rational numbers, inexact real/rational numbers, exact complex numbers and inexact complex numbers.
What is (remainder-11-4)?
-3; the sign of remainder is the same of dividend
What does truncate do?
Throws away the fractional part for a decimal number.
What does round do?
Rounds to the nearest integer.
What do ceiling and floor do?
Round up and round down, respectively.
What do we expect from (remainder-78)?
-7
What is the difference between an exact number and an inexact number?
An exact number is the true, exact value of the number, while an inexact number is just an approximation.
What are ways to describe numbers and consider when working with them in DrRacket?
To start, there are integers, which are most common. From there, it is rational then real numbers. Furthermore, complex numbers can be used in DrRacket. Also, DrRacket has approximate (also known as inexact, which have decimals) and exact numbers.
What is an example of how to add two numbers in Scheme?
(+56)
What does (/245) produce?
1/10
What kind of number is 2.33333?
Inexact real
What kind of number is 3.0?
Inexact integer
What kind of number is 4/5?
Exact rational (or exact real)
What does expt do?
Expt finds allows you to use exponents for example (expt23) is 8.
What does the procedure remainder do?
When taking the quotient of two numbers, i.e., (quotient52), the computer outputs a number that represents how many times the second number can go into the first evenly. The remainder procedure displays the remainder, so in the case above, (remainder52) would be one, but in a case like (remainder78), the remainder would be 7, since the quotient would be 0.
What is the difference between an exact and inexact number?
An output number is exact if it is expressed as an integer or ratio, and inexact if it is expressed in terms of decimals. The result of an operation will be inexact if any of the input numbers are inexact, including if the base or exponent is inexact. If all inputs are exact but an exact result cannot be calculated, the output will also be inexact, as in the square root of 2, (expt21/2).
When using quotient and remainder, what must you remember about signs?
Remainder should have same sign as dividend.
What is the result of (expt24)?
16
Will this result in an exact or inexact value? (*(sqrt2)(sqrt2))
Inexact
What is the result of (quotient92)?
4
What is the result of (remainder92)?
1
How can I find the largest value of 1 2 3 4 5 6 7 8?
(max12345678)
What is the result of (denominator45/46)?
46
What is the result of (expt2"4")?
Error. The exponent must be a number.
Do max and min work with all numbers?
No. They do not work with complex number, such as (max2/743+5i).
What procedures are there to extract “parts” of numbers?
What numbers appear in the one parameter version of (range10)?
'(0123456789)
Image Making
How can you create a solid red square of size 50?
(square50'outline"red")
What belongs in the Definitions pane before you can make images?
(require2htdp/image)
How do you denote the color blue?
'blue
What do beside, above, and overlay do for combining images?
beside puts images next each other, lining up at the vertical centers. For above, images are placed one on top of another, using the horizontal centers. overlay puts an image on top of another, and done by lining them up at the centers.
What does a call to rectangle look like?
(rectanglewidthheight'mode"color")
How do I create a pen for drawing?
(pencolorwidthstylecapjoin)
How do I define my own color, given the red, green, and blue components?
(make-colorREDGREENBLUE)
How do I overlay two images, with an offset?
(overlay/offseti1xoffyoffi2)
Procedures
Describe the structure of a procedure created using lambda.
(defineproc(lambda(params)body)
What does section from the loudhum library do?
It creates a procedure in a more legible, concise way by substituting <> in for the input value.
What symbol represents function composition?
o
What exactly is lambda?
It is a keyword that is used to name a procedure (much like define, which names a value instead)
What are the three main aspects of a procedure? (Not the documentation.)
The name, parameters (or inputs) and the instructions
What are the six P’s we suse to document procedures?
Procedure, Parameters, purpose, produces, preconditions, and postconditions
What is composition?
Composition is a function that is represented by o. In math, the function is represented by (f∘g)(x) = f(g(x)). From there, it is processed from right to left.
What are the three ways to write a procedure?
With lambda, composition (o), and section
How do I write subtract2 with lambda?
(definesubtract2(lambda(x)(-x2))
How do I write subtract2 with o?
(definesubtract-2(osubtract-1subtract-1)
How do I write subtract2 with section?
(definesubtract-2(section-<>2))
Can you have multiple inputs in a single procedure?
Yes. For example, (lambda(xy)...).
If you compose two different procedures, in what order are they applied? For example, for (definef1(osquareadd1)), is the square procedure or the add1 procedure applied first?
The composed procedures are applied from right to left. In this example, first the add1 procedure is applied, then the square procedure.
How can you use procedure sectioning to re-write (define half (/ ? 2)) with a syntax that DrRacket can process?
(definehalf(section/<>2). For the procedure half, the parameter provided takes the place of the diamond in (section/<>2).
Strings
How do you denotate a string?
With quotation marks. For example, "string"
What does string-append do?
Merges two or more strings together into one
What is the null string?
This refers to a zero character string, "". Note: Information taken from “Characters and Strings”
For the (substringstrstartend) procedure, what do start and end represent?
start is the index of the first character you want, end is one after the last character you want. We count starting at 0.
What does string->list do?
Converts a string into a list of its constituent characters.
What does list->string do?
Converts a list of characters into a string?
What is (list->string'("alpha""beta""gamma"))?
An error. list->string only works with lists of characters.
What is the role of backslash (\) character in a string?
It is an escape character that indicates something special about the next character. \\n is a newline. \\t is a tab. \\\\ is a backslash.
What is the result of (string-append"L""O""L")?
“LOL”
How do we use the string procedure?
(stringchar0char1char2...) combines characters into a string.
How would you turn a sentence (one string) into a list of words (punctuation may be attached to some words)?
(string-splitstr)
What is the result of (substring"Hello"14)?
ello
What is the result of (string-ref“Hello”0)?
#\H
What is the value of (string-length"a\\b")?
3
What is the value of (string-length"a\nb\n")?
4
Lists
What is a list?
A list is a collection of values that you can process one-by-one or en masse.
What are some important list operations?
take, drop, list-ref, length
What do the take and drop operations do to a list?
They create a new list by keeping or discarding the first n elements of the given list.
Suppose we have defined fruits with (definefruits(list"apple""orange""banana""pear")). What is (takefruits2)?
'("apple""orange")
For the same definition, what is (dropfruits3)?
'("pear")
In Racket, what position (number) is the initial element in a list in?
0
What should we get from (list-ref'(abc)3)?
An error.
What should we get from (list-ref'(abc)1)?
'b
Is there a limit to how long a list can be in Scheme?
Not that we’ve found.
How do you join two lists together?
(appendlist1list2)
What is the result of (make-list5'LOL)?
'(LOLLOLLOLLOLLOL)
How would you extract the last n items of a list in order using the drop procedure?
(droplst(-(lengthlst)n))
How can you generate the list of integers from a to b?
(rangeab)
What’s an easy way to make lists of identical values?
(make-listnval) can be used, which will take the value that is entered and repeat it as many times as specified for n.
Characters
How do I express the letter a?
#\a
More generally, how are characters written?
Characters are distinguished from other things like strings or symbols by writing #\ before the character.
How are characters organized?
Each character has a collating sequence number (this can be found by applying char->integer and vice versa by integer->char).
How do I ignore case when comparing two letters?
(char-ci<?letter1letter2)
What is the difference between char<? and char-ci<??
char-ci<? is case insensitive, meaning that it treats uppercase and lowercase versions of the same letter as equivalent. char<?, on the other hand, does not.
What is the difference between Unicode and ASCII?
Unicode is more recently devised and supports many more characters than ASCII, from many languages. ASCII does not provide many characters outside the English language.
Symbols
What is a symbol in Scheme?
A symbol is an atomic value, typically a word, that denotes only itself. It is faster to compare symbols than it is to compare strings.
What is the purpose of symbols?
Symbols are quicker to compare with than strings are (Additional information – the tick mark that is used with symbols in necessary as Scheme will see it as an identifier otherwise).
Miscellaneous
What is mapping?
The process of doing something to each element in a greater collection of values (string, list, etc.)
What is the procedure to write text to a file?
The command (string->filestrfname) is used (also this will overwrite files that exist already, given the same name).
What happens when you click “Run” in DrRacket?
The interactions pane is cleared, and any changes to the definitions pane go into effect. Note: Information taken from “The DrRacket Programming Environment.”
How is a list differentiable from a procedure?
Although both appear between parentheses, whereas a procedure will include a procedure name then an input, without quotes around the procedure name, ie (sqrt2), a list will have a tick mark before the parentheses, and the interior information will often consist of either a series of words in quotes or numbers separated by spaces, ie '("Twas""Brillig").
Do XML files require a CSS?
No
How do you add a comment in the definitions pane?
Use a semicolon to introduce the comment
Why is indentation important?
Indentation helps us resolve nesting.
How do I get the previous command I typed in the interactions pane?
Ctrl-up-arrow or escape-p
What is the keyboard shortcut for “Run”?
Ctrl-R
What is the result of quoting a number (e.g., (quote29))?
DrRacket returns a number (e.g., (quote29) -> 29).
What are the whitespace characters?
Space, tabs, line feed, form feed, carriage return, and newline.
How are parentheses interpreted in Racket?
Parentheses are used for lists and for compound expressions in which we apply a procedure to values.
What happens if you put parentheses around a named value, such as (pi) or (3)?
DrRacket will issue an error. An open parenthesis usually signifies a procedure call.
How can a document use functions from another document?
The original document must include (provide(all-defined-out)) and the second document can retrieve those functions with (requirelocation/filename).
What is the usual file extension of Racket files?
.rkt
Is "a" a character?
No. It’s a one-character string, not a character.
What are the differences between (+23) and '(+23)?
(+23) indicates that the computer should add the numbers 2 and 3. '(+23) is a list with three values, the symbol + and the numbers 2 and 3. (This answer is from the article List Basic).
What does Sam believe the most important thing we have learned so far?
We are wonderful people and should take care of ourselves.