CrossClj

2.0.0 docs

SourceDocs



RECENT

    akar

    Clojars

    Apr 12, 2018


    Readme

    Index of all namespaces


    « Project + dependencies

    First-class patterns for Clojure

    The README below is fetched from the published project artifact. Some relative links may be broken.

    Akar

    Join the chat at https://gitter.im/missingfaktor/akar Build Status

    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 "1.0.0"]
    
    # All Akar projects
    [akar "1.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 © 2018 Rahul Goma Phulore, Rahul Kavale

    Distributed under Apache License 2.0.