Hello,


I would like to announce the first release of retrograde, a small Clojure 
DSL that deals with the problem of accessing information and results from 
previous iterations during the **lazy** transformation of a sequence or 
during the **lazy** generation of an infinite sequence. The main motivation 
for retrograde was the observation that in tricky cases, when a calculation 
requires access to previous iterations, Clojure programmers (the author at 
least!) tend to resort to using loop/recur, therefore losing laziness. Even 
if one sticks to lazy-seq, handling the passing of various bits of "state" 
to the next iteration is awkward at best, with the most horrific cases 
including use of real state such as atoms etc.

Retrograde allows access to the results of previous iterations using the 
"prime" syntax. For example, here is an infinite list of Fibonacci numbers:

(retrograde/calculate [x 1 (if (and x' x'') (+ x' x'') 0)])

x is defined as the name of the result in each iteration. The result of the 
previous iteration then becomes available as x' (read as "x-prime") and the 
result of the iteration before that is available as x''. You can go back as far 
as you like by adding more prime symbols (single quotes) to the name of your 
result. 

The optional 1 value after the name of the result is the value of x' during the 
first iteration. This is followed by the code fragment that calculates the 
value of x in each iteration. 

The code produced by the macro uses lazy-seq to make sure that the calculation 
happens in a lazy manner, without you having to handle the passing of "state" 
to the next iteration. 

Retrograde also supports access to previous iterations via accumulators. Let's 
look into the (made up) problem of lazily transforming a sequence of numbers so 
that each output element is the input number added to all the odd numbers that 
have occurred in the sequence so far:


> (retrograde/transform
   [odds [] (if (odd? x) (conj odds' x) odds')
    x (apply + (conj odds' x))]
   (range 10))
(0 1 3 4 8 9 15 16 24 25)


Leiningen dependency: [retrograde "0.9"] 
Github: https://github.com/stathissideris/retrograde

Feeback in any form is more than welcome, please let me know.

Thanks,

Stathis


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to