Hi,
i'm writing a parser to evaluate super-scripted expression (not sure it is a good idea in real life but i like the display) used in exponentiation expressions, here is a working example :
Welcome to DrRacket, version 8.14 [cs].
Language: reader SRFI-105, with debugging; memory limit: 8192 MB.
SRFI-105 Curly Infix parser for Racket Scheme and R6RS by Damien MATTEI
(based on code from David A. Wheeler and Alan Manuel K. Gloria.)
Parsed curly infix code result =
(module repl racket (provide (all-defined-out)) (require Scheme+))
Scheme+ v10.0 by Damien Mattei
> {3 ²}
9
the above expression is well transformed (with syntax transformers) in (** 3 2)
but if i try : {3 ⁻²}
which require to transform the above expression in : (** 3 (- 2))
(note: i could produce (** 3 -2)
which would work but for prefix general expressions it is not always possible to work like this)
then with (** 3 (- 2))
i have this error:
$nfx$ op1 e1 : parsed-args=.#<syntax (** 3 (- 2))>
. ../superscript-parser.rkt:207:24: -: unbound identifier;
also, no #%top syntax transformer is bound
context...:
other binding...:
context at layer 1...: in: -
the offending line of code is this one:
(return (cons #'-
(state-0-syntax-analysis nxt)))
that would return what would became after syntax transforming (- 2)
Writing this post i find a solution :
(return (cons '-
(state-0-syntax-analysis nxt)))
which give the good result:
{3 ⁻²}
1/9
i post anyway the message because i'm curious of what solution to avoid the original error. I found a solution with (quote -)
but i hoped to have one with (syntax -)
working too.
Generally adding something like (require (for-syntax racket/base))
is enought to remove the error, but not in this case.
(define n 3)
{3 ²*⁽ⁿ⁻⁴⁾}
1/9
{3 ²·⁽ⁿ⁻⁴⁾}
1/9
Damien