Is there a feature like "try" in Racket

Now I am inclined to intrigue, looking at the book The Seasoned Schemer . I typed the code using racket, however, when I use try , the circuit did not have this method or macro. And the extension was reported: unbound identifier in the module in: try. Code as shown below: (on page 89)

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

I searched for documents with a racket, but did not find a familiar function.

So who knows if there is some kind of function like "try"?

+6
source share
2 answers

You have not mentioned this, but I assume that the book you are talking about is The Seasoned Schemer. Use the following macro definitions to implement try , as defined in the book:

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

I just found someone who already wrote all the code snippets from The Seasoned Schemer on github.

And this is his answer: (He is not unhygienic and does not require another 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)))) 

Link https://github.com/viswanathgs/The-Seasoned-Schemer

+13
source

Source: https://habr.com/ru/post/922009/


All Articles