# Syntax of \`id\` in grammar for FEP

**URL:** <https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109>\
**Category:** Questions & Answers\
**Created:** [June 30, 2022, 1:20pm UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109 "2022-06-30T13:20:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmatos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/pmatos/32/26_2.png) [@pmatos](https://racket.discourse.group/u/pmatos)\
**Post date:** [June 30, 2022, 1:20pm UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/1 "2022-06-30T13:20:28Z")

</div>

If I look at the documentation for a linklet grammar here: [14.14&nbsp;Linklets and the Core Compiler](https://docs.racket-lang.org/reference/linklets.html)

it says:

> The grammar of an defn-or-expr is similar to the expander’s grammar of fully expanded expressions (see [Fully Expanded Programs](https://docs.racket-lang.org/reference/syntax-model.html#%28part._fully-expanded%29)) ...

In [Fully Expanded Programs](https://docs.racket-lang.org/reference/syntax-model.html#%28part._fully-expanded%29)) though, I feel like the syntax for an `id` is missing. I understand this is a tiny detail but actually for a long time I thought `id`s couldn't start with a number until I saw I could write `1/xpto` as an `id`. What's possible? Is any sequence of graphical chars until a space or paren, an `id`?

---

<div class="post-metadata">

**Author:** ![JustinZed](https://avatars.discourse-cdn.com/v4/letter/j/8e7dd6/32.png) [@JustinZed](https://racket.discourse.group/u/JustinZed)\
**Post date:** [June 30, 2022, 1:50pm UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/2 "2022-06-30T13:50:30Z")

</div>

Section 1.2.2 of the Reference ([1.2&nbsp;Syntax Model](https://docs.racket-lang.org/reference/syntax-model.html#%28part._stxobj-model%29)) says that "an identifier is represented as a syntax object containing a symbol." The rules for symbols are given in Section 3.6 of the Racket Guide ([3.6&nbsp;Symbols](https://docs.racket-lang.org/guide/symbols.html)). I agree that the documentation should be clearer about this.

---

<div class="post-metadata">

**Author:** ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)\
**Post date:** [June 30, 2022, 7:02pm UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/3 "2022-06-30T19:02:42Z")

</div>

In linklets, an `id` is a symbol. Any string can be a symbol, since you can use `|` to escape arbitrary characters. That symbol is transmitted as-is through the linklet process. Here's an example of running a program that uses a single space as an identifier.

```scheme
[samth@huor:~/.../racket/benchmarks/shootout (show-pass) plt] PLT_LINKLET_SHOW=1 r -e '(define | | 1)'
;; linklet ---------------------
(linklet
  ((.top-level-bind! .top-level-require!)
    (.mpi-vector .syntax-literals)
    (.namespace .phase .self .inspector .bulk-binding-registry
      .set-transformer!))
  (\x20;) (define-values (\x20;) 1)
  (if #f (begin (set! \x20; #f)) (void))
  (begin
    (.top-level-bind! (unsafe-vector*-ref .syntax-literals 0)
      (unsafe-vector*-ref .mpi-vector 0) 0 .phase .namespace
      '\x20; #f '#f)))
;; schemified ---------------------
(lambda (instance-variable-reference .top-level-bind!1
         .top-level-require!2 .mpi-vector3 .syntax-literals4
         .namespace5 .phase6 .self7 .inspector8
         .bulk-binding-registry9 .set-transformer!10 \x20;11)
  (define \x20; 1)
  (variable-set!/define \x20;11 \x20; '#f)
  (let ([app_12 (unsafe-vector*-ref .syntax-literals4 0)])
    (#%app .top-level-bind!1 app_12
      (unsafe-vector*-ref .mpi-vector3 0) 0 .phase6 .namespace5
      '\x20; #f '#f)))
;; compiled ---------------------
done

```

---

<div class="post-metadata">

**Author:** ![pmatos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/pmatos/32/26_2.png) [@pmatos](https://racket.discourse.group/u/pmatos)\
**Post date:** [June 30, 2022, 7:33pm UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/4 "2022-06-30T19:33:31Z")

</div>

Thanks - that's interesting and scary at the same time. 🙂  
I don't think I knew about the power of `|`.

So either you have anything within `|`, or any sequence of characters except space and parens can be an `id`. Is that it?

---

<div class="post-metadata">

**Author:** ![JustinZed](https://avatars.discourse-cdn.com/v4/letter/j/8e7dd6/32.png) [@JustinZed](https://racket.discourse.group/u/JustinZed)\
**Post date:** [June 30, 2022, 8:11pm UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/5 "2022-06-30T20:11:00Z")

</div>

It's even better, since the characters can be Unicode !

Welcome to DrRacket, version 8.5 [cs].  
Language: racket, with debugging; memory limit: 4096 MB.

> (define (😀😆😂 😉) (+ 😉 8))  
> (😀😆😂 5)  
> 13

---

<div class="post-metadata">

**Author:** ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)\
**Post date:** [June 30, 2022, 8:26pm UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/6 "2022-06-30T20:26:08Z")

</div>

I think I would just say that it can be any symbol, and symbols can have arbitrary strings as their content. The use of `|` is part of the printer, not the symbol itself.

---

<div class="post-metadata">

**Author:** ![hendrikboom3](https://avatars.discourse-cdn.com/v4/letter/h/b5e925/32.png) [@hendrikboom3](https://racket.discourse.group/u/hendrikboom3)\
**Post date:** [June 30, 2022, 11:49pm UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/7 "2022-06-30T23:49:46Z")

</div>

Not quite so simple.

```
'foo

```

means  
(quote foo)

And I suspect 3.5 is a number, not a symbol.

But |'foo| and |3.5| are probably symbols.

Can anyone confirm?

And how does one write | as a one=character symbol? ||| ?

-- hendrik

---

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [July 1, 2022, 12:15am UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/8 "2022-07-01T00:15:05Z")

</div>

Outside `|...|`, you can use backslash to escape, so

```scheme
>foo)

```

can be produced with:

```scheme
\||foo)|

```

---

<div class="post-metadata">

**Author:** ![pmatos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/pmatos/32/26_2.png) [@pmatos](https://racket.discourse.group/u/pmatos)\
**Post date:** [July 1, 2022, 12:07pm UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/9 "2022-07-01T12:07:21Z")

</div>

You mean "they are probably identifiers", not symbols.

They are only symbols if you do `'|'foo|` or `'|3.5|`.

```nohighlight
Welcome to Racket v8.5 [cs].
> |'foo|
'foo: undefined;
 cannot reference an identifier before its definition
  in module: top-level
 [,bt for context]
> |3.5|
3.5: undefined;
 cannot reference an identifier before its definition
  in module: top-level
 [,bt for context]
> (define |3.5| 3.5)
> |3.5|
3.5
> (symbol? |3.5|)
#f
> '|3.5|
'|3.5|
> (symbol? '|3.5|)
#t

```

This is horrendous, even if very general.

---

<div class="post-metadata">

**Author:** ![simonls](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/simonls/32/170_2.png) [@simonls](https://racket.discourse.group/u/simonls)\
**Post date:** [July 1, 2022, 1:54pm UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/10 "2022-07-01T13:54:56Z")

</div>

> [@pmatos](#):
>
> This is horrendous, even if very general.

I think it can be a useful feature, especially considering that other kinds of `#lang`s may have very different requirements for what is allowed as a valid identifier, it is useful to have an underlying implementation language that can use pretty much everything.

(Imagine having to mangle/encode/decode your dsl identifiers to/from a very specific narrow set of allowed identifiers in the implementation language, personally I would find that more annoying)

Another case where it was useful for me is in the syntax-class that is used for a name mapping in `define-attributes` there an empty symbol is used for the case when you want to "drop" the name, making the implementation simpler.

```scheme
(define-attributes ([l]) vec3- (x y z)) ;; x y z is bound to (vec3-x l) (vec3-y l) (vec3-z l)

```

> <https://github.com/SimonLSchlee/define-attributes/blob/57bffa14f11a604a7bf34a7dbc16f56f5ebf638c/define-attributes-lib/main.rkt#L12>

---

<div class="post-metadata">

**Author:** ![pmatos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/pmatos/32/26_2.png) [@pmatos](https://racket.discourse.group/u/pmatos)\
**Post date:** [July 7, 2022, 6:41am UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/11 "2022-07-07T06:41:11Z")

</div>

Looking a bit closer at this, what sort of syntax is that `\x20;`? I assume something starting with `\x` and ending with `;` has some special meaning ? Although I can't find anything in the docs.

---

<div class="post-metadata">

**Author:** ![pmatos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/pmatos/32/26_2.png) [@pmatos](https://racket.discourse.group/u/pmatos)\
**Post date:** [July 7, 2022, 6:43am UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/12 "2022-07-07T06:43:25Z")

</div>

> [@simonls](#):
>
> (Imagine having to mangle/encode/decode your dsl identifiers to/from a very specific narrow set of allowed identifiers in the implementation language, personally I would find that more annoying)

I guess that's a matter of preference. 🙂 For someone who works on C/C++ compilers, name mangling/demangling is just accepted so I guess my views here are biased.

---

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [July 7, 2022, 7:13am UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/13 "2022-07-07T07:13:24Z")

</div>

I believe this is from Chez Scheme. You can search for “\x” in [https://cisco.github.io/ChezScheme/csug9.5/csug9\_5.pdf](https://cisco.github.io/ChezScheme/csug9.5/csug9_5.pdf) (esp. the ones under the section 7.9 and `print-extended-identifiers`)

---

<div class="post-metadata">

**Author:** ![pmatos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/pmatos/32/26_2.png) [@pmatos](https://racket.discourse.group/u/pmatos)\
**Post date:** [July 7, 2022, 7:22am UTC](https://racket.discourse.group/t/syntax-of-id-in-grammar-for-fep/1109/14 "2022-07-07T07:22:19Z")

</div>

Oh, interesting. You seem to be definitely right. Thanks.
