Ch 16 - Structs and Functions Flashcards

1
Q

Think Julia

What are the two kinds of functions?

A

They demonstrate two kinds of functions: pure functions and modifiers. They also demonstrate a development plan I’ll call prototype and patch, which is a way of tackling a complex problem by starting with a simple prototype and incrementally dealing with the complications.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 6057-6059). Kindle Edition.

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

Think Julia

What is a: pure function

A

Here is a simple prototype of addtime:

function addtime( t1, t2)
….MyTime( t1. hour + t2. hour, t1. minute + t2. minute, t1. second + t2. second)
end

The function creates a new MyTime object, initializes its fields, and returns a reference to the new object. This is called a pure function because it does not modify any of the objects passed to it as arguments and it has no effect, like displaying a value or getting user input, other than returning a value.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 6059-6071). Kindle Edition.

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

Think Julia

What is a: modifier

A

Sometimes it is useful for a function to modify the objects it gets as parameters. In that case, the changes are visible to the caller. Functions that work this way are called modifiers.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 6106-6109). Kindle Edition.

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

Think Julia

What is a: invariant requirement

A

Requirements like these are called invariants because they should always be true. To put it a different way, if they are not true, something has gone wrong.

A condition that should never change during the execution of a program.

Ben Lauwens and Allen B. Downey. thinkjulia (Kindle Locations 6261-6263). Kindle Edition.

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