# Matching Question

**URL:** <https://racket.discourse.group/t/matching-question/3391>\
**Category:** Questions & Answers\
**Created:** [December 4, 2024, 8:46am UTC](https://racket.discourse.group/t/matching-question/3391 "2024-12-04T08:46:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rugged](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@Rugged](https://racket.discourse.group/u/Rugged)\
**Post date:** [December 4, 2024, 8:46am UTC](https://racket.discourse.group/t/matching-question/3391/1 "2024-12-04T08:46:41Z")

</div>

Hi,

I am a bit confused why the following code doesn't produce an output:

```scheme
(match #f
    [else
     (cond
       [#f 'not-evaluated]
       [else 'also-not-evaluated])])

```

I would expect it to output 'also-not-evaluated

Thanks

---

<div class="post-metadata">

**Author:** ![notjack](https://avatars.discourse-cdn.com/v4/letter/n/e47774/32.png) [@notjack](https://racket.discourse.group/u/notjack)\
**Post date:** [December 4, 2024, 10:11am UTC](https://racket.discourse.group/t/matching-question/3391/2 "2024-12-04T10:11:29Z")

</div>

The `else` in `match` is treated as a variable, which `match` binds. What you wrote is equivalent to this:

```scheme
(match #f
  [foo
   (cond
    [#f 'not-evaluated]
    [foo 'also-not-evaluated])])

```

And since `foo` is bound to `#f`, none of the `cond` branches are taken and the whole `cond` form evaluated to `(void)`.

I recommend using `_` instead of `else` when you want to express a catch-all fallback branch with `match`. The `_` form is treated specially by `match` and interpreted as "match anything, bind nothing". Like this:

```scheme
(match #f
  [_
   (cond
    [#f 'not-evaluated]
    [else 'this-is-evaluated-now])])

```

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [December 4, 2024, 1:33pm UTC](https://racket.discourse.group/t/matching-question/3391/3 "2024-12-04T13:33:23Z")

</div>

One « précision » to add: cond recognizes else by binding; if it isn’t bound to the same thing as what it knows from racket/base, it won’t treat it as an else (or conversely if you give it something else that _is_ bound to that, cond does see the else).

---

<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:** [December 4, 2024, 1:45pm UTC](https://racket.discourse.group/t/matching-question/3391/4 "2024-12-04T13:45:24Z")

</div>

and if i remember well of Lisp , the ancestor of Scheme, in Lisp there is no `else` ,we simply replace it by `T` or `t`, meaning True when there is a need of an `else` endind the `cond`. It is then a bit rustic but more simple to understand:

```scheme
;; la recherche de l'element a un niveau arbitraire
(defun member1 (ele liste)
  (cond
   ((atom liste) NIL)
   ((equal (car liste) ele) liste)
   (T (memb1 ele (member1 ele (car liste)) (cdr liste)))))

```
