On 2012-02-29 19:14:48 +0100, ROELOF WOBBEN wrote: > ;String -> String > ;This function takes out the first character of a given string with the > name s > ; given "roelof" expect "r" > ; given "example" expect "e" > (define (string_first s) > (if (eq? (string? s) true) > (string-ith* s 0 ) > "You have not entered a string")) > [Ed: reformatted] > > So I hope somone can give me feedback on my first attempt so i can learn > from it.
A couple of comments: * `string-first` (- instead of the _) is a more idiomatic naming * (eq? (string? s) true) is verbose. (string? s) already returns a boolean. * Generally, when writing programs using the design recipe you don't need to think of the error cases (e.g., when the contract is violated) like `s` not being a string. You may want to think of some edge cases though (how long can a string be?). Cheers, Asumu ____________________ Racket Users list: http://lists.racket-lang.org/users