Вопрос

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'?

Это было полезно?

Решение

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))

Другие советы

I've just found someone who has already written all code snippets from the book The Seasoned Schemer in github.

And it is his answer: ( It is not non-hygienic and don't require other model)

(define-syntax letcc
  (syntax-rules ()
    ((letcc var body ...)
     (call-with-current-continuation
       (lambda (var)  body ... )))))


(define-syntax try 
  (syntax-rules () 
    ((try var a . b) 
     (letcc success 
       (letcc var (success a)) . b))))

The link is https://github.com/viswanathgs/The-Seasoned-Schemer

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top