# \#'else used in match

**URL:** <https://racket.discourse.group/t/else-used-in-match/3066>\
**Category:** Questions & Answers\
**Created:** [August 1, 2024, 8:24am UTC](https://racket.discourse.group/t/else-used-in-match/3066 "2024-08-01T08:24:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WSWZhh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/wswzhh/32/1867_2.png) [@WSWZhh](https://racket.discourse.group/u/WSWZhh)\
**Post date:** [August 1, 2024, 8:24am UTC](https://racket.discourse.group/t/else-used-in-match/3066/1 "2024-08-01T08:24:45Z")

</div>

```scheme
<pkgs>/dsl/nested-word-list> (define (tokenize s)
                                (for/list ([str (regexp-match* #px"\\(|\\)|\\w+" s)])   
                                  (match str
                                             ["("
                                              (token 'LEFT-PAREN str)]
                                             [")"
                                              (token 'RIGHT-PAREN str)]
                                             [else
                                              (token 'WORD str)])))
string:8:16: else: not allowed as an expression
  in: (else (token (quote WORD) str))
 [,bt for context]

```

**what happen?**

---

<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:** [August 1, 2024, 8:40am UTC](https://racket.discourse.group/t/else-used-in-match/3066/2 "2024-08-01T08:40:06Z")

</div>

1. Are you sure that your DSL provides `match`? Does `(match 1 [1 #t])` work? I believe you need `(require racket/match)` to make the code work.
2. But even when the code does work, it's still not really correct. `match` doesn't support the `else` clause. What it's doing is to bind the value to the identifier `else`, which is certainly not what you want. You should use `_` instead of `else`.

---

<div class="post-metadata">

**Author:** ![WSWZhh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/wswzhh/32/1867_2.png) [@WSWZhh](https://racket.discourse.group/u/WSWZhh)\
**Post date:** [August 1, 2024, 9:04am UTC](https://racket.discourse.group/t/else-used-in-match/3066/3 "2024-08-01T09:04:44Z")

</div>

thanks very much ,I followed your answer and solved the problem  
the document **brag: a better Racket AST generator**** 1 Quick start** write it this way

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/1/1fb8e6b9cd6a7c3f0ac00362553c9c634792f2c5.png)

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [August 1, 2024, 11:03am UTC](https://racket.discourse.group/t/else-used-in-match/3066/4 "2024-08-01T11:03:22Z")

</div>

An identifier such as `foo` or `else` matches anything.  
So in your example `match` isn't looking for `else` it just uses the normal rules for identifiers.  
It is customary to use `_` to mean "match anything and I don't care what was matched".
