schemeracketseasoned-schemer

Is there any function like 'try' in Racket


Now I'm leaning schemer by looking the book The Seasoned Schemer. I writed the code by racket, however when I using the try, the schemer didn't have this method or macro. And It reported expand: unbound identifier in module in: try. The code as the below: (in the page 89)

(define (remove-member-first* a lat)
   (try oh (rm a lat oh) lat))

I've search the racket documents, but didn't find smiliar function.

So who does know whether there are kinda function like the 'try'?


Solution

  • You don't mention it, but I'm guessing that the book you're talking about is "The Seasoned Schemer". Use the following macro definitions for implementing try as defined in the book:

    (require mzlib/defmacro)
    
    (define-macro (letcc c . body)
      `(call/cc (lambda (,c) ,@body)))
    
    (define-macro (try x a b)
      `(letcc *success*
         (letcc ,x
           (*success* ,a))
         ,b))