Error in syntax-parse

hello,
i have this error in this code:

#lang racket
(require syntax/parse)
(require syntax/strip-context)
(define (emit-interaction stx)
  (syntax-parse stx
    #:context '|error while parsing interaction|
		[(_ expr-or-def)
                 (strip-context (syntax expr-or-def))]))

(emit-interaction 10)
error while parsing interaction: bad syntax in: 10

what is wrong? i just want to get 10 without error,even if it seems silly...

I think you meant to write

(define-syntax (emit-interaction stx)
  ...)

rather than

(define (emit-interaction stx)
  ...)

no?

1 Like

no :slight_smile:

doing this make an error:
: wildcard not allowed as an expression
after encountering unbound identifier (which is possibly the real problem):
syntax-parse in: (
expr-or-def)

the solution was:

(define (emit-interaction stx)
  (syntax-parse stx
    #:context '|error while parsing interaction|
		[(~var expr-or-def)
                 (strip-context (syntax expr-or-def))]))

but i find yesterday that i can do the same with:

(datum->syntax #f result)

i mean (emit-interaction 10) create the same strange syntax object than (datum->syntax #f 10)

same thing if argument is a variable:

(define x 3)
(emit-interaction x)

(datum->syntax #f x)

the two syntax create an object syntax , i needed this strange macro with parse-syntax because a simple one with an identifier as argument would have return a syntax object with containing identifier and not the value stored in identifier.

Damien

I agree with @jbclements and additionally you also want to use (require (for-syntax syntax/parse syntax/strip-context)). Without for-syntax you get en error messages because the syntax-parse needs to be required at syntax phase (matching the define-syntax).

Note the last two lines telling you that syntax-parse is not bound (because of missing for-syntax).

If you turn your emit-interaction into a non macro by just using define you might as well write it as a function:

(define x 3)
(define emit-interaction identity)
(emit-interaction x)
;; or alternatively
x

Please provide more context on what you are trying to accomplish, currently I don't understand what your actual goal is.

Yes i will post in another thread the whole code.Consider this problem solved. The 2 solutions was equivalent, i will use simplest one, the two solutions are not portable to another Scheme.