Op 2-3-2012 10:37, Pierpaolo Bernardi schreef:
On Fri, Mar 2, 2012 at 09:41, Roelof Wobben<r.wob...@home.nl>  wrote:


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 "aaaa" expected "a"
;; given "" expected "
(define (first-string s)
  (cond
    [(eq? s "") (error "first-string" "Empty string found")]    ;; check for
a empty string.if so put a error message
    [(and (string? s) (not(eq? s "")))  (string-ith s 0)]              ;; if
it's a non-empty string then do the trick.
    [(number? s) (error "first-string" "No string found")]      ;; if it's a
number then put a error message
    [(boolean? s) (error "first-string" "No string found")]     ;; if it's a
boolean then put a error message
    [(image? s) (error "first string" "No string found")]         ;; if it's
a image put a error message
    ))

But when I do (first-string ") then still DrRacket gives his own error
message instead of the one I made.
Any tips are welcome here.
The immediate problem is that eq? is not the right predicate for
checking for empty strings.  Use string=? or string-length.

Once fixed this, what happens if you call (first-string '(a b c)) ?

P.


Thanks ,
This works in Windows well.
When I do (first-string ' ( a b c)) I see this error message : quote: expected the name of the symbol after the quote, but found a part

I see I made a error. With String -> String I only have to check for empty strings so i can delete the (string?s) (boolean?s) (image?s) ('number?s) parts.

Roelof



____________________
 Racket Users list:
 http://lists.racket-lang.org/users

Reply via email to