GitXplorerGitXplorer
j

clj-ripple

public
1 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
305e598be284171af084dc2b42de70edc4de404e

.

eeduardoejp committed 14 years ago
Unverified
b0121e0ce2d6618fa81dc814902af8c3ac69eacf

..

eeduardoejp committed 14 years ago
Unverified
935e3ba7968cdff58442e4a1defeb90bcd4ace9b

.

eeduardoejp committed 14 years ago
Unverified
0f99f96482e4be01140c48e6595d5b4dead4b978

.

eeduardoejp committed 14 years ago
Unverified
41d2059d84a29f0001513e55b1dd2aa73c113545

.

eeduardoejp committed 14 years ago
Unverified
5a7af4a04d441a840fdad0c5aef38b1cc4d14435

.

eeduardoejp committed 14 years ago

README

The README file for this repository.

clj-ripple

clj-ripple is a library for translating Clojure source code into Ripple source code, which can then be executed. This allows for easy embedding of Ripple into Clojure programs.

Usage

Simply add this to your leiningen deps: [clj-ripple "0.1.0-SNAPSHOT"]

Syntax

The ripple macro takes specially formatted Clojure source code and translates it (using the translate function) into the equivalent Ripple source code. It then executes it using the run-ripple function, inside an evironment created with the with-ripple macro, which dynamically binds the *ripple* var to a fresh QueryPipe and the *sink* var to a fresh Collector<T,E> sink.

Although all of those components (with-ripple, run-ripple & translate) can be used separately, it is best to simple use the ripple macro.

The result is return as a Clojure lazy sequence containing all the stacks as sequences. The topmost elements in the stacks appear first and are followed by the elements at the bottom. Example: ((top, top-1, top-2), (top, top-1), (top, top-1, top-2, ..., top-n))

Examples

clj-ripple syntax and its equivalent Ripple source code can be understood by reading the following examples:

; Before code is executed, Ripple must be initialized through the init-ripple function. When passed no parameters, it initializes Ripple
; with a default configuration (see Ripple wiki's "Running Ripple")
; For a custom configuration, pass the properties as a Clojure hash-map.
(init-ripple)

@prefix foaf: <http://xmlns.com/foaf/0.1/>
@list dan: <http://danbri.org/foaf.rdf#danbri>
:dan. foaf:knows. foaf:name.
(ripple
  (prefix foaf "http://xmlns.com/foaf/0.1/") ; An string passed to prefix is inmediately put inside <>
  (def dan @"http://danbri.org/foaf.rdf#danbri") ; Since regular strings can be used as data, in non-prefix situations, strings must be dereferenced in order to be evaluated as URLs.
  (!/dan foaf/knows foaf/name) ; !/ is the default namespace.
  )

@list days: "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"
1 2 3 :days.
(ripple
  (def days "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday")
  (1 2 3 !/days) ; By default, lists and other primitives are applied the . (op) operator.
  )

@list days: "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"
1 2 3 :days
(ripple
  (def days "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday")
  (1 2 3 '!/days) ; But quoting them removes the . (op) operator.
  )

16 dup. mul.
(ripple
  (16 dup mul)
  )

@list n triangle:
  n 1 add. n mul. 2 div.
4 :triangle.
(ripple
  (def triangle [n] ; To create a parametered list, give it an args vector.
    n 1 add n mul 2 div)
  (4 !/triangle)
  )

@list fact:
  dup. 0 equal.
  (1 popd.)
  (dup. 1 sub. :fact. mul.)
  branch.
5 :fact.
(ripple
  (def fact
    dup 0 equal
    (1 popd)
    (dup 1 sub !/fact mul)
    branch)
  (5 !/fact)
  )

; Top level lists are evaluated as single lines of Ripple code. Different lines must be specified as different lists to avoid confusion
; Lists inside lists, however, are interpreted as Ripple lists.

@show prefixes
@show contexts
(ripple
  (show :prefixes)
  (show :contexts)
  )

(10 20 30) rdf:rest{2} rdf:first.
(ripple
  ((10 20 30) [rdf/rest 2] rdf/first)
  )

(10 20 30) rdf:rest{0,1} rdf:first.
(ripple
  ((10 20 30) [rdf/rest 0 1] rdf/first)
  )

Further Information

For more information about Ripple, please visit the following websites:

  1. http://ripple.fortytwo.net/

  2. https://github.com/joshsh/ripple/wiki