💾 Archived View for idiomdrottning.org › clojure-like-destructuring-in-brev captured on 2023-04-26 at 13:44:29. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-03)

-=-=-=-=-=-=-

Clojure-like destructuring in brev

I’ve been learning Clojure and it’s pretty fun because a lot of design decisions are similar to brev. I really like Clojure a lot.

Of course, some things are very different.

One thing Clojure is famous for is its destructuring function definitions. That’s something brev can do as well, although the more direct inspiration was Haskell.

Here is an example:

(define fruit-color (call-table))

(fruit-color 'banana 'yellow)
(fruit-color 'apple 'red)
(fruit-color 'pear 'green)

(define (basket-color-inspect ('shopping-basket (= fruit-color color)))
  (print "The shopping basket has a " color " fruit."))

(basket-color-inspect '(shopping-basket apple))

This prints out:

The shopping basket has a red fruit.

Here is another example:

(define computer-color (call-table))
(computer-color 'apple 'bondi)

(define leaf-color (call-table))
(leaf-color 'apple 'green)

(define (basket-apple-inspect ('shopping-basket (= (fn (x 'apple)) color)))
  (print "The shopping basket has a " color " apple."))

(basket-apple-inspect `(shopping-basket ,leaf-color))

That prints out:

The shopping basket has a green apple.

brev