Question about syntax

Hi,

i have this code :

;; operators
     (cond ((char=? c #\+)
	    (define n (string->number p-tok)) ; partial token is completed
	    (if n
		  (return (cons n
			         (cons #'+
				        (parse-superscript-token-s0 nxt)))) ; continue the parsing of tokens
		  (error "Error parsing superscript : state2-number : bad format of string that can not be converted in number: " p-tok))
	   

	   ;; todo continue here
	   ((char=? c #\-)

...

where i deal with basic arithmetic operators (+,-,*,/) and in each conditional branch the code is almost the same but i do not think there is a way in Scheme to factorize it, i mean i wanted to replace #'+ by something generic where i can construct the syntax object from the c character (of course this would not be exactly the same syntax object as syntax object take in account the line the character position in code but that does not matters) but i do not think it is possible.

I do not think i would have a solution at this problem, note i do not want a racket solution if it exists but a scheme compatible one. I'm facing this little problem in a recurrent way, so perheaps i missed something.....but that would surprise me a lot...

Regards,

update: i updated the code because there was error (unrelated with the question)

In r6rs (r6rs-lib), 12.6 Syntax-object and datum conversions, syntax->datum and datum->syntax

thank you i did not noticed it, but i do not understand well the use i can do with it. I can do :

but i do not know what put in place of 'something' relative to the + operator (i can not put + because i would have to write it then for each operator, +,-,....)
Strange is that 'something' doesn not appear anymore in the syntax info box.

But i will try that, and see how it behave in real code....

No it does not seems to works , give (syntax #+) but not (syntax +)

this seems better:

will see in real use.... at some point #<syntax +> should become the + procedure, not 'something' :sweat_smile:

Yes, you need to convert the character to a symbol. See

Identifiers stripped in this manner are converted to their symbolic names

just below syntax->datum in the same link.

This can be done like the code you wrote (datum->syntax #'here (string->symbol (string ch))) or (datum->syntax #'here (string->symbol (format "~a" ch))). This will create the equivalent of #'+ (modulo source locations).

In Racket specific code, format-id is simpler for this kind of conversion, btw.

(format-id #'here "~a" ch)

(Also lets you specify a source location for the generated syntax object, and other more esoteric stuff)