[racket] I just can't understand readtables

From: Tomás Coiro (tomcoiro at hotmail.com)
Date: Mon Apr 29 16:12:04 EDT 2013

Thanks for that Danny :)
I'll try to do that.

Although I think that readtables documentations aren't understandable.
I mean, searching on Google I can find 3 or 4 questions about them and no one seems to understand them.

> From: dyoo at hashcollision.org
> Date: Mon, 29 Apr 2013 12:44:54 -0600
> Subject: Re: [racket] I just can't understand readtables
> To: tomcoiro at hotmail.com
> CC: users at racket-lang.org
> 
> Hi Tomas,
> 
> For this particular case, you might not even need to use readtables.
> Since you're already dealing with making your own Clojure-style
> language, you might be able to override the literal datum macro,
> #%datum, to rewrite uses of byte strings to regexps.
> 
> Here's what this might look like:
> 
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> #lang racket/base
> 
> (module my-custom-language racket/base
>   ;; Example of overriding #%datum:
>   (provide (except-out (all-from-out racket/base)
>                        #%datum)
>            (rename-out (#%my-datum #%datum)))
> 
>   (require (for-syntax racket/base))
> 
>   ;; Here is our substitute definition for processing raw datums in
>   ;; our language:
>   (define-syntax (#%my-datum stx)
>     (syntax-case stx ()
>       [(_ . bstring)
>        (bytes? (syntax-e #'bstring))
>        ;; If we see a raw byte string, translate it to a use of
>        ;; a regexp.
>        (with-syntax ([an-str (bytes->string/utf-8 (syntax-e #'bstring))])
>          (syntax/loc stx
>            (regexp an-str)))]
>       [(_ . other)
>        ;; Otherwise, delegate to the original definition of #%datum:
>        (syntax/loc stx
>          (#%datum . other))])))
> 
> 
> ;; Here is an example use of that custom language:
> (module test (submod ".." my-custom-language)
>   (define r #"hello world, this should be a regexp")
>   (printf "~v\n" r)
>   (regexp? r))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130429/f97b42e3/attachment.html>

Posted on the users mailing list.