Coder Social home page Coder Social logo

missingfaktor / akar Goto Github PK

View Code? Open in Web Editor NEW
174.0 18.0 13.0 3.48 MB

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

License: Apache License 2.0

Clojure 100.00%
clojure pattern-matching functional-programming

akar's Introduction

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.

akar's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

akar's Issues

View don't handle exceptions

;; fails with  java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
(match {:foo 0}
       {:foo (:view last foo)} foo)

;; working
(match {:foo [1]}
       {:foo (:view last foo)} foo)

Improve unit tests

  • Move tests as-is to Midje, without any logical changes
  • Bring consistency to unit tests. The test structure, the nesting of blocks, the description styles are not consistent.
  • syntax-test has some tests that test macro expansions, and some that don't concern themselves with implementation details and just run the code. I think the latter is the way to go. It would be great to have all syntax tests migrated to that style.

Got java.lang.NoClassDefFoundError while requiring akar.syntax

Hi,

I was trying to follow the example in README, but I got some error requiring akar.syntax:

(ns test-akar
  (:require [akar.syntax :refer [match]]))

Exception thrown: java.lang.NoClassDefFoundError (Could not initialize class akar.syntax__init)
forName0 - (Class.java:-2)
forName - (Class.java:348)
classForName - (RT.java:2154)
classForName - (RT.java:2163)
loadClassForName - (RT.java:2182)
load - (RT.java:436)
load - (RT.java:412)
load/fn - clojure.core - (core.clj:5866)
load - clojure.core - (core.clj:5865)
invoke - (RestFn.java:408)
load-one - clojure.core - (core.clj:5671)
load-lib/fn - clojure.core - (core.clj:5711)
load-lib - clojure.core - (core.clj:5710)
applyTo - (RestFn.java:142)
apply - clojure.core - (core.clj:632)
load-libs - clojure.core - (core.clj:5749)
applyTo - (RestFn.java:137)
apply - clojure.core - (core.clj:632)
require - clojure.core - (core.clj:5832)
invoke - (RestFn.java:408)
eval16598/loading--auto-- - test-akar - (form-init6887063743962048892.clj:1)
eval16598 - test-akar - (form-init6887063743962048892.clj:1)

I'm using Did I missing [akar "0.1.0"]. Did I miss anything? Please kindly help.

Thank you,

  • Cox

`recur` special form doesn't work inside match expressions

Here is an example:

akar.try-out=> (defn tail-recursive-sum [x running-total]
                 (match x
                        0  running-total
                        :_ (recur (dec x) (+ running-total x))))

CompilerException java.lang.IllegalArgumentException: Mismatched argument count to recur, expected: 0 args, got: 2, compiling:(/private/var/folders/cl/wrqg78nx3c3cxwyb4nmmv1l8394zzh/T/form-init6487640578328843470.clj:4:13)

Easy to see why this is happening. Akar expands clause bodies to anonymous functions, and recur binds to the nearest closing function.

Weekly Digest (16 August, 2018 - 23 August, 2018)

Here's the Weekly Digest for missingfaktor/akar:


ISSUES

Last week, no issues were created.


PULL REQUESTS

Last week, no pull requests were created, updated or merged.


COMMITS

Last week there were no commits.


CONTRIBUTORS

Last week there were no contributors.


STARGAZERS

Last week there were no stargazers.


RELEASES

Last week there were no releases.


That's all for last week, please 👀 Watch and Star the repository missingfaktor/akar to receive next weekly updates. 😃

You can also view all Weekly Digests by clicking here.

Your Weekly Digest bot. 📆

Support syntax-quoted symbol literals

We could extend literal notation to treat syntax-quoted symbol literals as constant patterns. e.g. `baba/banana could map to (!constant `baba/banana).

This came out of a conversation with @darkleaf on this issue thread #20.

Multi-module project setup

In future, we would like to have some child projects of Akar such as akar-exceptions (an alternative to slingshot et al), akar-typed (Typed Clojure support for Akar), and so on. All of these should be independent artefacts that users should be able to pick and choose. Also we would ideally want to version them together.

This Leiningen plugin seems relevant.

Provide a `defn-trampolined` macro

Clojure's recur based TCO doesn't work with Akar because what look like tails don't remain tails after AST transformation. Trampolining is a good solution in rare cases where this is a problem.

Migrate to clojure.spec

clojure.spec appears to cover much the same grounds as seqex, and it's part of the standard library. We should migrate out syntax layer to use clojure.spec.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.