Re: Opinions on Equality Semantics

2013-04-08 Thread Philip Potter
One reason for being slightly "impure" here is for greater java
interoperability. Clojure gets much of its equality semantics for
collections from java.lang.List and java.lang.Set, which define equality to
depend only on collection contents and not on concrete type. By having
equality semantics which match up, you can pass a clojure vector, list, or
seq to a library expecting a j.l.List.

(it's a little more complicated than this; clojure defines its own equality
semantics which broadly matches java collection semantics using the
.equiv() method. It differs only in which numeric types it considers equal.
The clojure = function calls .equiv if present, and .equals otherwise. But
broadly clojure's equality matches java collection equality.)
On Apr 9, 2013 12:02 AM, "JvJ"  wrote:

> This is just an idle curiosity up for discussion, but in Clojure, if (= a
> b) is true, then given some function f, it is not necessarily true that (=
> (f a) (f b))
>
> For instance:
>
> (defn check-eq
> [f a b]
> [(= a b)
> (= (f a) (f b))])
>
> (check-eq #(conj % 1) '(1 2 3) [1 2 3])
> [true false]
>
> Even though the behaviour of lists and vectors differs under specific
> functions, they still count as equal, but this statement "If a = b, then (f
> a) = (f b)" seems like it would be some sort of rule or axiom about
> functional programming.  What's the FP purists' view on this?
>
>
>
>  --
> --
> 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/groups/opt_out.
>
>
>

-- 
-- 
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/groups/opt_out.




Re: [ANN] Instaparse 1.0.0

2013-04-08 Thread Laurent PETIT
Man, this looks like pure gold!

Le mardi 9 avril 2013, Mark Engelberg a écrit :

> Instaparse is an easy-to-use, feature-rich parser generator for Clojure.
> The two stand-out features:
>
> 1. Converts standard EBNF notation for context-free grammars into an
> executable parser.  Makes the task of building parsers as lightweight and
> simple as working with regular expressions.
>
> 2. Works with *any* context-free grammar.  This means you don't have to
> learn the esoteric subtleties of LR, LL, LALR or any other specialized
> subset.  Left-recursion, right-recursion, ambiguous grammars -- instaparse
> handles it all.
>
> Example:
>
> (def as-and-bs
>   (parser
> "S = AB*
>  AB = A B
>  A = 'a'+
>  B = 'b'+"))
>
> => (as-and-bs "abbbbb")
> [:S
>  [:AB [:A "a" "a" "a" "a" "a"] [:B "b" "b" "b"]]
>  [:AB [:A "a" "a" "a" "a"] [:B "b" "b"]]]
>
> https://github.com/Engelberg/instaparse for full feature list and
> extensive tutorial.
>
> --
> --
> 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 '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  'clojure%2bunsubscr...@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  'clojure%2bunsubscr...@googlegroups.com');>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
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/groups/opt_out.




[ANN] Instaparse 1.0.0

2013-04-08 Thread Mark Engelberg
Instaparse is an easy-to-use, feature-rich parser generator for Clojure.
The two stand-out features:

1. Converts standard EBNF notation for context-free grammars into an
executable parser.  Makes the task of building parsers as lightweight and
simple as working with regular expressions.

2. Works with *any* context-free grammar.  This means you don't have to
learn the esoteric subtleties of LR, LL, LALR or any other specialized
subset.  Left-recursion, right-recursion, ambiguous grammars -- instaparse
handles it all.

Example:

(def as-and-bs
  (parser
"S = AB*
 AB = A B
 A = 'a'+
 B = 'b'+"))

=> (as-and-bs "abbbbb")
[:S
 [:AB [:A "a" "a" "a" "a" "a"] [:B "b" "b" "b"]]
 [:AB [:A "a" "a" "a" "a"] [:B "b" "b"]]]

https://github.com/Engelberg/instaparse for full feature list and extensive
tutorial.

-- 
-- 
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/groups/opt_out.




Re: [ANN] java.jdbc 0.3.0-alpha1

2013-04-08 Thread Sean Corfield
Only identifiers (converting from SQL entities to Clojure keywords)
are handled "in" java.jdbc directly (inside result-set-seq) - entities
are handled in the DSL which generates SQL and therefore it's not
related to a connection. If you don't use the DSL, there's no
translation going on - you pass in strings to the java.jdbc functions
and they do whatever you've told them to do...

In (query db-spec (select * :employee (where {:department "IT"}))) the
DSL is invoked first to generate "SELECT * FROM employee WHERE
department = ?" before query is introduced and before db-spec is
looked at.

True, you could still have a default for identifiers on db-spec which
was used for result-set-seq but that seems asymmetric. If folks think
that's worthwhile despite the asymmetry, can someone create a ticket
in JIRA so I don't forget to look into it in more detail?

Sean

On Mon, Apr 8, 2013 at 7:24 PM, Matching Socks  wrote:
> Could the entities and identifiers functions (translating map-keys to
> SQL-names and back) be specified along with connection parameters to avoid
> repetition with each operation?
>
> --
> --
> 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/groups/opt_out.
>
>



-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
-- 
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/groups/opt_out.




Re: Opinions on Equality Semantics

2013-04-08 Thread Phil Hagelberg

JvJ writes:

> Even though the behaviour of lists and vectors differs under specific 
> functions, they still count as equal, but this statement "If a = b, then (f 
> a) = (f b)" seems like it would be some sort of rule or axiom about 
> functional programming.  What's the FP purists' view on this?

Baker's "Equal Rights for Functional Objects" is the best overview of
equality semantics I've ever read:

http://home.pipeline.com/~hbaker1/ObjectIdentity.html

> Two objects are "operationally equivalent" if and only if there is no
> way that they can be distinguished, using ... primitives other than
> [equality primitives]. It is guaranteed that objects maintain their
> operational identity despite being named by variables or fetched from or
> stored into data structures.

Clojure is inspired by it, but cheats in a number of places. The
most obvious being the way that seqs and vectors can be considered
equal. This could be considered cutting corners in order to make
laziness less onerous to deal with. IIRC there are a few other places
where Clojure deviates from this definition of operational equivalence
around defrecord and deftype, but since I don't use those features the
details escape me at the moment.

-Phil

-- 
-- 
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/groups/opt_out.




Re: [ANN] java.jdbc 0.3.0-alpha1

2013-04-08 Thread Matching Socks
Could the entities and identifiers functions (translating map-keys to 
SQL-names and back) be specified along with connection parameters to avoid 
repetition with each operation?

-- 
-- 
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/groups/opt_out.




Re: Opinions on Equality Semantics

2013-04-08 Thread Andy Fingerhut
I think the general pattern here is equality being a function of _part_ of
the value, but not all of it.  For Clojure's = on lists/sequences/vectors,
it is based upon the sequence of values, but not whether it is a list,
sequence, or vector.  For Perverse?'s equals it is quite explicit in its
definition which part it is ignoring.  The functions f being considered
have behavior that explicitly depends upon parts of the value that equality
is ignoring.  Clojure's = on collections also ignores metadata, by design,
and yet functions can return values that depend upon the metadata.

This certainly does lead to as many cases as you care to dream up where (=
a b) but not (= (f a) (f b)).  I believe  Haskell lets you define your own
equality for new types, so there is nothing unique to Clojure here.

Regarding whether it is a good or bad idea for Clojure to define (= '(1 2
3) [1 2 3]), it is often very useful, and lets you write (= s1 s2) instead
of (= (seq s1) (seq s2)) in many places.  I have no objections to it.

What the FP purist's point of view is on that question I don't know.  I'd
guess that a Haskell programmer would frown on defining equality for a new
type in a way that exposes this behavior.  I didn't have much luck from a
few minutes of Google searches, but did find the discussion linked below.
Someone points out how certain Haskell functions are frowned upon because
they cause certain theorems about program transformation to no longer
apply, that would otherwise be true in the absence of those functions.
Such program transformations can be used to help optimize code generated by
compilers.

http://stackoverflow.com/questions/12687392/why-is-seq-bad

Andy



On Mon, Apr 8, 2013 at 4:16 PM, Ben Wolfson  wrote:

> On Mon, Apr 8, 2013 at 4:02 PM, JvJ  wrote:
>
>>
>> Even though the behaviour of lists and vectors differs under specific
>> functions, they still count as equal, but this statement "If a = b, then (f
>> a) = (f b)" seems like it would be some sort of rule or axiom about
>> functional programming.  What's the FP purists' view on this?
>>
>
> You don't even need different types for this:
>
> user> (deftype Perverse? [a b]
>Object
>(equals [this other] (= a (.a other
> user.Perverse?
> user> (defn f [^Perverse? p]
>(Perverse?. (.b p) (.a p)))
> #'user/f
> user> (= (->Perverse? 1 2) (->Perverse? 1 4))
> true
> user> (= (f (->Perverse? 1 2)) (f (->Perverse? 1 4)))
> false
> user>
>
> --
> Ben Wolfson
> "Human kind has used its intelligence to vary the flavour of drinks, which
> may be sweet, aromatic, fermented or spirit-based. ... Family and social
> life also offer numerous other occasions to consume drinks for pleasure."
> [Larousse, "Drink" entry]
>
>  --
> --
> 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/groups/opt_out.
>
>
>

-- 
-- 
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/groups/opt_out.




Re: Clojure is in GSoC 2013!

2013-04-08 Thread Ambrose Bonnaire-Sergeant
Yay!


On Tue, Apr 9, 2013 at 3:33 AM, Daniel Solano Gómez wrote:

> Hello, all,
>
> I am happy to report that Clojure has been accepted as a mentoring
> organization for Google Summer of Code 2013.  Now is the time for
> sudents to start researching their projects and reaching out to members.
> At the same time, we need to start putting together an application
> template for students.  I'll write more in the coming days.
>
> Sincerely,
>
> Daniel
>

-- 
-- 
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/groups/opt_out.




Re: Function recurring regardless of condition

2013-04-08 Thread Alan Malloy
You might be interested in 
https://github.com/amalloy/clusp/blob/master/src/snusp/core.clj, my Clojure 
interpreter for SNUSP (which is brainfuck with different control-flow 
mechanics). It's purely functional, and IMO does a good job of separating 
concerns; both of those are things it sounds like you were having trouble 
with, so hopefully reading it will give you some ideas. Basically my 
approach is to have an object (hash-map) that represents the state of the 
interpreter (the "world"), and "compile" each instruction to a function 
before doing anything. Then, I just look up the instruction at the current 
position, call it on the world, and use the returned world for the next 
step.

On Saturday, April 6, 2013 4:49:36 PM UTC-7, Andrew Spano wrote:
>
> Hello, I'm a new clojure programmer--but after learning a bit of clojure 
> including iteration, some core high order functions, and a little bit about 
> state management I decided to try my hand on a brainfuck interpreter.
>
> Located here:
>
> https://github.com/recursor94/brainfuck.clj/blob/master/brainfuck/src/brainfuck/fuck.clj
>
> Handling looping complicated things.  And the way I chose to deal with 
> looping resulted in some pretty ugly functions.  I hope to clean that up in 
> the future and refractor the code into a more functional style after I've 
> finished the first draft.
>
> The issue is in a particular function which never stops recuring even when 
> the condition for recuring is false:
>
> (defn exec-instruction
>   "executes each function in the codemap vector in sequential order"
>
>
> ([end-index]
>(inc-code-pos)  ;;side affect function that moves the code pointer (I 
> have both a code pointer and a data pointer in my interpreter)
>(loop [index (:index @codemap)]
>  (let [codevec (@codemap :struct)
>instruct (get codevec index)]
>(println "index:" index
> "instruct" instruct
> "minus one index:" (- end-index 2))
>(instruct))
>  (when-not (= index (- end-index 1))
>(println "yeah you are")
>(inc-code-pos)
>(recur (inc index)
> ;;end problem
> ([]
>(doseq [instruct (@codemap :struct)]
>  (instruct) ;;higher order functions ftw
>  (inc-code-pos
>
>
> And here is the function that triggers this function:
>
> (defn begin-loop
>   "run through a loop until current cell drops to zero"
>   []
>   (loop [loop-counter (@cells @pointer)
>  end-loop (find-end (@codemap :index)) ;;find-end returns an integer
>  pos (@codemap :index)]
> (println "cell counter:" loop-counter
>  "other:"  (@cells @pointer)
>  "at 0:" (@cells @pointer)
>  "also:" end-loop)  ;;debug output
> (exec-instruction end-loop)
> (when-not (= loop-counter 0)
>   (recur (@cells @pointer) end-loop pos
>
>
> The program is supposed to stop when it reaches a closing end brace and jump 
> back to the opening brace in the code.  But the output indicates that the 
> program never gets passed the first iteration.
>
> For example, given this hello world brainfuck program:
>
>  
> ++[>+++>++>+++>+-]>++.>+.+++..+++.>++.<<+++.>.+++.--..>+.>.
>
> The program outputs the following:
> index: 11 instruct #'brainfuck.fuck/+pointer minus one index: 39
> yeah you are
> index: 12 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 13 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 14 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 15 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 16 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 17 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 18 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 19 instruct #'brainfuck.fuck/+pointer minus one index: 39
> yeah you are
> index: 20 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 21 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 22 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 23 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 24 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 25 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 26 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 27 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 28 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 29 instruct #'brainfuck.fuck/plus minus one index: 39
> yeah you are
> index: 30 instruct #'brainfuck.fuck/+pointer minus one index: 39
> yeah you are
> index: 31 instruct #'brainfuck.fuck/plus minus one inde

Re: Opinions on Equality Semantics

2013-04-08 Thread Ben Wolfson
On Mon, Apr 8, 2013 at 4:02 PM, JvJ  wrote:

>
> Even though the behaviour of lists and vectors differs under specific
> functions, they still count as equal, but this statement "If a = b, then (f
> a) = (f b)" seems like it would be some sort of rule or axiom about
> functional programming.  What's the FP purists' view on this?
>

You don't even need different types for this:

user> (deftype Perverse? [a b]
   Object
   (equals [this other] (= a (.a other
user.Perverse?
user> (defn f [^Perverse? p]
   (Perverse?. (.b p) (.a p)))
#'user/f
user> (= (->Perverse? 1 2) (->Perverse? 1 4))
true
user> (= (f (->Perverse? 1 2)) (f (->Perverse? 1 4)))
false
user>

-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure."
[Larousse, "Drink" entry]

-- 
-- 
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/groups/opt_out.




Opinions on Equality Semantics

2013-04-08 Thread JvJ
This is just an idle curiosity up for discussion, but in Clojure, if (= a 
b) is true, then given some function f, it is not necessarily true that (= 
(f a) (f b))

For instance:

(defn check-eq
[f a b]
[(= a b)
(= (f a) (f b))])

(check-eq #(conj % 1) '(1 2 3) [1 2 3])
[true false]

Even though the behaviour of lists and vectors differs under specific 
functions, they still count as equal, but this statement "If a = b, then (f 
a) = (f b)" seems like it would be some sort of rule or axiom about 
functional programming.  What's the FP purists' view on this?



-- 
-- 
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/groups/opt_out.




Re: java.jdbc delta update examples

2013-04-08 Thread Sean Corfield
If you're using 0.3.0-alpha1, I think I'd recommend using native SQL
and the execute! function:

(j/execute! my-db "UPDATE employee SET SALARY = SALARY + 1000 WHERE
department = ?" [dept])

Sean

On Mon, Apr 8, 2013 at 1:31 PM, Craig  wrote:
>
> I am looking for example(s) of using clojure java.jdbc to perform delta
> update eg SALARY = SALARY + 1000. Links appreciated. Thanks.
>
> --
> --
> 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/groups/opt_out.
>
>



-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
-- 
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/groups/opt_out.




Re: Monads usage

2013-04-08 Thread Armando Blancas
Last week I released a project with a monadic translator that needed to:
- work on sequences of expressions, arbitrarily nested
- generate Clojure code or stop and report the first error
- maintain a symbol table with easy access but not global state

The relevant code is here:
https://github.com/blancas/eisen/blob/master/src/main/clojure/blancas/eisen/trans.clj

The code uses a StateT monad transformer and Either monad wrapped in five 
API functions: ->left, ->right, get-se, modify-se, run-se. Functions report 
errors with (->left); function (->right) wraps good values. The macro 
(monad) corresponds to Haskell's do; it chains monadic values or 
short-circuits and propagates errors.


(defn trans-binop
  "Translates the application of a binary operator."
  [ast]
  (monad [x (trans-expr (:left ast))
  y (trans-expr (:right ast))]
(let [f (-> ast :op :value str symbol)]
  (->right `(~f ~x ~y)


The symbol table is available through get-se and modify-se. A typical use 
case is to enter declared names, translate the expressions, then remove the 
names from the symbol table.

(defn trans-let
  "Translates a let expression."
  [{:keys [decls exprs]}]
  (let [env (map (comp symbol :name) decls)]
(monad [_ (modify-se into env)
decls (trans-bindings decls)
exprs (trans-exprs exprs)
_ (modify-se difference env)]
  (->right `(let [~@(apply concat decls)] ~@exprs)


To translate expressions in a sequence it uses the generic function (seqm); 
function (run-se) evaluates the resulting sequenced monads using an initial 
state "predefs". The result from (run-se) feeds (either) which evaluates to 
the first form on ->left and to the second on ->right.

(let [job (monad [v (seqm (map eval-ast coll))] (->right v))]
(either [res (run-se job predefs)]
  {:ok false :error res}
  {:ok true :decls (map first res) :value (-> res last second)})))


On Monday, April 8, 2013 7:56:35 AM UTC-7, Carlos Galdino wrote:
>
> Hi,
>
> I've been reading about monads for the past couple of weeks and I think I 
> got the idea, but I still don't know when to use it since I don't have 
> enough experience with functional programming.
>
> So, I'd like to ask you guys if you can point me to some examples of 
> Monads usage "in the wild". Because I've seen a lot of simple examples but 
> not a real one, used in a library, etc.
>
> Does anyone know a good example of real world usage?
>
> Thanks in advance.
>

-- 
-- 
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/groups/opt_out.




java.jdbc delta update examples

2013-04-08 Thread Craig

I am looking for example(s) of using clojure java.jdbc to perform delta 
update eg SALARY = SALARY + 1000. Links appreciated. Thanks.

-- 
-- 
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/groups/opt_out.




Re: Clojure is in GSoC 2013!

2013-04-08 Thread Laurent PETIT
Exciting times !
On Apr 8, 2013 9:35 PM, "David Nolen"  wrote:

> WOOT!
>
>
> On Mon, Apr 8, 2013 at 9:33 PM, Daniel Solano Gómez 
> wrote:
>
>> Hello, all,
>>
>> I am happy to report that Clojure has been accepted as a mentoring
>> organization for Google Summer of Code 2013.  Now is the time for
>> sudents to start researching their projects and reaching out to members.
>> At the same time, we need to start putting together an application
>> template for students.  I'll write more in the coming days.
>>
>> Sincerely,
>>
>> Daniel
>>
>
>  --
> --
> 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/groups/opt_out.
>
>
>

-- 
-- 
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/groups/opt_out.




Re: Clojure is in GSoC 2013!

2013-04-08 Thread David Nolen
WOOT!


On Mon, Apr 8, 2013 at 9:33 PM, Daniel Solano Gómez wrote:

> Hello, all,
>
> I am happy to report that Clojure has been accepted as a mentoring
> organization for Google Summer of Code 2013.  Now is the time for
> sudents to start researching their projects and reaching out to members.
> At the same time, we need to start putting together an application
> template for students.  I'll write more in the coming days.
>
> Sincerely,
>
> Daniel
>

-- 
-- 
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/groups/opt_out.




Clojure is in GSoC 2013!

2013-04-08 Thread Daniel Solano Gómez
Hello, all,

I am happy to report that Clojure has been accepted as a mentoring
organization for Google Summer of Code 2013.  Now is the time for
sudents to start researching their projects and reaching out to members.
At the same time, we need to start putting together an application
template for students.  I'll write more in the coming days.

Sincerely,

Daniel


signature.asc
Description: Digital signature


ANN Money 1.1.0 is released

2013-04-08 Thread Michael Klishin
ClojureWerkz Money [1] is a Clojure library for working with monetary
amounts
and currencies, built on top of Joda Money.

Release notes for 1.1.0:
http://blog.clojurewerkz.org/blog/2013/04/08/money-1-dot-1-0-is-released/

1. https://github.com/clojurewerkz/money
-- 
MK

http://github.com/michaelklishin
http://twitter.com/michaelklishin

-- 
-- 
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/groups/opt_out.




Re: [GSoC] Clojure refactoring library and integration in Counterclockwise

2013-04-08 Thread Laurent PETIT
2013/4/8 Michael Holzer :
> Hi everybody!
>
> I saw the project suggestion on the ideas page [0] and would be very
> interested to work on it.
>
> First a few words about me and my background:
> I'm from Graz, Austria, currently finishing up my studies in
> mathematical computer sciences and informatics. I've been playing around
> with Clojure for quite a while now, nothing big yet but I'm confident
> that I'm familiar enough with Clojure to tackle a project like this one.
> Last year I've worked on a similar project in Scala - the Scala
> Refactoring library [1] - implementing some refactorings and source
> generators and also doing the integration in the Scala Eclipse plugin
> [2], [3].
>
> I already contacted Laurent Petit about the project but haven't heard
> back from him yet.

Sorry, very busy ATM, will try to catch up with things before the end
of the week,


> Since the plan is to create an IDE-independent
> library I think that most of the work will take place outside the
> Counterclockwise plugin. Given that and that Laurent Petit already
> expressed his concern about the time needed for mentoring: would anyone
> be interested in mentoring this project? (Of course this doesn't mean
> that I wouldn't be perfectly happy if Laurent Petit decides to do the
> mentoring)
>
> And now to the part that will be hopefully of broader interest for every
> Clojure user:
> What do you expect from a refactoring library or from an IDE providing
> refactoring tools?
>
> Looking forward to your answers!
>
> Best regards,
> Michael Holzer
>
> [0]
> http://dev.clojure.org/display/community/Project+Ideas#ProjectIdeas-RefactoringfeatureforCCWotherIDEs
> [1] http://scala-refactoring.org/
> [2]
> http://scala-ide.org/docs/current-user-doc/features/typingviewing/refactoring/index.html#Method_signature_refactoring_new
> [3]
> http://scala-ide.org/docs/current-user-doc/features/typingviewing/source-generators/index.html
>
> --
> --
> 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/groups/opt_out.
>
>

-- 
-- 
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/groups/opt_out.




[GSoC] Clojure refactoring library and integration in Counterclockwise

2013-04-08 Thread Michael Holzer
Hi everybody!

I saw the project suggestion on the ideas page [0] and would be very
interested to work on it.

First a few words about me and my background:
I'm from Graz, Austria, currently finishing up my studies in
mathematical computer sciences and informatics. I've been playing around
with Clojure for quite a while now, nothing big yet but I'm confident
that I'm familiar enough with Clojure to tackle a project like this one.
Last year I've worked on a similar project in Scala - the Scala
Refactoring library [1] - implementing some refactorings and source
generators and also doing the integration in the Scala Eclipse plugin
[2], [3].

I already contacted Laurent Petit about the project but haven't heard
back from him yet. Since the plan is to create an IDE-independent
library I think that most of the work will take place outside the
Counterclockwise plugin. Given that and that Laurent Petit already
expressed his concern about the time needed for mentoring: would anyone
be interested in mentoring this project? (Of course this doesn't mean
that I wouldn't be perfectly happy if Laurent Petit decides to do the
mentoring)

And now to the part that will be hopefully of broader interest for every
Clojure user:
What do you expect from a refactoring library or from an IDE providing
refactoring tools?

Looking forward to your answers!

Best regards,
Michael Holzer

[0]
http://dev.clojure.org/display/community/Project+Ideas#ProjectIdeas-RefactoringfeatureforCCWotherIDEs
[1] http://scala-refactoring.org/
[2]
http://scala-ide.org/docs/current-user-doc/features/typingviewing/refactoring/index.html#Method_signature_refactoring_new
[3]
http://scala-ide.org/docs/current-user-doc/features/typingviewing/source-generators/index.html

-- 
-- 
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/groups/opt_out.




Re: Monads usage

2013-04-08 Thread Ben Wolfson
I don't know if this is adequately "in the wild" (since it's part of a
monad lib itself), but part of my monads library uses a continuation monad
to let two mutually recursive functions traverse and rebuild a tree
structure without blowing the stack. It would be a pain to do this kind of
thing by hand, since (unlike in the typical even/odd example where the
built-in trampoline function is simple to use) the recursive calls aren't
naturally written as tail calls. The use of a continuation monad
effectively results in the functions' being rewritten in CPS, and the
implementation does the trampolining for you:

https://github.com/bwo/monads/blob/master/src/monads/cont.clj#L62

--

(declare reorg-binds)

(defn- reorg-plus [m]
  (if-instance Mplus m
(let [l (.l m)
  r (.r m)]
  (mdo li <- (reorg-binds l)
   ri <- (reorg-binds r)
   ri <- (if-instance Mplus ri
   (let [lr (.l ri)]
 (if-instance Mplus lr
   (reorg-plus ri)
   (return ri)))
   (return ri))
   (if-instance Mplus li
 (let [l-l (.l li)]
   (mdo ri <- (reorg-plus ri)
(reorg-plus (Mplus. l-l (Mplus. (.r li) ri)
 (return (Mplus. li ri)
(return m)))

(defn- reorg-binds [m]
  (if-instance Bind m
(let [comp (.comp m)]
  (if-instance Bind comp
(let [i-comp (.comp comp)
  i-f (.f comp)
  f (.f m)]
  (mdo i <- (reorg-plus i-comp)
   (reorg-binds (Bind. i (fn [x] (Bind. (i-f x) f))
(mdo comp <- (reorg-plus comp)
 (return (Bind. comp (.f m))
(return m)))

(defn reorganize
  "Reorganize the monadic computation m so that binds nested on the
left are moved to the right, i.e. transform expressions like

(>>= (>>= (>>= m f) g) h)

into expressions like

(>>= m (fn [x] (>>= (f x) (fn [y] (>>= (g y) h).

A monad implementation for which these two expressions give
different results is broken.

Similarly reorganizes mplus operations nested on the left:

(mplus (mplus (mplus a b) c) d)

Becomes

(mplus a (mplus b (mplus c d))).

And, similarly, an mplus operation which is not associative is
considered to be in error.

Both transformations are interleaved:

(mplus (mplus (>>= (>>= (mplus (mplus a b) c) f) g) d) e)

becomes

(mplus (>>= (mplus a (mplus b c)) (fn [x] (>>= (f x) g))) (mplus d e)).

Note that *only* mplus and bind operations are investigated: the
reorganization does not recurse into the monadic-computation
arguments of e.g. listen, local, or pass."
  [m]
  ;; this reorg-plus is here in case we fall through reorg-binds right
  ;; away. We can't call reorg-plus in reorg-binds in the else branch
  ;; of the first if-instance, because it can lead to, yes, stack
  ;; overflows.
  (run-cont (reorg-plus (run-cont (reorg-binds m)

--





On Mon, Apr 8, 2013 at 7:56 AM, Carlos Galdino wrote:

> Hi,
>
> I've been reading about monads for the past couple of weeks and I think I
> got the idea, but I still don't know when to use it since I don't have
> enough experience with functional programming.
>
> So, I'd like to ask you guys if you can point me to some examples of
> Monads usage "in the wild". Because I've seen a lot of simple examples but
> not a real one, used in a library, etc.
>
> Does anyone know a good example of real world usage?
>
> Thanks in advance.
>
> --
> --
> 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/groups/opt_out.
>
>
>



-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure."
[Larousse, "Drink" entry]

-- 
-- 
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/gr

Re: Monads usage

2013-04-08 Thread Timothy Baldridge
oops, gen-plan was missing a helper function:

(defn- with-bind [id expr psym body]
  `(fn [~psym]
 (let [[~id ~psym] ( ~expr ~psym)]
   (assert ~psym "Nil plan")
   ~body)))



On Mon, Apr 8, 2013 at 9:32 AM, Timothy Baldridge wrote:

> I have a love/hate relationship with monads. I think their use in Clojure
> programming is much more limited than most would like to admit.
>
> However, I have found a very nice use for them: in my case, I'm attempting
> to insert a very complex AST into Datomic. I'd like all my data to go into
> Datomic as one large transaction (a vector of hashmaps). My first attempt
> at this code looked like this:
>
> Assume my data is:
>
> {:type :+
>  :arg0 {:type :const
>   :value 1}
>  :arg1 {:type :const
>   :value 2}
>
>
> Insert for the + node:
>
> (let [[arg0-id with-arg0] (insert-node (:arg0 this) plan)
>   [arg1-id with-arg1] (insert-node (:arg1 this) with-arg1)
>   [this-id with-this] (assert-entity {:arg0 arg0-id :arg1 arg1-od})]
>   [this-id with-this])
>
> So basically every single function has to return the last inserted id as
> well as a db tx plan that contains all items that need to be inserted. Not
> only is this code ugly, but I found it very error prone. Sometimes I would
> pass the wrong plan name in, and things would break. So I looked at this
> and said "why not use the state monad". So now insert-node looks like this:
>
> (insert-node [ent]
>   (fn [plan]
>  . do stuff .
>  [ent plan]))
>
>
> I created a monad binding function called "gen-plan":
>
> (defmacro gen-plan [binds id-expr]
>   (let [binds (partition 2 binds)
> psym (gensym "plan_")
> f (reduce
>(fn [acc [id expr]]
>  `(~(with-bind id expr psym acc)
>~psym))
>`[~id-expr ~psym]
>(reverse binds))]
> `(fn [~psym]
>~f)))
>
> And our example above looks like this:
>
> (gen-plan
>   [arg0-id (insert-node (:arg0 this))
>arg1-id (insert-node (:arg1 this))
>this-id (assert-entity {:arg0 arg0-id :arg1 arg1-id})]
>   this-id)
>
> Notice how the state monad makes the plan implicit.
>
> And now I can write super complex functions like this, without drowning in
> the code. Notice how this block (which generates a tx for writing a SSA
> style if expression to Datomic) is clear from any mentions of explicit
> state, but yet is remains completely functional.
>
> (gen-plan
>  [fnc (get-in-plan [:state :fn])
>
>   test-id (write-ssa test)
>   test-block (get-block)
>
>   pre-then-block (add-block fnc)
>   _ (set-block pre-then-block)
>   then-val (write-ssa then)
>   post-then-block (get-block)
>   then-terminated? (terminated? post-then-block)
>
>   pre-else-block (add-block fnc)
>   _ (set-block pre-else-block)
>   else-val (write-ssa else)
>   post-else-block (get-block)
>   else-terminated? (terminated? post-else-block)
>
>   merge-block (add-block fnc)
>   _ (set-block merge-block)
>   phi-val (add-phi)
>
>   _ (set-block test-block)
>   br-id (terminate-block :inst.type/br test-id pre-then-block
> pre-else-block)
>
>   _ (if then-terminated?
>   (no-op)
>   (gen-plan
>[_ (set-block post-then-block)
> _ (terminate-block :inst.type/jmp merge-block)
> _ (add-to-phi phi-val post-then-block then-val)]
>nil))
>
>   _ (if else-terminated?
>   (no-op)
>   (gen-plan
>[_ (set-block post-else-block)
> _ (terminate-block :inst.type/jmp merge-block)
> _ (add-to-phi phi-val post-else-block else-val)]
>nil))
>
>   _ (set-block merge-block)]
>  phi-val)
>
>
>
> So I look at this way, I see monads as a purely academic exercise 90% of
> the time. To try to go "whole hog" and apply them to every problem at hand
> is just nonsense. However, there are times (like in this example) where
> monads end up being the perfect tool for the job at hand. So I say, instead
> of looking at a problem and saying "what monad is this?" Instead, look at
> ugly code and say "hrm...I wonder if programming method X could make this
> cleaner". If that method is a monad, awesome!
>
> Timothy
>
>
>
> On Mon, Apr 8, 2013 at 8:56 AM, Carlos Galdino 
> wrote:
>
>> Hi,
>>
>> I've been reading about monads for the past couple of weeks and I think I
>> got the idea, but I still don't know when to use it since I don't have
>> enough experience with functional programming.
>>
>> So, I'd like to ask you guys if you can point me to some examples of
>> Monads usage "in the wild". Because I've seen a lot of simple examples but
>> not a real one, used in a library, etc.
>>
>> Does anyone know a good example of real world usage?
>>
>> Thanks in advance.
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure

Re: Monads usage

2013-04-08 Thread Timothy Baldridge
I have a love/hate relationship with monads. I think their use in Clojure
programming is much more limited than most would like to admit.

However, I have found a very nice use for them: in my case, I'm attempting
to insert a very complex AST into Datomic. I'd like all my data to go into
Datomic as one large transaction (a vector of hashmaps). My first attempt
at this code looked like this:

Assume my data is:

{:type :+
 :arg0 {:type :const
  :value 1}
 :arg1 {:type :const
  :value 2}


Insert for the + node:

(let [[arg0-id with-arg0] (insert-node (:arg0 this) plan)
  [arg1-id with-arg1] (insert-node (:arg1 this) with-arg1)
  [this-id with-this] (assert-entity {:arg0 arg0-id :arg1 arg1-od})]
  [this-id with-this])

So basically every single function has to return the last inserted id as
well as a db tx plan that contains all items that need to be inserted. Not
only is this code ugly, but I found it very error prone. Sometimes I would
pass the wrong plan name in, and things would break. So I looked at this
and said "why not use the state monad". So now insert-node looks like this:

(insert-node [ent]
  (fn [plan]
 . do stuff .
 [ent plan]))


I created a monad binding function called "gen-plan":

(defmacro gen-plan [binds id-expr]
  (let [binds (partition 2 binds)
psym (gensym "plan_")
f (reduce
   (fn [acc [id expr]]
 `(~(with-bind id expr psym acc)
   ~psym))
   `[~id-expr ~psym]
   (reverse binds))]
`(fn [~psym]
   ~f)))

And our example above looks like this:

(gen-plan
  [arg0-id (insert-node (:arg0 this))
   arg1-id (insert-node (:arg1 this))
   this-id (assert-entity {:arg0 arg0-id :arg1 arg1-id})]
  this-id)

Notice how the state monad makes the plan implicit.

And now I can write super complex functions like this, without drowning in
the code. Notice how this block (which generates a tx for writing a SSA
style if expression to Datomic) is clear from any mentions of explicit
state, but yet is remains completely functional.

(gen-plan
 [fnc (get-in-plan [:state :fn])

  test-id (write-ssa test)
  test-block (get-block)

  pre-then-block (add-block fnc)
  _ (set-block pre-then-block)
  then-val (write-ssa then)
  post-then-block (get-block)
  then-terminated? (terminated? post-then-block)

  pre-else-block (add-block fnc)
  _ (set-block pre-else-block)
  else-val (write-ssa else)
  post-else-block (get-block)
  else-terminated? (terminated? post-else-block)

  merge-block (add-block fnc)
  _ (set-block merge-block)
  phi-val (add-phi)

  _ (set-block test-block)
  br-id (terminate-block :inst.type/br test-id pre-then-block
pre-else-block)

  _ (if then-terminated?
  (no-op)
  (gen-plan
   [_ (set-block post-then-block)
_ (terminate-block :inst.type/jmp merge-block)
_ (add-to-phi phi-val post-then-block then-val)]
   nil))

  _ (if else-terminated?
  (no-op)
  (gen-plan
   [_ (set-block post-else-block)
_ (terminate-block :inst.type/jmp merge-block)
_ (add-to-phi phi-val post-else-block else-val)]
   nil))

  _ (set-block merge-block)]
 phi-val)



So I look at this way, I see monads as a purely academic exercise 90% of
the time. To try to go "whole hog" and apply them to every problem at hand
is just nonsense. However, there are times (like in this example) where
monads end up being the perfect tool for the job at hand. So I say, instead
of looking at a problem and saying "what monad is this?" Instead, look at
ugly code and say "hrm...I wonder if programming method X could make this
cleaner". If that method is a monad, awesome!

Timothy



On Mon, Apr 8, 2013 at 8:56 AM, Carlos Galdino wrote:

> Hi,
>
> I've been reading about monads for the past couple of weeks and I think I
> got the idea, but I still don't know when to use it since I don't have
> enough experience with functional programming.
>
> So, I'd like to ask you guys if you can point me to some examples of
> Monads usage "in the wild". Because I've seen a lot of simple examples but
> not a real one, used in a library, etc.
>
> Does anyone know a good example of real world usage?
>
> Thanks in advance.
>
> --
> --
> 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.

Monads usage

2013-04-08 Thread Carlos Galdino
Hi,

I've been reading about monads for the past couple of weeks and I think I 
got the idea, but I still don't know when to use it since I don't have 
enough experience with functional programming.

So, I'd like to ask you guys if you can point me to some examples of Monads 
usage "in the wild". Because I've seen a lot of simple examples but not a 
real one, used in a library, etc.

Does anyone know a good example of real world usage?

Thanks in advance.

-- 
-- 
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/groups/opt_out.




Re: Signing libraries on clojars

2013-04-08 Thread Mark Engelberg
When I do "lein deploy clojars", the tool hangs after reporting that it has
created the jar.

Any idea what might be causing it to hang?

On Fri, Apr 5, 2013 at 7:19 PM, Nelson Morris wrote:

> Yep.  There is an issue for making it work over scp, which the
> lein-clojars plugin uses, at
> https://github.com/ato/clojars-web/issues/118. Unfortunately the
> commits mentioning they "fix" it are incorrect.
>
> At the moment, `lein deploy clojars` is the way to send signatures.
> This command is built in to lein 2.x.
>
> -
> Nelson
>
> On Fri, Apr 5, 2013 at 8:35 PM, Phil Hagelberg  wrote:
> > I'm not sure Clojars supports sending signatures over scp yet. You might
> > need to do an HTTP deploy with `lein deploy`. The docs around this are a
> bit
> > scarce; sorry about that.
> >
> > Phil
> >
> > --
> > --
> > 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/groups/opt_out.
> >
> >
>
> --
> --
> 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/groups/opt_out.
>
>
>

-- 
-- 
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/groups/opt_out.




Re: java.lang.OutOfMemoryError when slurping lots of files?

2013-04-08 Thread Adrian Muresan
Thank you very much, that worked splendidly.


On Friday, April 5, 2013 5:14:30 PM UTC+2, Alex Nixon wrote:
>
> Java substrings prevent the original string from being garbage collected; 
> perhaps this also happens with regex matches?
>
> You can test the theory by surrounding the values in your map with 
> (String. ) and seeing if the problem goes away.
>
>
> On 5 April 2013 15:57, Adrian Muresan 
> > wrote:
>
>> Hello everyone,
>>
>> I'm trying to parse a large number of small reports for some data and I'm 
>> doing this by repeatedly calling the following function (with a for) on 
>> each of the files:
>>
>> (defn get-rep [file]
>> (let [report (with-open [rdr (io/reader file)](*slurp rdr*))
>>   reg #";\s+(\d+\.\d+) \s+; (\d+\.\d+) \s+;"
>>   match (re-matcher reg report)
>>   found (re-find match)
>>   fmax-85c (second found)
>>   rfmax-85c (nth found 2)
>>   found2 (re-find match)
>>   fmax-0c (second found2)
>>   rfmax-0c (nth found2 2)]
>>
>>   {:fmax-85c fmax-85c
>>   :rfmax-85c rfmax-85c
>>   :fmax-0c fmax-0c
>>   :rfmax-0c rfmax-0c}))
>>
>> My problem is that after a while my program crashes with a jvm heap 
>> error, it crashes on the slurp line (in bold), although that probably 
>> doesn't mean much. The slurp line is the only one that I suspect since it's 
>> the biggest memory consumer in my program.
>> Now I'm wondering what's going on and why don't the report files get 
>> freed from memory. I'm suspecting this might be caused by lazyness at some 
>> level, but I can't figure out where. Any ideas?
>>
>> Thanks!
>>
>> -- 
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> *Alex Nixon*
>
> Software Engineer | SwiftKey
>
> *al...@swiftkey.net ** | http://www.swiftkey.net/*
>
> ++
> WINNER - MOST INNOVATIVE MOBILE 
> APP
>  - GSMA GLOBAL MOBILE AWARDS 2012
>
> Head office: 91-95 Southwark Bridge Road, London, SE1 0AX TouchType is a 
> limited company registered in England and Wales, number 06671487. 
> Registered office: 91-95 Southwark Bridge Road, London, SE1 0AX
>  

-- 
-- 
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/groups/opt_out.