Skip to content

First-class patterns for Clojure. Made with love, functions, and just the right amount of syntax.

License

Notifications You must be signed in to change notification settings

missingfaktor/akar

Repository files navigation

Akar

Clojars Project Clojars Project Clojars Project Clojars Project

[Speech]
Queen: Hmm...

Who's been painting my roses red?
Who's been painting my roses red?

Who dares to taint with vulgar paint
the royal flower bed?

For painting my roses red
someone will lose his head.

[Spoken]
Three: Oh no, your majesty, please, it's all his fault!
Two: Not me, Your Grace. The Ace! The Ace!
Queen: You?
Ace: No, Two!
Queen: The Deuce, you say?
Two: Not me, the Tres!
Queen: That's enough! Off with their heads!

Akar is a pattern matching library for Clojure, with focus on simplicity and abstraction.

Akar patterns are first-class values (just functions, actually), that can be manipulated, composed, abstracted over, like any other values. In fact, this is exactly how various pattern operations, such as guards, alternation, and views are implemented in Akar.

The library also features a syntactic layer that makes common use cases convenient, but at the same time stays true to the first-class spirit of the core model.

Akar (IPA: [ɑkɑɾ], Devanagari: आकार) is a Sanskrit/Marathi word for shape. The logo is a Saraswati Kolam, a diagrammatic representation of Hindu goddess of wisdom.

To learn more, read the Akar tutorial and FAQs.

Releases and Dependency Information

# Specific Akar projects
[akar/akar-core "3.0.0"]

# All Akar projects
[akar "3.0.0"]

Example

(ns your.app
  (:require [akar.syntax :refer [match]]
            [clojure.data.xml :as xml]))

; Example borrowed from https://wiki.scala-lang.org/display/SYGN/Xml-pattern-matching
(defn italics [xml-node]
  (match xml-node
         {:tag :i :content (:seq [contents])} (println contents)
         {:tag :node :content nodes}          (doseq [child nodes] (italics child))
         :_                                   nil))

(def xml-doc
  (xml/parse (java.io.StringReader.
               "<node>
                  <node>This is <i>some</i> text content.
                    <node>This is <i>deeper</i> stuff.</node>
                  </node>
                  <node>I am some text.
                    <title>I am <i>a title</i>.</title>
                    This is a sentence with an <i>italicized</i> entry.
                  </node>
                </node>")))

(italics xml-doc)

; prints:
;   some
;   deeper
;   italicized

Contributing

Do you wish to contribute to Akar? Splendid! Get started here.

License

Copyright © 2024 Rahul Goma Phulore

Distributed under Apache License 2.0.

About

First-class patterns for Clojure. Made with love, functions, and just the right amount of syntax.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published