<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jul 10, 2014, at 6:40 AM, Matthew Flatt <<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">The readtable strategy works when <language> itself uses a<br>readtable-based reader. The idea is that you install a mapping for `#λ`</blockquote><blockquote type="cite">while leaving all the other mappings in place. If <language> uses a<br>readtable-based reader, then it picks up your extension, otherwise it<br>doesn't.<br><br>I think a `#lang afl at-exp racket` combination should work fine: `afl`<br>installs a handler for `#λ`, `at-exp` installs a handler for `@`, and<br>`racket` uses `read-syntax` to see both extensions.<br></blockquote><div><br></div><div>Well for some reason it doesn’t:</div><div><div>#lang afl at-exp racket/base</div><div>(map #λ(+ % 1) '(1 2 3)) ; read: bad syntax `#λ’</div><div><br></div><div>But also for some reason this does:</div><div>#lang at-exp afl racket/base</div><div><div>(map #λ(+ % 1) '(1 2 3)) ; '(2 3 4)</div><div>(map #λ@+[% 1] ‘(1 2 3)) ; ‘(2 3 4)</div><div>By the way I only just got this to work yesterday by doing basically this but for afl:</div><div><a href="https://github.com/AlexKnauth/rackjure/commit/5fa266e672d529dde227ef216aaef157fa5c618c">https://github.com/AlexKnauth/rackjure/commit/5fa266e672d529dde227ef216aaef157fa5c618c</a></div><div><br></div><div>Also is there any way to get something like this to work?:</div><div>#lang afl at-exp racket/base</div><div>@#λ(+ % 1)[1] ; read: bad syntax `#λ'</div></div></div><br><blockquote type="cite">Adding `#fn` support is a little trickier if you want to fall back to<br>`#f` or `#false` when the character after `#f` (as determined by a<br>peek) is not `n`. For that case, the readtable addition for `#f` should<br>remember the old readtable, and then when it needs to fall back, it<br>calls `read/recursive` with the saved readtable as the third argument.<br>That way, immediate parsing of `#f...` uses the saved readtable without<br>`afl` extensions, while parsing of sub-expressions will return to the<br>current readtable that includes the `afl` extensions.<br></blockquote><div><br></div><div>Do you mean like this?:</div><div>(define lambda-readtable (current-readtable))</div><div>(parameterize ([current-readtable orig-readtable])</div><div> (read-syntax/recursive src in #f lambda-readtable))</div><br><blockquote type="cite">Documentation for the functions from a "<language>/lang/reader.rkt" is<br>in section 1.3.18 of the Reference, which defines `#lang` (as being<br>"like `#reader`, which is described in the same section).<br></blockquote><div><br></div><div>Ok I just found this in section 1.3.18:</div><div><span style="font-family: Charter, serif; line-height: 24px; background-color: rgb(255, 255, 255);">The arity of the resulting procedure determines whether it accepts extra source-location information: a </span><span class="RktSym" style="margin: 0px; padding: 0px; font-family: 'Source Code Pro', monospace; background-color: rgb(255, 255, 255);">read</span><span style="font-family: Charter, serif; line-height: 24px; background-color: rgb(255, 255, 255);"> procedure accepts either one argument (an input port) or five, and a</span><span class="RktSym" style="margin: 0px; padding: 0px; font-family: 'Source Code Pro', monospace; background-color: rgb(255, 255, 255);">read-syntax</span><span style="font-family: Charter, serif; line-height: 24px; background-color: rgb(255, 255, 255);"> procedure accepts either two arguments (a name value and an input port) or six. In either case, the four optional arguments are the reader’s module path (as a syntax object in </span><span class="RktSym" style="margin: 0px; padding: 0px; font-family: 'Source Code Pro', monospace; background-color: rgb(255, 255, 255);"><a href="file:///Applications/Racket%20v6.0.1.8/doc/reference/Reading.html?q=read-syntax/recursive#%28def._%28%28quote._~23~25kernel%29._read-syntax%29%29" class="RktValLink" data-pltdoc="x" style="margin: 0px; padding: 0px; text-decoration: none; color: rgb(0, 119, 170);">read-syntax</a></span><span style="font-family: Charter, serif; line-height: 24px; background-color: rgb(255, 255, 255);"> mode) followed by the line (positive exact integer or </span><span class="RktVal" style="margin: 0px; padding: 0px; font-family: 'Source Code Pro', monospace; color: rgb(34, 139, 34); background-color: rgb(255, 255, 255);">#f</span><span style="font-family: Charter, serif; line-height: 24px; background-color: rgb(255, 255, 255);">), column (non-negative exact integer or </span><span class="RktVal" style="margin: 0px; padding: 0px; font-family: 'Source Code Pro', monospace; color: rgb(34, 139, 34); background-color: rgb(255, 255, 255);">#f</span><span style="font-family: Charter, serif; line-height: 24px; background-color: rgb(255, 255, 255);">), and position (positive exact integer or </span><span class="RktVal" style="margin: 0px; padding: 0px; font-family: 'Source Code Pro', monospace; color: rgb(34, 139, 34); background-color: rgb(255, 255, 255);">#f</span><span style="font-family: Charter, serif; line-height: 24px; background-color: rgb(255, 255, 255);">) of the start of the </span><span class="RktInBG" style="margin: 0px; padding: 0px; background-color: rgb(238, 238, 238); font-family: Charter, serif; line-height: 24px;"><span class="hspace" style="margin: 0px; padding: 0px; font-family: 'Source Code Pro', monospace; white-space: inherit;"></span><span class="RktIn" style="margin: 0px; padding: 0px; font-family: 'Source Code Pro', monospace; white-space: inherit; color: rgb(204, 102, 51);">#reader</span><span class="hspace" style="margin: 0px; padding: 0px; font-family: 'Source Code Pro', monospace; white-space: inherit;"></span></span><span style="font-family: Charter, serif; line-height: 24px; background-color: rgb(255, 255, 255);"> form. </span></div><div><br></div><div>But maybe there should be a link or something to section 1.3.18 from sections 17.2 and 17.3.1 of the Guide. </div><div>That would make it a lot easier to find it. </div><br><blockquote type="cite"><br>At Sat, 5 Jul 2014 13:33:27 -0400, "Alexander D. Knauth" wrote:<br><blockquote type="cite"><br>If I have a meta-language like this:<br> #lang my-meta-lang <language><br>And my-meta-lang is similar to at-exp in that it can accept any arbitrary <br>language with any arbitrary reader<br>(as long as it looks at the readtable), then how do I escape back to the reader <br>specified by <language><br>from inside a reader macro from my-meta-lang?<br><br>What I’m trying to do is something like #lang afl <language> where afl adds <br>rackjure-like anonymous function literals<br>to <language>. <br><br>So to parse this:<br>#lang afl racket<br>#λ(+ % 1)<br>It would use the racket reader but wrap it to use the afl-readtable, which <br>includes dispatch-macros that would<br>read the (+ % 1) and parse the result into a lambda expression. <br><br>But if <language> was something else, with a different reader, then how could I <br>use that to read the (+ %1 1).<br><br>For example if it was something like this:<br>#lang afl at-exp racket<br>#λ@+[% 1]<br><br>There’s also another problem. If it was this:<br>#lang afl <language><br>#f<br>Or this:<br>#lang afl <language><br>#false<br>Or some other thing starting with f that means something to <language>,<br>Then it would see the #f and hope that it would turn out to be #fn. If it <br>doesn’t, then it uses the racket reader<br>(instead of the one provided by <language>) to read the #f or the #false. <br><br>So back to my original question: How do I escape back to the reader specified <br>by <language><br>from inside a reader macro? <br><br>By the way I can’t find anything in the docs about what the arguments to the <br>read and read-syntax functions<br>provided by <language>/lang/reader.rkt are supposed to be or mean. <br><br><br>____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></blockquote></div><br></body></html>