Macro syntax incompatibility

hello,

i have a macro that works in Guile scheme and is accepted by Racket but the execution is bad:

here is the macro:

(define-syntax for
  (lambda (stx)
    (syntax-case stx ()
      ((kwd (init test incrmt) body ...)
       (with-syntax ((BREAK (datum->syntax #'kwd 'break))
		     (CONTINUE (datum->syntax #'kwd 'continue)))
		    #'(call/cc
		       (lambda (escape)
			 (let-syntax ((BREAK (identifier-syntax (escape))))
			   init
			   (let loop ()
			     (when test
				   (call/cc
				    (lambda (next)
				      (let-syntax ((CONTINUE (identifier-syntax (next))))
					body ...)))
				   incrmt
				   (loop)))))))))))

and here is a simple example in Scheme:

scheme@(guile-user)> (for ((define i 0) (< i 5) (set! i (+ i 1))) (display i) (newline))
0
1
2
3
4

and here is the problem in Racket:
Welcome to DrRacket, version 8.6 [cs].
Language: racket, with debugging; memory limit: 512 MB.

(define-syntax for
  (lambda (stx)
    (syntax-case stx ()
      ((kwd (init test incrmt) body ...)
       (with-syntax ((BREAK (datum->syntax #'kwd 'break))
		     (CONTINUE (datum->syntax #'kwd 'continue)))
		    #'(call/cc
		       (lambda (escape)
			 (let-syntax ((BREAK (identifier-syntax (escape))))
			   init
			   (let loop ()
			     (when test
				   (call/cc
				    (lambda (next)
				      (let-syntax ((CONTINUE (identifier-syntax (next))))
					body ...)))
				   incrmt
				   (loop)))))))))))

(for ((define i 0) (< i 5) (set! i (+ i 1))) (display i) (newline))
. . ../../Applications/Racket v8.6/share/pkgs/errortrace-lib/errortrace/stacktrace.rkt:700:4: identifier-syntax: undefined;
cannot reference an identifier before its definition

i just realize the problem comes from identifier-syntax not existing in Racket (but i had no error until i used the macro...)

how can identifier-syntax be replaced with in racket?

thanks in advance
Damien

Import it like this:

(require (for-syntax r6rs/private/base-for-syntax))
1 Like

Welcome to DrRacket, version 8.6 [cs].
Language: reader "racket/SRFI-105.rkt", with debugging; memory limit: 512 MB.
'()

(for ((define i 0) (< i 5) (set! i (+ i 1))) (display i) (newline))
0
1
2
3
4
'()

Great :slight_smile:
thank you
damien