# A match-like DSL for deep immutable updates

**URL:** <https://racket.discourse.group/t/a-match-like-dsl-for-deep-immutable-updates/3220>\
**Category:** Show & Tell\
**Created:** [October 12, 2024, 1:01am UTC](https://racket.discourse.group/t/a-match-like-dsl-for-deep-immutable-updates/3220 "2024-10-12T01:01:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![quasarbright](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/quasarbright/32/834_2.png) [@quasarbright](https://racket.discourse.group/u/quasarbright)\
**Post date:** [October 12, 2024, 1:01am UTC](https://racket.discourse.group/t/a-match-like-dsl-for-deep-immutable-updates/3220/1 "2024-10-12T01:01:50Z")

</div>

I made an optics library called "Ocular Patdown" that features a `match`-like DSL for performing deep immutable updates.

Example:

```racket
> (update (list 1 2 3) 
    [(list a b c) 
     (set! a #t) 
     (modify! b -)])
'(#t -2 3)

```

[Here are the docs](https://docs.racket-lang.org/ocular-patdown/index.html)

It works by creating a tree of composed optics for a pattern, with leaves binding an optic that focuses on that location within the target value.

The DSL is implemented using [`syntax-spec`](https://docs.racket-lang.org/syntax-spec-v2/Reference.html).

This is also an optics library, currently featuring lenses, traversals, prisms, and isomorphisms. But the update language is the coolest part IMO, and it's why I made the library.

This is the first library I've ever published, so I'd love to hear feedback! Hope you find it interesting.

---

<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:** [October 12, 2024, 1:59am UTC](https://racket.discourse.group/t/a-match-like-dsl-for-deep-immutable-updates/3220/2 "2024-10-12T01:59:55Z")

</div>

As someone who has written too many optics libraries, let me just say that this is exceptionally cool.

---

<div class="post-metadata">

**Author:** ![bakgatviooldoos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bakgatviooldoos/32/1381_2.png) [@bakgatviooldoos](https://racket.discourse.group/u/bakgatviooldoos)\
**Post date:** [October 12, 2024, 6:24pm UTC](https://racket.discourse.group/t/a-match-like-dsl-for-deep-immutable-updates/3220/3 "2024-10-12T18:24:21Z")

</div>

Nothing of note from me, but the `make-iso` had me delighted, haha, because it's such a nice idea.

Thanks for sharing!

* * *

Edit: oops.
