<div dir="ltr">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.<div>
<br></div><div>This is a simple module that I came up with:</div><div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">(module numberless racket</font></div><div><font face="courier new, monospace">  (provide (rename-out [no-nums #%datum]))</font></div>
<div><font face="courier new, monospace">  </font></div><div><font face="courier new, monospace">  ;; Raises a syntax error when a number literal is encountered.</font></div><div><font face="courier new, monospace">  ;; Note that the datum must be quoted to prevent infinite expansion.</font></div>
<div><font face="courier new, monospace">  (define-syntax (no-nums stx)</font></div><div><font face="courier new, monospace">    (syntax-case stx ()</font></div><div><font face="courier new, monospace">      ((_ . datum) #'(if (number? (quote datum)) (raise-syntax-error 'Sorry "number literals disallowed" (quote datum)) (quote datum))))))</font></div>
<div><div><br></div><div>I don't know if that's the right way to go about it, but it gets most of the job done.</div><div><br></div><div><font face="courier new, monospace">> 3</font></div><div><font face="courier new, monospace"><i>Sorry: number literals disallowed    </i>3</font></div>
<div><br></div><div>But it doesn't catch quoted number literals:</div><div><br></div><div><font face="courier new, monospace">> '3</font></div><div><font face="courier new, monospace">3</font></div><div><br></div>
<div>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 <font face="courier new, monospace">(read-accept-quasiquote #f)</font>, but I couldn't find anything about messing with the regular quote syntax.</div>
<div><br></div><div>Any suggestions? (Also, am I even approaching this correctly? That is, should I be doing something other than redefining <font face="courier new, monospace">#%datum</font>?)</div><div><br></div>-- <br>
<div dir="ltr"><i><font face="garamond, serif">SEE YOU SPACE COWBOY...</font></i></div>
</div></div></div>