Re: Wow, Lisp Reader !!
"David McClain (as dbm at refined-audiometrics dot com)" <[email protected]> Sat, 23 May 2026 15:17:42 -0700
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
Yes, I have that for myself. Perhaps I just need to polish it a bit harder. For the embedded colon chars in my angle input, I currently have to write #N|12:42:33.25| or #N”12:42:33.25” so that I have either a symbol or a string to take apart. But if I back up a bit and do the read-chars myself, then I ought to be able to get around this. That #N format also gives me complex notation like 1.2+2.7j as well as dates like 2025/05/23. Those can be written directly into a Sexpr enclosed by a WITH-EXTENDED-NUMBER-SYNTAX macro that just traces the Sexpr tree and tries interpreting every symbol as one of these extended number formats. > On May 23, 2026, at 15:00, Jon Boone <[email protected]> wrote: > > Would either of these approaches possibly work? > Like '$math_expr$' in LaTeX triggers in-line math-mode, you can create a macro-key sequence that switches to your custom Readtable just for that format and have the macro evaluate the input to generate the proper character sequence for normal Readtable usage, or > I think you can create a custom macro-key in the default Readtable that lets you type your preferred syntax. This macro would un-read the previous symbols with the ':' delimiters and re-format them into output compatible with the normal read-table. > > —jon > > > On Sat, May 23, 2026 at 5:41 PM David McClain (as dbm at refined-audiometrics dot com) <[email protected] <mailto:[email protected]>> wrote: >> Holy smokes… Common Lisp did such an amazing job with everything else, and especially CLOS. But now that I am old, I want to specialize the Lisp Reader for myself. I get really wearing not being able to enter DD:MM:SS for Right Ascensions and Declinations. >> >> But gobsmack'ingly, the Common Lisp Reader is hugely resistant to customization. The HyperSpec hints that custom readers should be possible: >> >> 2.1.4 Character Syntax Types >> >> The Lisp reader <https://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#lisp_reader> constructs an object <https://www.lispworks.com/documentation/HyperSpec/Body/26_glo_o.htm#object> from the input text by interpreting each character <https://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#character> according to its syntax type <https://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#syntax_type>. The Lisp reader <https://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#lisp_reader> cannot accept as input everything that the Lisp printer <https://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#lisp_printer> produces, and the Lisp reader <https://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#lisp_reader> has features that are not used by the Lisp printer <https://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#lisp_printer>. The Lisp reader <https://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#lisp_reader> can be used as a lexical analyzer for a more general user-written parser. >> >> >> >> And yet, there are no functions to allow interrogation of the Readtable for character syntax types corresponding to any particular character, except for those that are marked as macro characters. >> >> >> Other, macro characters, like tic (apostrophe) #\’ should really only carry meaning at the leading edge of a symbol name. But it serves as a stopping delimiter in the Lisp Reader so that you cannot have symbol names like Thing and Thing’, without writing them as |Thing’|. >> >> Interestingly, the colon character, #\:, which is used to separate package names from symbol names, is *NOT* shown as anything special in the HyperSpec. It is simply listed as a constituent character. >> >> Maddeningly, LW chose to intercept this character with eager resolution, rather than allowing it to just become absorbed as a compound symbol token for later analysis. And there are no CL Hooks to be found that allows for alternate interpretations. >> >> So I find it totally mystifying that this corner of Common Lisp should be so comparatively backwards. >> >> >> >> [ I apologize if I come off too harsh. I cut my teeth on Forth, which has no restrictions, at the observatories many decades ago… ] >>