Operator (from racket/base) not known

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

Without seeing the code it's difficult to tell the issue, but is it possible that you need (require (for-template racket/base)) instead? This would be a problem if your unbound #'- is at phase 0 of the enclosing module, where racket/base isn't already available at the right phase.

#lang racket/base
; Call the phase at which this module runs "phase 0"

(module bad-reference racket/base ; <- only contains phase 1 bindings
  ;; uncomment below to fix:
  ;;(require (for-template racket/base))
  (provide negated)
  (define (negated x) #`(- #,x)))
;                        ^ this is bound only at phase 1, because
;                                 v 'bad-reference is required at phase 1
(require (for-syntax racket/base 'bad-reference))

(define-syntax (negate stx)
  (syntax-case stx {}
    [(_ x) (negated #'x)]))
;           ^ negated runs in phase 1,
; v but the expansion gets used in phase 0
(negate 5)
;; -: unbound identifier;
;;   also, no #%app syntax transformer is bound
;;   at: -
;;   in: (- 5)
1 Like

yes, your solution worked.