<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='color:#1F497D'>If anyones interested…<o:p></o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>When
loading a source, the function ##read-all-as-a-begin-expr-from-psettings is
called which reads the whole file using the reader as if it started with a 
'begin' form. <o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>Unlike
some common lisp parsers, it does not read a toplevel and then macroexpand it.
But you can evaluate a form during reading using the #. macro form (well, you <o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>have
to enable this. see below).<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>Unfortunately,
##read-all-as-a-being-expr-from-port (another function in the chain of calls) 
makes a copy of the ##current-readtable (the default readtable) <o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>and
then passes it around to other reader macros. So we cant just modify that.  <o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>In
_io.scm<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>(define-prim
(##read-all-as-a-begin-expr-from-port<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
port<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
readtable<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
wrap<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
unwrap<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
start-syntax<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
close-port?)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'> 
(##with-exception-catcher<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>  
(lambda (exc)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>    
(if close-port?<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>      
(##close-input-port port))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>    
(macro-raise exc))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>  
(lambda ()<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>    
(let ((rt<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>           
(##readtable-copy-shallow readtable)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>      
(macro-readtable-start-syntax-set! rt start-syntax)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>      
(let* ((re<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>              
(##make-readenv port rt wrap unwrap 'script))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
(head<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>              
(##cons (wrap re '##begin)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                      
'())) ;; tail will be replaced with expressions read<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>    
         (expr<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>              
(wrap re head))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
(first<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>              
(##read-datum-or-eof re))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
(script-line<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>              
(and (##eq? first (##script-marker))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                   
(##read-line port #\newline #f ##max-fixnum)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
(language-and-tail<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>              
(##extract-language-and-tail script-line)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>        
(if language-and-tail<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>          
(let ((language (##car language-and-tail)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>            
(##readtable-setup-for-language! rt language)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>        
(let* ((rest<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                
(if (##eof-object? first)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                  
'()<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                  
(##read-all re ##read-datum-or-eof)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>               
(port-name<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                
(##port-name port)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>          
(if close-port?<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>            
(##close-input-port port))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>          
(cond ((##eof-object? first)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                 
(##vector #f expr port-name))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                
((##eq? first (##script-marker))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                 
(##set-cdr! head rest)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                 
(##vector script-line expr port-name))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>               
 (else<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                 
(##set-cdr! head (##cons first rest))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>                 
(##vector #f expr port-name)))))))))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>----------------------------------------------------------------------<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>So.
Solutions to being able to redefine the reader table while the file is being
read. <o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>(1)
Redefine ##read-all-as-a-begin-expr-from-psettings to not make a copy of the
readtable. Probably  not a good idea.<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>(2)
Create a special reader syntax which imports the current readtable/environment
as a paramter into the special reader when one loads/compiles a file. <o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>I
like this one. So instead of doing #.(begin (func-1) (func-2)) you redefine #.
to behave the same way except (current-file-readtable) now references the
actual <o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>readtable/environment
being used.<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>Note
that you can change the current-readtable parameter value as shown below and
thus change the reader macro when loading non scripts (regular .scm files). I think
what<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>happens
if the file is declared to be a script is that first the default readtable is
passed in but is then copied and then modified to fit the appropriate language.<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>If
it is a regular scheme file, i don't think the default readtable is modified,
but i haven't looked into this.<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'> (parameterize<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'> 
((current-readtable <o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>   
(let ((readtab <o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>       
(readtable-keywords-allowed?-set (readtable-eval-allowed?-set
(current-readtable) #t) #f)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>     
(##readtable-char-class-set! readtab  ;;changing  reader macro as a
demonstration. look at _io.scm for more examples<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>      
#\; #\t (lambda (re c)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>            (display
c) (display "GOOFY!")<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>            (error
"IM NOT a comment!")))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>     
readtab)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'> 
(load "tar.scm")<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'> ;....save
the current-readtable which has been modified<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>tar.scm:<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>;'yodel<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>Output:<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'> ;GOOFY!***
ERROR IN ##load -- IM NOT a comment!<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>OK,
but what if we want to change the readtable in the actual file instead of
before loading it?<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>Well,
now all we have to figure out is, given a environment object and readtable, how
do we go about 'injecting' a parameter into the environment?<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>Well,
in _io.scm, heres the definition of the read-sharp-dot macro. And thats about
far as I went. I imagine youde have to find out how to pass a environment to
the #eval.<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>(define
(##read-sharp-dot re next start-pos)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'> 
(if (not (macro-readtable-eval-allowed? (macro-readenv-readtable re)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>   
(begin<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>     
(##raise-datum-parsing-exception 'invalid-token re)<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>  
   (##read-datum-or-label-or-none-or-dot re)) ;; skip error<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>   
(begin<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>     
(macro-read-next-char-or-eof re) ;; skip char after #\#<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>     
(let* ((expr<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>             
(##read-expr-from-port<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>              
(macro-readenv-port re)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>            
(val<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>       
      (##eval expr)))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>       
(macro-readenv-filepos-set! re start-pos) ;; set pos to start of datum<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'>       
(macro-readenv-wrap re val)))))<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-family:"Courier New"'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>

</div>

</body>

</html>