When I was doing Exercise 9.2.2, which requires developing a
function named repeat that takes in a string and returns that string appended
to itself,
I wrote like that:
(check-expect repeat “hello” (string-append
“hello””hello”))
(define repeat (string-append “hello””hello”))
Then, I found
that this new defined function could only be applied to the string “hello”,
which was different than what I expected. So, I went to office hour, and asked
professor this question. Then I know that I lacked a place-holder, which has a technical name- parameter. So the
correct expressions should be:
(check-expect(repeat
“hello”)(string-append “hello””hello”)
(define (repeat
string)(string-append string string))
Then, I tried
a different string in Interactions Plane:
>(repeat “lol”)
“lollol”
The result shows that the new defined function- repeat- now
works for any string.
No comments:
Post a Comment