[racket] Writing algebraic maths expressions

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Sat Mar 7 11:04:05 EST 2015

Alexander, hello.

> On 2015 Mar 7, at 12:34, Alexander D. Knauth <alexander at knauth.org> wrote:
> 
> Would this work for you:
> https://github.com/AlexKnauth/infix-macro
> It’s a macro, not a reader extension, so you would need to put spaces.
[...]
> There’s also this:
> http://planet.racket-lang.org/display.ss?package=infix.plt&owner=soegaard

Many thanks for this!  Jens Axel's infix parser appears to be exactly the thing I was imagining.  The fact that it doesn't need the intervening spaces is attractive: otherwise, it feels like a sort of half-way house, where I've got to mentally overload two different syntaxes (in a sense) rather than simply page in one or the other.

And thanks for the explanation about 'group' as opposed to '\\'.

> And for sweet-exp (ii), the braces don’t interact in a complicated way with the surrounding syntax (no worrying about where semicolons go, and you don’t have to worry about where braces go either, except that where there are braces, it’s a infix expression).

There's clearly _something_ going on with the parsing, though.  For example

#lang sweet-exp racket/base

(define (f x)
  {x * x}
  ;
  )

produces 'invalid module text. . unexpected `)`.  Also, in <http://sourceforge.net/p/readable/wiki/Scheme-tutorial/>, at 'Unsweeten: Translating Sweet-expressions into S-expressions', there's a passage 

> Unsweeten also copies comments to the output file, but only in certain cases. Only a group of semicolon comments starting from either the file's very beginning, or after a blank line, are copied to the output. Such semicolon comments will have indentation (if any) removed. Block comments and comments inside a datum are never copied. Semicolon comments immediately after a datum aren't copied either (the reader has to consume them to see if it's reached the end of the datum - and once the data is consumed unsweeten can't copy the comment out).
> Unsweeten also has some special substitutions. If a semicolon begins a line, the next character may cause it to do something special. If line begins with ";#: or ";!", the line is copied back without the leading semicolon. If a line begins with ";_", then the line is copied back without either of those first two characters.

I can broadly understand why this is happening, but this again feels like the half-way problem mentioned above.  The infix.plt solution, piggybacking as it does on the at-exp reader, seems to evade this problem.

Best wishes,

Norman


-- 
Norman Gray  :  http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK



Posted on the users mailing list.