[racket] Completely disallow numbers, quoted and all

From: Daniel Brady (dabrady at umail.iu.edu)
Date: Wed Jun 4 00:38:11 EDT 2014

So I'm playing around with the DrRacket reader, and I'm decided to see if I
could disallow certain types of literal data. I figured I'd start with
numbers, and maybe see if I can come up with a tiny numberless language
like pure lambda calculus.

This is a simple module that I came up with:

(module numberless racket
  (provide (rename-out [no-nums #%datum]))

  ;; Raises a syntax error when a number literal is encountered.
  ;; Note that the datum must be quoted to prevent infinite expansion.
  (define-syntax (no-nums stx)
    (syntax-case stx ()
      ((_ . datum) #'(if (number? (quote datum)) (raise-syntax-error 'Sorry
"number literals disallowed" (quote datum)) (quote datum))))))

I don't know if that's the right way to go about it, but it gets most of
the job done.

> 3
*Sorry: number literals disallowed    *3

But it doesn't catch quoted number literals:

> '3

I don't know what part the reader deals with quoted values. I looked at
Reading Quotes, and figured out how to disallow the quasiquoting syntax
with (read-accept-quasiquote #f), but I couldn't find anything about
messing with the regular quote syntax.

Any suggestions? (Also, am I even approaching this correctly? That is,
should I be doing something other than redefining #%datum?)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140604/9a01117a/attachment-0001.html>

Posted on the users mailing list.