Re: [racket] Is this a good design

2012-03-02 Thread Roelof Wobben
Op 2-3-2012 9:51, Danny Yoo schreef: > I did some study on that chapter but I cannnot make it work, > This is what I have so far : > > ;;String -> String > ;; Get the first character of a string (s) if there is one. error otherwise. > ;; given "" expected "a" > ;; given "" expected " > (d

Re: [racket] Is this a good design

2012-03-02 Thread Danny Yoo
> I did some study on that chapter but I cannnot make it work, > This is what I have so far : > > ;;String -> String > ;; Get the first character of a string (s) if there is one. error otherwise. > ;; given "" expected "a" > ;; given "" expected " > (define (first-string s) > (cond >[(eq?

Re: [racket] Is this a good design

2012-02-29 Thread David Van Horn
On 2/29/12 3:22 PM, Raoul Duke wrote: but *write it down*. How are we to know, as reader's of your contract and purpose statements, that we have to provide non-empty strings? er, can you make a new EmptyString type and use that in the contract part of the comment? What's a type? You can def

Re: [racket] Is this a good design

2012-02-29 Thread David Van Horn
On 2/29/12 3:17 PM, Roelof Wobben wrote: Oke, Wierd idea that input control is not neccesarly. I have tried C and C++ and they empasise to do input control. [But you were taking an inconsistent approach: you checked in the input was a string, but then assumed it was non-empty. If you're going

Re: [racket] Is this a good design

2012-02-29 Thread Raoul Duke
> but *write it down*.  How are we to know, as reader's of your contract and > purpose statements, that we have to provide non-empty strings? er, can you make a new EmptyString type and use that in the contract part of the comment? Racket Users list: http://lists.racket-l

Re: [racket] Is this a good design

2012-02-29 Thread Roelof Wobben
You ignored part of what Asumu said, which (to paraphrase) is that your program should live and die by its contract. When you write down: String -> String you're saying this program consumes a String and produces a String. If somebody applies your program to something that is *not* a stri

Re: [racket] Is this a good design

2012-02-29 Thread David Van Horn
On 2/29/12 2:42 PM, Roelof Wobben wrote: >> A couple of comments: >> >> * `string-first` (- instead of the _) is a more idiomatic naming Oke, changed that. >> * (eq? (string? s) true) is >> verbose. (string? s) already returns a boolean. I changed that , thanks for the tip. * Generally, w

Re: [racket] Is this a good design

2012-02-29 Thread Roelof Wobben
>> A couple of comments: >> >> * `string-first` (- instead of the _) is a more idiomatic naming Oke, changed that. >> * (eq? (string? s) true) is >> verbose. (string? s) already returns a boolean. I changed that , thanks for the tip. * Generally, when writing programs using the design recip

Re: [racket] Is this a good design

2012-02-29 Thread Asumu Takikawa
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) >

[racket] Is this a good design

2012-02-29 Thread ROELOF WOBBEN
Hello, I am now in the book How to design a programm second edition at the point I have to design functions.Now I wonder if I understand this part right so I have made this function. ;String -> String ;This function takes out the first character of a given string with the name s; given "roelof" exp