# Is this macros pair possible?

**URL:** <https://racket.discourse.group/t/is-this-macros-pair-possible/1048>\
**Category:** Questions & Answers\
**Tags:** macro\
**Created:** [June 2, 2022, 2:15pm UTC](https://racket.discourse.group/t/is-this-macros-pair-possible/1048 "2022-06-02T14:15:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kalimehtar](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kalimehtar/32/394_2.png) [@Kalimehtar](https://racket.discourse.group/u/Kalimehtar)\
**Post date:** [June 2, 2022, 2:15pm UTC](https://racket.discourse.group/t/is-this-macros-pair-possible/1048/1 "2022-06-02T14:15:16Z")

</div>

I would like to make something like

```scheme
(my-if cond1 act1 ...)
(my-else act2 ...)

```

that should expand to

```scheme
(if cond1 (begin act1 ...) (begin act2 ...))

```

Is it possible?

---

<div class="post-metadata">

**Author:** ![dominik.pantucek](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dominik.pantucek/32/144_2.png) [@dominik.pantucek](https://racket.discourse.group/u/dominik.pantucek)\
**Post date:** [June 2, 2022, 2:54pm UTC](https://racket.discourse.group/t/is-this-macros-pair-possible/1048/2 "2022-06-02T14:54:14Z")

</div>

I assume you know what you are doing.

```scheme
#lang racket

(require (for-syntax syntax/parse))

(define-for-syntax current-my-if (make-parameter #f))

(define-syntax (my-if stx)
  (syntax-parse stx
    ((_ condition body ...)
     (when (current-my-if)
       (raise-syntax-error #f "Already in my-if" stx))
     (current-my-if (list #'condition
                          #'(begin
                              body ...)))
     #'(void))))
(define-syntax (my-else stx)
  (syntax-parse stx
    ((_ body ...)
     (unless (current-my-if)
       (raise-syntax-error #f "Not in my-if" stx))
     (define this-my-if (current-my-if))
     (current-my-if #f)
     #`(if #,(car this-my-if)
           #,(cadr this-my-if)
           (begin
             body ...)))))

(my-if #f (displayln "it's true"))
(my-else (displayln "no, false"))

(my-if #t (displayln "woo hoo"))
(my-else (displayln "nope"))

```

Basically the real expansion is deferred to the my-else expansion and there can be any arbitrary number of expressions in between. Also the notion of "in my-if" is more like a guideline than actual rule here. However if you only need side effects, it is mostly OK.

Still, I would strongly advise against entering this rabbit hole 😉

---

<div class="post-metadata">

**Author:** ![Kalimehtar](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kalimehtar/32/394_2.png) [@Kalimehtar](https://racket.discourse.group/u/Kalimehtar)\
**Post date:** [June 2, 2022, 3:45pm UTC](https://racket.discourse.group/t/is-this-macros-pair-possible/1048/3 "2022-06-02T15:45:18Z")

</div>

I want something like [my-cond/iffy with sweet-exp](https://docs.racket-lang.org/my-cond-iffy/index.html)

But without outer `my-cond`.
