Re: Confusing interplay between macros and metadata

2011-11-09 Thread Marshall T. Vandegrift
Tassilo Horn tass...@member.fsf.org writes:

 I'm facing the same issue.  I have this macro for java interop:

 (defmacro with-traversal-context
   [[g tc]  body]
   `(let [old-tc# (.getTraversalContext ^Graph ~g)]
  (try
(.setTraversalContext ^Graph ~g ^TraversalContext ~tc)
~@body
(finally (.setTraversalContext ^Graph ~g ^TraversalContext old-tc#)

 But the type hints are gone in the macro expansion, thus I have 3
 reflection warnings per macro application, and real, performance
 critical reflection warnings get lost in the shuffle.

What you appear to be having is actually the different, but
conceptually-related problem of the metadata reader macro and unquote
operations interacting in a way which is consistent, but potentially not
optimal.  Fortunately in your sort of situation, you can work around the
problem by replacing the metadata reader macro with explicit metadata
operations.  Something like the following should work:

  (defn assoc-meta [x  kvs]
(with-meta x (apply assoc (meta x) kvs)))

  (defmacro with-traversal-context
[[g tc]  body]
(let [g (assoc-meta g :tag Graph)
  tc (assoc-meta tc :tag TraversalContext)]
  `(let [^TraversalContext old-tc# (.getTraversalContext ~g)]
 (try
   (.setTraversalContext ~g ~tc)
   ~@body
   (finally (.setTraversalContext ~g old-tc#))

-Marshall

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


(newbie) - first question - split list of maps into map of maps based on distinct values

2011-11-09 Thread Colin Yates
Hi all,

So finally I have managed to get to write some clojure.  Gotta say, after
two days I am seriously excited - talk about removing ceremony and focusing
on the issue.  I feel like a blind man performing surgery with welding
gloves on whilst holding this tiny but unbelievably powerful and mysterious
tool (compared to a seeing man performing surgery with welding gloves
expertly using the Java welding torch :)).  I have *so* much learning to do
around clojure (and choosing appropriate metaphors :)) - I love it!

Anyway, my first (of many) questions:

I have a vector of maps generated as a result of an outer-join.  I want to
convert that into a map of maps where the keys in the first map are the
distinct set of some key in vector of maps and the value is a vector of
maps that have that value.

For example, given:

[{:id 1, :name abc} {id:2 :name def} {id:1 :name xef}]

then coolFunctionWhichIsAlludingMe would return

{1 [{:id1 :name abc} {:id1 :name xef}] 2 [{id:2 :name def}]}

The context for this is if I do a select * from order join
order-line-items then I get a map from order to order-line-items.

I know this is 101 and I would be astonished if there wasn't a function
already in core to do this.  I have read a gazillion resources around
Clojure as well (a while ago) but it is all surface knowledge and doesn't
stick until I actually get down to using the tools, which is happening now.
 (I am sort-of apologising for taking up traffic with such a ridiculously
simple question :)).

Thanks!

Col

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

Re: (newbie) - first question - split list of maps into map of maps based on distinct values

2011-11-09 Thread Colin Yates
Sometimes the answer is just too simple: group-by

(see the last post 
on 
http://stackoverflow.com/questions/3052162/coverting-a-vector-of-maps-to-map-of-maps-in-clojure)

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

Re: Confusing interplay between macros and metadata

2011-11-09 Thread Tassilo Horn
Marshall T. Vandegrift llas...@gmail.com writes:

Hi Marshall,

 I'm facing the same issue.  I have this macro for java interop:

 (defmacro with-traversal-context
   [[g tc]  body]
   `(let [old-tc# (.getTraversalContext ^Graph ~g)]
  (try
(.setTraversalContext ^Graph ~g ^TraversalContext ~tc)
~@body
(finally (.setTraversalContext ^Graph ~g ^TraversalContext 
 old-tc#)

 But the type hints are gone in the macro expansion, thus I have 3
 reflection warnings per macro application, and real, performance
 critical reflection warnings get lost in the shuffle.

 What you appear to be having is actually the different, but
 conceptually-related problem of the metadata reader macro and unquote
 operations interacting in a way which is consistent, but potentially
 not optimal.  Fortunately in your sort of situation, you can work
 around the problem by replacing the metadata reader macro with
 explicit metadata operations.

Yes, that would probably do the trick.  But on IRC, Alan already gave me
this recipe (gensyming the given parameter g) which is even a bit
shorter.

--8---cut here---start-8---
(defmacro with-traversal-context
  [[g tc]  body]
  `(let [^Graph g# ~g
 ^TraversalContext old-tc# (.getTraversalContext g#)]
 (try
   (.setTraversalContext g# ~tc)
   ~@body
   (finally (.setTraversalContext g# old-tc#)
--8---cut here---end---8---

-- 
(What the world needs (I think) is not
  (a Lisp (with fewer parentheses))
  but (an English (with more.)))
Brian Hayes, http://tinyurl.com/3y9l2kf

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


Multiple try via macro

2011-11-09 Thread Michael Jaaka
Hi!

I would like to write macro, which tries to evalute one of statements.
If exception happens the next statement is taken, if not then rest of
expressions execution is stopped.

(defmacro try-this[  body ]
`(if (seq ~body)
(try
~(first body)
(catch Exception e# (try-this ~(rest body
(throw (Exception. nothing succeed

(try-this
(/ 2 0)
(+ 2 3)
(println 2))


So the macro should expand to something like this:


(try
(/ 2 0)
(catch Exception e
(try (+ 2 3)
(catch Exception e
(try (println 2)
(catch Exception e  (Exception. 
nothing succeed)))

Any help?

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


ANN: Fughetta 0.0.1

2011-11-09 Thread sebastiansen
Releasing first versioned Fughettahttps://github.com/Sebastiansen/fughetta 
project 
with new functions and arrangements.

Enjoy!

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

Re: `conj` into maps

2011-11-09 Thread Stuart Sierra
It may relate to the implementation of IPersistentCollection.cons(Object). 

As far as I know, the IPersistentCollection.cons(Object) method powers the 
polymorphic behavior of the `conj` function, and is the foundation for the 
persistent collections in general.

-S

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

Re: Multiple try via macro

2011-11-09 Thread Stuart Halloway
 Hi!
 
 I would like to write macro, which tries to evalute one of statements.
 If exception happens the next statement is taken, if not then rest of
 expressions execution is stopped.
 
 (defmacro try-this[  body ]
   `(if (seq ~body)
   (try
   ~(first body)
   (catch Exception e# (try-this ~(rest body
   (throw (Exception. nothing succeed
 
 (try-this
   (/ 2 0)
   (+ 2 3)
   (println 2))
 
 
 So the macro should expand to something like this:
 
 
 (try
   (/ 2 0)
   (catch Exception e
   (try (+ 2 3)
   (catch Exception e
   (try (println 2)
   (catch Exception e  (Exception. 
 nothing succeed)))
 
 Any help?


Something like:

(defmacro try-this
  [ forms]
  (loop [[f  more] forms]
(when f
  `(try
~f
(catch Throwable t#
  (try-this ~@more))

Stu

Stuart Halloway
Clojure/core
http://clojure.com

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

Re: form-zip

2011-11-09 Thread George Jahad
I see your point.  Still it seems odd that the default zipper
generating function isn't one that understands the big 4 clojure
datastructures.


On Nov 8, 8:04 pm, Alan Malloy a...@malloys.org wrote:
 They have a different make-node function, so that when you edit a
 vector-zip you get vectors instead of something else. It's also easy
 to imagine your data units are simple vectors, grouped together in
 some kind of list structure. Then you would want the zipper to tell
 you hey, this node is a leaf for vectors - thus seq-zip.

 On Nov 8, 7:21 pm, George Jahad cloj...@blackbirdsystems.net wrote:

  Now that I think of it, why are seq-zip and vector-zip separate
  functions?  Why not a single function that handles both seq and
  vectors, and sets and maps too?

  What am I missing?

  On Nov 1, 8:56 pm, George Jahad cloj...@blackbirdsystems.net wrote:

   surely this one's been written before, but i needed it the other day
   and couldn't find it.

   form-zip returns a zipper from a clojure form.

   user= (require '[clojure.zip :as zip])
   user= (use 'form-zip.core)
   user= (- '{1 2 3 4} form-zip  zip/next zip/remove zip/root)
   {3 4}

   fz-node-seq returns a seq of the nodes.

   user= (fz-node-seq '{1 2 3 4})
   ({1 2, 3 4} [1 2] 1 2 [3 4] 3 4)

   a one hour hack, probably full of edge cases i haven't thought of.

   on clojars and github:https://github.com/GeorgeJahad/form-zip



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


Re: Multiple try via macro

2011-11-09 Thread Michael Jaaka
Thank you.

Is loop and not for example let, for recursion optimalization?

On Nov 9, 2:51 pm, Stuart Halloway stuart.hallo...@gmail.com wrote:
  Hi!

  I would like to write macro, which tries to evalute one of statements.
  If exception happens the next statement is taken, if not then rest of
  expressions execution is stopped.

  (defmacro try-this[  body ]
     `(if (seq ~body)
                     (try
                             ~(first body)
                             (catch Exception e# (try-this ~(rest body
                     (throw (Exception. nothing succeed

  (try-this
     (/ 2 0)
     (+ 2 3)
     (println 2))

  So the macro should expand to something like this:

  (try
     (/ 2 0)
     (catch Exception e
             (try (+ 2 3)
                     (catch Exception e
                             (try (println 2)
                                     (catch Exception e  (Exception. nothing 
  succeed)))

  Any help?

 Something like:

 (defmacro try-this
   [ forms]
   (loop [[f  more] forms]
     (when f
       `(try
         ~f
         (catch Throwable t#
           (try-this ~@more))

 Stu

 Stuart Halloway
 Clojure/corehttp://clojure.com

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


Re: Dynamic test creation?

2011-11-09 Thread AndyK
Questions about tabular tests...
* can they take a lazy-seq as input?
* will the tests be parallelized? (i have anywhere from 10k-20k tests
to run)

On Nov 8, 4:16 pm, Alex Baranosky alexander.barano...@gmail.com
wrote:
 Sounds lile you could use Midje's tabular tests.  Or if you want write a
 acro to generate a tabular fact.  Tje tabular fact will give you good
 reporting.
 On Nov 8, 2011 1:44 PM, AndyK andy.kri...@gmail.com wrote:







  I finally had a chance to try this out and it fails with

  error: java.lang.ClassCastException: java.lang.String cannot be cast
  to clojure.lang.IObj
  Compilation failed.

  When I substituted in something like this...

  (defn prn-form [n scenario]
   `(prn ~(str foo n) (prn ~(str n  ::  scenario

  the file did compile.

  Is the fact that deftest is also a macro going to cause a problem with
  the original idea?

  On Nov 2, 8:36 am, Nate Young youn...@gmail.com wrote:
   On 11/01/2011 03:05 PM, AndyK wrote:

How would (run-tests 'my-namespace) know to run all thosedynamic
tests? I thought that it parsed the namespace for 'my-namespace when
you call it. Or is it that the call to defcsvtests sets off a chain of
macro resolutions before run-tests can even do its thing (so that it

   Right. Its that the macro-expansion phase actually reads from the csv
   file in order to create a number of deftest forms, and each one then
   gets evaluated, so after you've evaluated (defcsvtests), then
   (run-tests) will be able to find a number of tests to run.

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


Re: form-zip

2011-11-09 Thread George Jahad


 (fz-node-seq x) is just (tree-seq coll? seq x)

Good Point! I had never noticed the parallels between tree-seq and
zippers, but it's obvious when you point it out.  Thanks for
mentioning that.

 (personally I don't have enough experience to be comfortable with
  them),

yeah, i haven't found a great use case for zippers yet either.  but
lately I've been experimenting with using them to write more readable
code transforms.  hence the need for form-zip.

Like clojure.walk, but with the ability to backtrack.


 fz-node-seq doesn't seem useful.

Ouch!  Ok, here's one that is.  As you astutely noted above,
fz-node-seq is functionally equivalent to (tree-seq coll? seq x), but
what's interesting about it is, it is implemented like so:
   (map zip/node (fz-loc-seq form))

What's useful there is the call to fz-loc-seq which provides
a seq of every zipper loc in the form.  Useful again for code
transforms, I think.

Thanks again for exercising my brain cells.  I haven't forgotten that
beer I owe you.



On Nov 8, 8:06 pm, Alan Malloy a...@malloys.org wrote:
 (fz-node-seq x) is just (tree-seq coll? seq x) then, yeah? I could see
 form-zip being useful for people who like zippers (personally I don't
 have enough experience to be comfortable with them), but fz-node-seq
 doesn't seem useful.

 On Nov 1, 8:56 pm, George Jahad cloj...@blackbirdsystems.net wrote:

  surely this one's been written before, but i needed it the other day
  and couldn't find it.

  form-zip returns a zipper from a clojure form.

  user= (require '[clojure.zip :as zip])
  user= (use 'form-zip.core)
  user= (- '{1 2 3 4} form-zip  zip/next zip/remove zip/root)
  {3 4}

  fz-node-seq returns a seq of the nodes.

  user= (fz-node-seq '{1 2 3 4})
  ({1 2, 3 4} [1 2] 1 2 [3 4] 3 4)

  a one hour hack, probably full of edge cases i haven't thought of.

  on clojars and github:https://github.com/GeorgeJahad/form-zip



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


Re: Multiple try via macro

2011-11-09 Thread Meikel Brandmeyer (kotarak)
Hi,

the loop is unnecessary in this case. You can just as well use let.

And you may want to use an if with the (throw (Exception. nothing 
succeeded)) instead of the when.

Sincerely
Meikel

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

Re: `conj` into maps

2011-11-09 Thread Chas Emerick
Right, a collection can implement cons however it likes.  While it's 
convenient, I was just curious about the 'why' of APersistentMap's 
implementation, esp. since it overlaps w/ `merge`.

- Chas

On Nov 9, 2011, at 8:28 AM, Stuart Sierra wrote:

 It may relate to the implementation of IPersistentCollection.cons(Object). 
 
 As far as I know, the IPersistentCollection.cons(Object) method powers the 
 polymorphic behavior of the `conj` function, and is the foundation for the 
 persistent collections in general.
 
 -S
 
 -- 
 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 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

Re: SQL Korma Missing Pred

2011-11-09 Thread Dennis Crenshaw
So it does, 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

Re: Multiple try via macro

2011-11-09 Thread Stuart Halloway
 Thank you.
 
 Is loop and not for example let, for recursion optimalization?

The primary purpose of the loop in this example is to indicate the local time 
where I am and therefore the absence of Mountiain Dew in my bloodstream. :-)

Stu


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


Re: using sqlite3

2011-11-09 Thread willyh
project.clj:
---
(defproject testsqlite 1.0.0-SNAPSHOT
  :description FIXME: write description
  :disable-deps-clean false
  :dependencies [[org.clojure/clojure 1.3.0]
 [org.clojure/clojure-contrib 1.2.0]
 [org.clojure/java.jdbc 0.1.0]
 [org.xerial/sqlite-jdbc 3.7.2]]
  :main testsqlite.core)

core.clj:
---
(ns testsqlite.core
  (:import [java.io File])
  (:require [clojure.java.jdbc :as sql])
  (:gen-class))

(def db-name test.db)

(def db {
 :classname org.sqlite.JDBC
 :subprotocol sqlite; Protocol to use
 :subname db-name; Location of the db
 })

(def new-db-conn (merge db {:create true}))

(defn create-tables
 Creates the tables needed.
 []
 (sql/create-table
  :members
  [:id :integer PRIMARY KEY]
  [:name varchar(32)]
  [:age :integer]
  [:programmer tinyint]))


(defn insert-record
  [name age programmer?]
  (sql/insert-values
   :members
   [:name
:age
:programmer]
   [name
age
programmer?]))


(defn get-records
  [record-fn]
  (sql/with-query-results
rs
[select * from members]
(doseq [r rs]
  (record-fn r

(defn delete-record
  [id]
  (sql/delete-rows :members [id = ? id]))

(defn -main
  [ args]
  (when (not (.exists (File. db-name)))
(sql/with-connection new-db-conn
  (create-tables)))
  (cond (= (nth args 0) insert)
(sql/with-connection db
  (insert-record (nth args 1)
 (Integer/parseInt (nth args 2))
 (Integer/parseInt (nth args 3
(= (nth args 0) dump)
(sql/with-connection db
  (get-records println))
(= (nth args 0) delete)
(sql/with-connection db
  (delete-record (Integer/parseInt (nth args 1
)
  )


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

Re: using sqlite3

2011-11-09 Thread willyh
Use this project.clj instead (eliminating the reference to clojure-contrib):
(defproject testsqlite 1.0.0-SNAPSHOT
  :description FIXME: write description
  :disable-deps-clean false
  :dependencies [[org.clojure/clojure 1.3.0]
 [org.clojure/java.jdbc 0.1.0]
 [org.xerial/sqlite-jdbc 3.7.2]]
  :main testsqlite.core)


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

Re: Dynamic test creation?

2011-11-09 Thread Brian Marick

On Nov 9, 2011, at 8:37 AM, AndyK wrote:

 Questions about tabular tests...
 * can they take a lazy-seq as input?

Do you mean something like having a computation that generates a stream of test 
inputs and feeds them into a test evaluator? If so, no: all `tabular's` work 
happens at compile/macroexpansion time.

However, the underlying test-execution-and-reporting function is available and 
takes test descriptions as maps, so you could do something like

  (map midje.unprocessed/expect* (source-of-test-maps))

 * will the tests be parallelized? (i have anywhere from 10k-20k tests
 to run)

The code doesn't make any effort to parallelize tests. Tests are normally run 
as they're encountered at load time. (Unlike clojure.test, the `fact` macro 
doesn't stash a test-function away for later execution.)

A test runner like the above should be parallelizable, though I didn't make any 
special effort to ensure that. The default reporter just prints results. You'd 
probably want one that stashes them away in an atom as they come in. There's 
already a way to swap in different reporters, so that shouldn't be too hard. 

More discussion should probably happen at http://groups.google.com/group/midje


-
Brian Marick, Artisanal Labrador
Now working at http://path11.com
Contract programming in Ruby and Clojure
Occasional consulting on Agile


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


Re: NullPointerException in c.l.Compiler.lookupVar after aot compilation: means what?

2011-11-09 Thread Brian Marick

On Nov 8, 2011, at 6:44 PM, Stuart Halloway wrote:

 Line 4 of midje.util.report is unusual in several ways:  it precedes the ns 
 call, adds a second ns call, does an eval, and uses def forms not at the top 
 level:

Thanks, Stu. That code was a patch that came in when I was new to Clojure, and 
I didn't understand it. I think it was a workaround for something in Clojure 
1.1. I bet I can figure it out now.

-
Brian Marick, Artisanal Labrador
Now working at http://path11.com
Contract programming in Ruby and Clojure
Occasional consulting on Agile


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


Clojure on the reversim podcast

2011-11-09 Thread ronen
Iv been hosted on reversim (an Israeli software podcast) for a talk
about Clojure,

The talk is in Hebrew: http://www.reversim.com/

Ronen

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


core.logic questions

2011-11-09 Thread Mark
I'm working through the core.logic examples on http://objectcommando.com.  
I want to develop a query that returns the child and his parents.  The 
gives me what I want:
(run* [q]
 (fresh [m f c]
(== c 'Sonny)
(parent m c)
(parent f c)
(!= m f)
(== q {:child c :parents [m f]})))

I'd like to create a re-usable function for parent-of, so I have:
(defn parents-of [m f c]
  (parent m c)
  (parent f c)
  (!= m f))

(run* [q]
 (fresh [m f c]
(== c 'Sonny)
(parents-of m f c)
(== q {:child c :parents [m f]})))
produces ({:child Sonny, :parents [_.0 _.1]})

I'm obviously missing something about what I'm actually defining in the 
defn but I'm struggling to figure out what it is.

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

REPL magic: get the previous expression?

2011-11-09 Thread nchurch
Does anyone know how to programmatically get the previous expression
entered at the REPL?  You can get it interactively by pressing the up-
arrow key; and of course you can get the previous \result through the
variable *1.  Is there any similar variable or function (perhaps in
Java-land) that would give you the previous \expression?

Thanks,

Nick.

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


Re: core.logic questions

2011-11-09 Thread David Nolen
Functions that are going to be used in core logic must return goals.

(defn parents-of [m f c]
   (parent m c)
   (parent f c)
   (!= m f))


In this case you only return the (!= m f) subgoal instead of the goal that
represents the conjunction of all three subgoals.

(defn parents-of [m f c]
  (all
(parent m c) (parent f c)
(!= m f)))

Is probably what you want. Untested.

David

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

Open source Clojure projects

2011-11-09 Thread Zack Maril
For many of the older languages I look at, there are big open source 
projects that people are working on that are making a big impact. C has 
linux, Javascript has jQuery and Khan Academy's frameworks, Java has their 
libraries, etc. etc. 

Are there any Clojure projects I could contribute to?

I know new ideas are being developed all the time, I can see them cropping 
up on here everyday. It seems like by the time I hear about it, they are 
implemented already and most of the bugs have been sussed out though. 
Besides hacking on clojure itself, there doesn't seem like there are any 
projects I could add to (and I would have to learn way more to be able to 
contribute anything useful with the clojure code). 
-Zack

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

Re: Open source Clojure projects

2011-11-09 Thread Ulises
Whenever I see a question like this asked anywhere (and even when I
ask the question to myself or others) I usually recommend reading (or
read myself): http://prog21.dadgum.com/80.html

:)

U

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


sqlitejdbc jar on clojars

2011-11-09 Thread labwork07
sqlite3 had some problems but a later version (3.7.9) seems to work. Now  
the sqlitejdbc jar on clojars version 0.5.6 has the same problems as the  
old sqlite3 command line. Basically, I get this error below when reading  
certain .sqlite files. Is there a latest version of the sqlitejdcb driver  
for clojure?

cljstudent.sqlite= (get-data)
java.sql.SQLException: file is encrypted or is not a database  
(NO_SOURCE_FILE:0


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

Re: REPL magic: get the previous expression?

2011-11-09 Thread Michael Beattie
What do you mean?  If it's programatically then why not use a loop or 
something?

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

Re: `conj` into maps

2011-11-09 Thread Stuart Sierra
I expect you're right: it's vestigial.
-S

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

Re: sqlitejdbc jar on clojars

2011-11-09 Thread willyh
I'm using the sqlite-jdbc jar from a maven repository. I use this in
my leiningen project to fetch it:

[org.xerial/sqlite-jdbc 3.7.2]

I haven't had any issues with it, but that doesn't mean you won't.


On Nov 9, 12:50 pm, labwor...@gmail.com wrote:
 sqlite3 had some problems but a later version (3.7.9) seems to work. Now
 the sqlitejdbc jar on clojars version 0.5.6 has the same problems as the
 old sqlite3 command line. Basically, I get this error below when reading
 certain .sqlite files. Is there a latest version of the sqlitejdcb driver
 for clojure?
 cljstudent.sqlite= (get-data)
 java.sql.SQLException: file is encrypted or is not a database
 (NO_SOURCE_FILE:0

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


Re: REPL magic: get the previous expression?

2011-11-09 Thread nchurch
I mean I want to write a utility that has access to the previous
expression entered at the REPL no matter where this utility is
called.  Since the up-arrow key has this access, it must be
possible

On Nov 9, 12:57 pm, Michael Beattie mtbee...@gmail.com wrote:
 What do you mean?  If it's programatically then why not use a loop or
 something?

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


Re: REPL magic: get the previous expression?

2011-11-09 Thread Chas Emerick
The up-arrow key can recall the expressions you send thanks to either readline 
or Leiningen.  You might be able to hook the appropriate var in leiningen.repl 
in order to slip your own function into the options passed to the Clojure REPL 
it starts.

You need to be able to intercept the form being evaluated so you can store it 
off somewhere (either in a var via set! or otherwise).

Interesting idea.  Maintaining command history on the server side of the REPL 
(i.e. more than just having *!1, *!2, *!3 [or whatever]) might have some good 
use cases in general.

- Chas

On Nov 9, 2011, at 1:25 PM, nchurch wrote:

 I mean I want to write a utility that has access to the previous
 expression entered at the REPL no matter where this utility is
 called.  Since the up-arrow key has this access, it must be
 possible
 
 On Nov 9, 12:57 pm, Michael Beattie mtbee...@gmail.com wrote:
 What do you mean?  If it's programatically then why not use a loop or
 something?
 
 -- 
 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 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


Re: NullPointerException in c.l.Compiler.lookupVar after aot compilation: means what?

2011-11-09 Thread Brian Marick

On Nov 8, 2011, at 8:47 PM, Alan Malloy wrote:
 (let [ns-obj (the-ns (doto 'clojure.test require))
   the-var (intern ns-obj 'old-report)]
   (when-not (.hasRoot the-var)
 (intern ns-obj 'old-report clojure.test/report)))
 
 Seems to have the same effect as the defonce in some simple testing.
 
 Of course it's silly to use intern the second time: (.setRoot the-var
 clojure.test/report) would have been simpler. 

Thank you. You've made a user happy.

(You meant .bindRoot rather than .setRoot, right?)


-
Brian Marick, Artisanal Labrador
Now working at http://path11.com
Contract programming in Ruby and Clojure
Occasional consulting on Agile


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


Re: Open source Clojure projects

2011-11-09 Thread Chris Perkins
There are lots.  You could start browsing from here:  
https://github.com/languages/Clojure

- Chris

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

Re: Dynamic test creation?

2011-11-09 Thread Nate Young
On 11/08/2011 12:44 PM, AndyK wrote:
 I finally had a chance to try this out and it fails with
 
 error: java.lang.ClassCastException: java.lang.String cannot be cast
 to clojure.lang.IObj
 Compilation failed.
I think I fat-fingered my deftest-form definition:

I originally wrote:
(defn testdef-form [n [expected actual]]
  `(deftest ~(str testfromline n)
 (is (= ~expected ~actual

But it should probably be:
(defn testdef-form [n [expected actual]]
  `(deftest ~(symbol (str testfromline n))
 (is (= ~expected ~actual

The original, wrong, function would have produced something like this:
(deftest testfromline27
  (is (= 5 2)))

Which is probably what's giving you the error message you're seeing.
That string should be a symbol:
(deftest testfromline27
  (is (= 5 2)))

 When I substituted in something like this...
 
 (defn prn-form [n scenario]
   `(prn ~(str foo n) (prn ~(str n  ::  scenario
 
 the file did compile.
I'd have to see the rest of your code to comment on what's going on here.

 Is the fact that deftest is also a macro going to cause a problem with
 the original idea?
Macros certainly have composability issues, but its certainly safe to
write a macro that produces some other macro form. In fact, lots of
clojure.core macros use this to great effect (affect?), see -, cond,
or, and .. to name a few.

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


Re: Re: sqlitejdbc jar on clojars

2011-11-09 Thread labwork07
Thanks but I am not getting anything with it. Here's what I have. Does it  
seem correct?


(ns cljstudent.sqlite
(:require [clojure.contrib.sql :as sql]))


;; need this to load the sqlite3 driver (as a side effect of evaluating the  
expression)

;;(Class/forName org.sqlite.JDBC)

(def db-path /home/melipone/cljstudent/places.sqlite)
(def db-specs {:classname org.sqlite.JDBC,
:subprotocol sqlite,
:subname db-path})

(def db-query select * from moz_places where visit_count  100)

(defn get-data []
(sql/with-connection db-specs
(sql/with-query-results results [db-query]
(doall results





On , willyh wheine...@gmail.com wrote:

I'm using the sqlite-jdbc jar from a maven repository. I use this in



my leiningen project to fetch it:





[org.xerial/sqlite-jdbc 3.7.2]





I haven't had any issues with it, but that doesn't mean you won't.







On Nov 9, 12:50 pm, labwor...@gmail.com wrote:



 sqlite3 had some problems but a later version (3.7.9) seems to work. Now



 the sqlitejdbc jar on clojars version 0.5.6 has the same problems as the



 old sqlite3 command line. Basically, I get this error below when reading


 certain .sqlite files. Is there a latest version of the sqlitejdcb  
driver



 for clojure?



 cljstudent.sqlite= (get-data)



 java.sql.SQLException: file is encrypted or is not a database



 (NO_SOURCE_FILE:0





--



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

Re: Re: sqlitejdbc jar on clojars

2011-11-09 Thread labwork07

Sorry, I had my query wrong. This driver does work now. Thanks!

On , willyh wheine...@gmail.com wrote:

I'm using the sqlite-jdbc jar from a maven repository. I use this in



my leiningen project to fetch it:





[org.xerial/sqlite-jdbc 3.7.2]





I haven't had any issues with it, but that doesn't mean you won't.







On Nov 9, 12:50 pm, labwor...@gmail.com wrote:



 sqlite3 had some problems but a later version (3.7.9) seems to work. Now



 the sqlitejdbc jar on clojars version 0.5.6 has the same problems as the



 old sqlite3 command line. Basically, I get this error below when reading


 certain .sqlite files. Is there a latest version of the sqlitejdcb  
driver



 for clojure?



 cljstudent.sqlite= (get-data)



 java.sql.SQLException: file is encrypted or is not a database



 (NO_SOURCE_FILE:0





--



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

Re: REPL magic: get the previous expression?

2011-11-09 Thread nchurch
My particular use-case was to be able to write tests for things
entered at the REPL.  I'm almost done with a basic version of it and
will post it to the list when done.  It would be much easier if the
expressions were there anyway.  I guess the issue is that people may
not always be using Lein or Readline; they may be in Eclipse,
Netbeans, etc., which have their own REPLS.  Considering all that it
might make sense to just ask the user to launch a subrepl, which would
be both more robust and easier to implement.

I did look at lein.repl, thanks for the pointer!

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


Re: Creating a var, functions from a macro

2011-11-09 Thread Sean Bowman
Apparently the missing bit is I need to escape the symbol calls,
e.g.

(defn ~(symbol index) ...

Is this correct?

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


All subsets of a vector

2011-11-09 Thread Shoeb Bhinderwala
Is there a more elegant/idomatic way to achieve the following result:

user= a1
[a b c d]

user= (map-indexed (fn [n x] (vec (take (inc n) x))) (take (count a1)
(repeat a1)))
([a] [a b] [a b c] [a b c d])

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


Re: All subsets of a vector

2011-11-09 Thread Linus Ericsson
(map #(vec (take (inc %) a1)) (range (count a1)))

does it the lovely map.

/Linus

2011/11/9 Shoeb Bhinderwala shoeb.bhinderw...@gmail.com

 Is there a more elegant/idomatic way to achieve the following result:

 user= a1
 [a b c d]

 user= (map-indexed (fn [n x] (vec (take (inc n) x))) (take (count a1)
 (repeat a1)))
 ([a] [a b] [a b c] [a b c d])

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

Re: NullPointerException in c.l.Compiler.lookupVar after aot compilation: means what?

2011-11-09 Thread Stuart Halloway
 Line 4 of midje.util.report is unusual in several ways:  it precedes the ns 
 call, adds a second ns call, does an eval, and uses def forms not at the top 
 level:
 
 Thanks, Stu. That code was a patch that came in when I was new to Clojure, 
 and I didn't understand it. I think it was a workaround for something in 
 Clojure 1.1. I bet I can figure it out now.

Let me know if you don't find a workaround -- I would still like to understand 
that NPE.

Stu

Stuart Halloway
Clojure/core
http://clojure.com

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

Re: problems of a newbie

2011-11-09 Thread Alex Baranosky
Very hard question to answer.  It makes sense that static typing would
help, but in practice I never seem to get defects that are related to
types.  Ergo, Clojure's approach to typing works well, and the code stays
very minimalist.
On Nov 8, 2011 12:52 AM, Sean Corfield seancorfi...@gmail.com wrote:

 On Mon, Nov 7, 2011 at 4:20 AM, Dennis Haupt d.haup...@googlemail.com
 wrote:
  which is a good thing. type safety is good.

 Is it?
 --
 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 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

Re: All subsets of a vector

2011-11-09 Thread Alex Baranosky
Does Clojure have the equivalent of Haskell's 'scan' function? (I am on my
phone...) Seems like a solution with that would be nice. (scan is like
reduce except it keeps all intermediate results)
On Nov 9, 2011 5:57 PM, Linus Ericsson oscarlinuserics...@gmail.com
wrote:

 (map #(vec (take (inc %) a1)) (range (count a1)))

 does it the lovely map.

 /Linus

 2011/11/9 Shoeb Bhinderwala shoeb.bhinderw...@gmail.com

 Is there a more elegant/idomatic way to achieve the following result:

 user= a1
 [a b c d]

 user= (map-indexed (fn [n x] (vec (take (inc n) x))) (take (count a1)
 (repeat a1)))
 ([a] [a b] [a b c] [a b c d])

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

Re: All subsets of a vector

2011-11-09 Thread Benny Tsai
Another way to do it, using 'reductions':

(rest (reductions conj [] a1))

On Wednesday, November 9, 2011 5:47:08 PM UTC-5, Shoeb Bhinderwala wrote:

 Is there a more elegant/idomatic way to achieve the following result: 

 user= a1 
 [a b c d] 

 user= (map-indexed (fn [n x] (vec (take (inc n) x))) (take (count a1) 
 (repeat a1))) 
 ([a] [a b] [a b c] [a b c d]) 


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

Re: All subsets of a vector

2011-11-09 Thread Benny Tsai
That's exactly what 'reductions' does :)

On Wednesday, November 9, 2011 6:09:08 PM UTC-5, Alex Baranosky wrote:

 Does Clojure have the equivalent of Haskell's 'scan' function? (I am on my 
 phone...) Seems like a solution with that would be nice. (scan is like 
 reduce except it keeps all intermediate results)
 On Nov 9, 2011 5:57 PM, Linus Ericsson oscarlinu...@gmail.com wrote:

 (map #(vec (take (inc %) a1)) (range (count a1)))

 does it the lovely map.

 /Linus

 2011/11/9 Shoeb Bhinderwala shoeb.bh...@gmail.com

 Is there a more elegant/idomatic way to achieve the following result:

 user= a1
 [a b c d]

 user= (map-indexed (fn [n x] (vec (take (inc n) x))) (take (count a1)
 (repeat a1)))
 ([a] [a b] [a b c] [a b c d])

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

Re: NullPointerException in c.l.Compiler.lookupVar after aot compilation: means what?

2011-11-09 Thread Brian Marick

On Nov 9, 2011, at 4:58 PM, Stuart Halloway wrote:

 Line 4 of midje.util.report is unusual in several ways:  it precedes the ns 
 call, adds a second ns call, does an eval, and uses def forms not at the 
 top level:
 
 Thanks, Stu. That code was a patch that came in when I was new to Clojure, 
 and I didn't understand it. I think it was a workaround for something in 
 Clojure 1.1. I bet I can figure it out now.
 
 Let me know if you don't find a workaround -- I would still like to 
 understand that NPE.

It's all better now. Alan Malloy's fix worked fine on Clojure 1.2.1 and 1.3.


-
Brian Marick, Artisanal Labrador
Now working at http://path11.com
Contract programming in Ruby and Clojure
Occasional consulting on Agile


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


Re: All subsets of a vector

2011-11-09 Thread Alex Baranosky
Dang,
I just logged in in-flight just so I could post my solution with reductions
:)

(defn doit [coll]
  (rest (reductions conj [] coll)))

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

Re: All subsets of a vector

2011-11-09 Thread Bob Shock
Or my current favorite take-while iterate combo:

C:\clojure-1.2.0java -jar clojure.jar
Clojure 1.2.0
user= (take-while seq (iterate rest [1 2 3 4]))
([1 2 3 4] (2 3 4) (3 4) (4))

user= (take-while seq (iterate butlast [1 2 3 4]))
([1 2 3 4] (1 2 3) (1 2) (1))
user=

On Nov 9, 4:52 pm, Alex Baranosky alexander.barano...@gmail.com
wrote:
 Dang,
 I just logged in in-flight just so I could post my solution with reductions
 :)

 (defn doit [coll]
   (rest (reductions conj [] coll)))

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


Must PersistentQueue be stored in ref not atom?

2011-11-09 Thread Takahiro Hozumi
Hi,

To avoid peeking same element of a queue, I think PersistentQueue must
be stored in ref not atom.
Is this correct?

;;Ref: safe
(dosync
  (let [item (peek @r)]
(alter r pop)
item))

;Atom: unsafe
(let [item (peek @a)]
  (swap! a pop)
  item))

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


Re: Must PersistentQueue be stored in ref not atom?

2011-11-09 Thread Allen Johnson
In your example yes, but you could make it atomic by placing the
functionality in a function of it's own:

;; queue processing actions
(defn process-item [queue]
  (println Processed item: (peek queue))
  (pop queue))

;; usage
(let [queue (atom (into PersistentQueue/EMPTY [1 2 3]))]
  (swap! queue process-item) ; prints 1
  (swap! queue process-item) ; prints 2
  (swap! queue process-item)) ; prints 3

Probably better examples but that's the basic idea.

Allen

On Wed, Nov 9, 2011 at 8:46 PM, Takahiro Hozumi fat...@googlemail.com wrote:
 Hi,

 To avoid peeking same element of a queue, I think PersistentQueue must
 be stored in ref not atom.
 Is this correct?

 ;;Ref: safe
 (dosync
  (let [item (peek @r)]
    (alter r pop)
    item))

 ;Atom: unsafe
 (let [item (peek @a)]
  (swap! a pop)
  item))

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


Re: Must PersistentQueue be stored in ref not atom?

2011-11-09 Thread Takahiro
I see! Thank you.

2011/11/10 Allen Johnson akjohnso...@gmail.com:
 In your example yes, but you could make it atomic by placing the
 functionality in a function of it's own:

 ;; queue processing actions
 (defn process-item [queue]
  (println Processed item: (peek queue))
  (pop queue))

 ;; usage
 (let [queue (atom (into PersistentQueue/EMPTY [1 2 3]))]
  (swap! queue process-item) ; prints 1
  (swap! queue process-item) ; prints 2
  (swap! queue process-item)) ; prints 3

 Probably better examples but that's the basic idea.

 Allen

 On Wed, Nov 9, 2011 at 8:46 PM, Takahiro Hozumi fat...@googlemail.com wrote:
 Hi,

 To avoid peeking same element of a queue, I think PersistentQueue must
 be stored in ref not atom.
 Is this correct?

 ;;Ref: safe
 (dosync
  (let [item (peek @r)]
    (alter r pop)
    item))

 ;Atom: unsafe
 (let [item (peek @a)]
  (swap! a pop)
  item))

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


Re: Must PersistentQueue be stored in ref not atom?

2011-11-09 Thread Allen Johnson
Although now I see that this usage is breaking the side-effect free
rule. So actually this is probably not what you want to do. :)

Now I'm with you and thinking that atoms are not a proper fit for
PersistentQueue. Maybe someone from the conj can shed some light on
this.

Allen

On Wed, Nov 9, 2011 at 8:56 PM, Allen Johnson akjohnso...@gmail.com wrote:
 In your example yes, but you could make it atomic by placing the
 functionality in a function of it's own:

 ;; queue processing actions
 (defn process-item [queue]
  (println Processed item: (peek queue))
  (pop queue))

 ;; usage
 (let [queue (atom (into PersistentQueue/EMPTY [1 2 3]))]
  (swap! queue process-item) ; prints 1
  (swap! queue process-item) ; prints 2
  (swap! queue process-item)) ; prints 3

 Probably better examples but that's the basic idea.

 Allen

 On Wed, Nov 9, 2011 at 8:46 PM, Takahiro Hozumi fat...@googlemail.com wrote:
 Hi,

 To avoid peeking same element of a queue, I think PersistentQueue must
 be stored in ref not atom.
 Is this correct?

 ;;Ref: safe
 (dosync
  (let [item (peek @r)]
    (alter r pop)
    item))

 ;Atom: unsafe
 (let [item (peek @a)]
  (swap! a pop)
  item))

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


Re: Must PersistentQueue be stored in ref not atom?

2011-11-09 Thread Takahiro
I see. You are right.
A function passed to swap! must return only poped value, so peeked
element from a queue is used only for side-effect in the function.

2011/11/10 Allen Johnson akjohnso...@gmail.com:
 Although now I see that this usage is breaking the side-effect free
 rule. So actually this is probably not what you want to do. :)

 Now I'm with you and thinking that atoms are not a proper fit for
 PersistentQueue. Maybe someone from the conj can shed some light on
 this.

 Allen

 On Wed, Nov 9, 2011 at 8:56 PM, Allen Johnson akjohnso...@gmail.com wrote:
 In your example yes, but you could make it atomic by placing the
 functionality in a function of it's own:

 ;; queue processing actions
 (defn process-item [queue]
  (println Processed item: (peek queue))
  (pop queue))

 ;; usage
 (let [queue (atom (into PersistentQueue/EMPTY [1 2 3]))]
  (swap! queue process-item) ; prints 1
  (swap! queue process-item) ; prints 2
  (swap! queue process-item)) ; prints 3

 Probably better examples but that's the basic idea.

 Allen

 On Wed, Nov 9, 2011 at 8:46 PM, Takahiro Hozumi fat...@googlemail.com 
 wrote:
 Hi,

 To avoid peeking same element of a queue, I think PersistentQueue must
 be stored in ref not atom.
 Is this correct?

 ;;Ref: safe
 (dosync
  (let [item (peek @r)]
    (alter r pop)
    item))

 ;Atom: unsafe
 (let [item (peek @a)]
  (swap! a pop)
  item))

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


should partial accept a single argument?

2011-11-09 Thread Robert McIntyre
I'm curious why something like (partial *) doesn't work.

reading the docstring,

user (doc partial)
-
clojure.core/partial
([f arg1] [f arg1 arg2] [f arg1 arg2 arg3] [f arg1 arg2 arg3  more])
  Takes a function f and fewer than the normal arguments to f, and
  returns a fn that takes a variable number of additional args. When
  called, the returned function calls f with args + additional args.

It seems like fewer than the normal arguments to f could reasonably
include 0 arguments.

why not have (partial f) return f?
it would be consistent with (* n) == n, (+ n) == n etc, and would help
when using partial recursively.



sincerely,
--Robert McIntyre

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


smallest unit of code requiring a CA

2011-11-09 Thread Chris Gray
Hi,

I have a patch to the clojure compiler that I would like to submit.  I
haven't signed a CA, but the patch is quite small.  Would it be possible
to submit it without a CA?  I have no objection to signing one; it would
just be slightly embarassing to do so for such a small patch. :)

The patch is at
https://github.com/chrismgray/clojure/tree/namespace-divides and simply
allows code to refer to the / function in namespaces other than
clojure.core.

Cheers,
Chris

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


Re: Must PersistentQueue be stored in ref not atom?

2011-11-09 Thread Meikel Brandmeyer (kotarak)
Hi,

an atom can be sufficient, but you need to drop to a lower level.

(defn !paws
  Like swap! but returns the old value of the atom.
  [a f  args]
  (loop []
(let [old-value @a
  new-value (apply f old-value args)]
  (if (compare-and-set! a old-value new-value)
old-value
(recur)

(peek (!paws atom-with-queue pop))

However, my suspicion is, that you don't clearly divide the state handling 
from the program logic. The peek should happen in the update function you 
pass to swap!. If this is not side-effect free, it means that you have to 
coordinate with other identities and resources. Then a ref or an agent 
might be indeed a better fit than the atom.

Sincerely
Meikel

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

Re: smallest unit of code requiring a CA

2011-11-09 Thread Charlie Griefer

Chris Gray wrote:


I have a patch to the clojure compiler that I would like to submit. I
haven't signed a CA, but the patch is quite small. Would it be possible
to submit it without a CA? I have no objection to signing one; it would
just be slightly embarassing to do so for such a small patch. :)

The patch is at
https://github.com/chrismgray/clojure/tree/namespace-divides and simply
allows code to refer to the / function in namespaces other than
clojure.core.



FWIW, I'd just go ahead and sign the CA. Regardless of how small you 
might perceive this particular patch to be, you may very well find 
yourself submitting additional patches in the future.


Also, 100% conjecture on my part, but I'd assume the CA isn't about the 
size of the patch, but general protection for the core group that needs 
to be in place whether the accompanying patch is one line, one page, or 
one character.


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