Anki-Import

 view release on metacpan or  search on metacpan

t/data/cs61.anki  view on Meta::CPAN

```
(define pi 3.14)
(* pi 5 5)
```

The first line sets the value of `pi` to 3.14. The second line multiplies `pi`
by 25 (5 * 5).

`


#csnip
```
(define (square x)
    (* x x)
(square (+ 2 3))
```

It defines a function called `square` that takes a single argument called `x`.
The body of the function takes `x` and multiplies it by itself. The third line
calls the `square` function with result of the express `2 + 3` (or 5), which
returns an answer of 25 (5 squared).

`


#basic
Why is the `define` function considered an exception to the way scheme normally
processes arguments?

Because it does not evaluate the arguments that are passed to it.

`


#basic
Describe what we mean when we say a function is a *special form* function?

It is a function that does not process arguments the way other scheme functions
do. The `define` function is an example.

`


#cquest
What does the following code evaluate to and why?

```
(define hello (+ 2 3))
hello
```

The first line evaluates the word "hello," the function that was defined. It
does not evaluate to "5" because `define` does not evaluate its arguments. The
second line evaluates to 5, the result of the expression, 2 + 3.

`


#cquest
What is the code in bold referred to as?

```
(define (square <b>x</b>)
    (* x x)
(square (+ 2 3))
```

the formal parameter, the argument that is passed to the function

`



#cquest
What is the code in bold referred to as?

```
(define (square x)
    <b>(* x x)</b>
(square (+ 2 3))
```

the body

`



#cquest
What is the code in bold referred to as?

```
(define (square x)
    <b>(* x x)</b>
(square <b>(+ 2 3)</b>)
```

the argument expression

`


#cquest
What is the name for the result of the argument expression, `(+ 2 3) passed to
the function called?

```
(define (square x)
    (* x x)
(square (+ 2 3))
```

the actual argument value

`


#cquest
What is a predicate function?

```
Example: `(if (equal? (last 'y) 'y)`
```

It is a function that returns true or false and is denoted with a "?" at the
end.

`


#csnip
```
(define (plural wd)
    (if (equal? (last wd) 'y)
        (word (bl wd) 'ies)
	(word wd 's)))
(plural book)
(plural fly)
(plural boys)
```

Line 1 defines a function called `plural` that has one formal parameter called
`wd`.
`
Line 2 tests to see if `wd` ends in "y". If it does, line 3 will replace the
"y" with "ies," otherwise, line 4 will add an "s" to the word.
`
Lines 5-7 evaluate to the pluralized versions of the words. However, there is a
bug and with line 7, resulting in "boies." As an exercise, the bug should be
fixed.



( run in 0.493 second using v1.01-cache-2.11-cpan-d8267643d1d )