# Question about syntax

**URL:** <https://racket.discourse.group/t/question-about-syntax/3697>\
**Category:** Questions & Answers\
**Created:** [April 20, 2025, 11:08am UTC](https://racket.discourse.group/t/question-about-syntax/3697 "2025-04-20T11:08:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)\
**Post date:** [April 20, 2025, 11:08am UTC](https://racket.discourse.group/t/question-about-syntax/3697/1 "2025-04-20T11:08:56Z")

</div>

Hi,

i have this code :

```scheme
;; 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)

---

<div class="post-metadata">

**Author:** ![shhyou](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@shhyou](https://racket.discourse.group/u/shhyou)\
**Post date:** [April 21, 2025, 4:54am UTC](https://racket.discourse.group/t/question-about-syntax/3697/2 "2025-04-21T04:54:30Z")

</div>

In r6rs ([r6rs-lib](https://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-13.html#node_sec_12.6)), 12.6 Syntax-object and datum conversions, `syntax->datum` and `datum->syntax`

---

<div class="post-metadata">

**Author:** ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)\
**Post date:** [April 21, 2025, 8:15am UTC](https://racket.discourse.group/t/question-about-syntax/3697/3 "2025-04-21T08:15:21Z")

</div>

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

 ![datum](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/9/984b38313d8ebce7a93a3cf04d65847f8ed318ac.png)

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:

 ![datum2](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/2/25bc08d04c40fc0518131f9b965c8ec1405ba393.png)

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

---

<div class="post-metadata">

**Author:** ![shhyou](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@shhyou](https://racket.discourse.group/u/shhyou)\
**Post date:** [April 21, 2025, 7:38pm UTC](https://racket.discourse.group/t/question-about-syntax/3697/4 "2025-04-21T19:38:43Z")

</div>

> [@damien\_mattei](#):
>
> this seems better:

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).

---

<div class="post-metadata">

**Author:** ![shawnw](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/shawnw/32/1031_2.png) [@shawnw](https://racket.discourse.group/u/shawnw)\
**Post date:** [April 21, 2025, 8:07pm UTC](https://racket.discourse.group/t/question-about-syntax/3697/5 "2025-04-21T20:07:50Z")

</div>

In Racket specific code, [`format-id`](https://docs.racket-lang.org/reference/syntax-util.html#%28def._%28%28lib._racket%2Fsyntax..rkt%29._format-id%29%29) is simpler for this kind of conversion, btw.

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

```

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