clojure.data diff question

2012-01-13 Thread vitalyper
Clojure (use 'clojure.data)
nil

Clojure (doc diff)
-
clojure.data/diff
([a b])
Recursively compares a and b, returning a tuple of
[things-only-in-a things-only-in-b things-in-both].
Comparison rules:

* For equal a and b, return [nil nil a].
* Maps are subdiffed where keys match and values differ.
* Sets are never subdiffed.
* All sequential things are treated as associative collections
by their indexes, with results returned as vectors.
* Everything else (including strings!) is treated as
an atom and compared for equality.
nil

Clojure (diff [a b c] [c d])
[[a b c] [c d] nil]

Looks like the result doesn't match documentation:
Recursively compares a and b, returning a tuple of
[things-only-in-a things-only-in-b things-in-both].

-- 
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: Help! Migrating to 1.3.0

2012-01-13 Thread vitalyper
Have seen this as well. For efficiency sake 1.3.0 requires :dynamic
meta for convention based ear-muffed vars (intended for rebinding).
The warning actually is quite descriptive if you think about it.
See more in-depth discussion at
http://blog.japila.pl/2011/03/cant-dynamically-bind-non-dynamic-var-in-clojure-1-3/

HTH

On Jan 13, 11:47 am, labwor...@gmail.com wrote:
 I have a few issues. What do the following warnings mean and what should I
 do about them?

 user= (require 'mypackage)
 Warning: *default-encoding* not declared dynamic and thus is not
 dynamically rebindable, but its name suggests otherwise. Please either
 indicate ^:dynamic *default-encoding* or change the name.
 Warning: *buffer-size* not declared dynamic and thus is not dynamically
 rebindable, but its name suggests otherwise. Please either indicate
 ^:dynamic *buffer-size* or change the name.
 Warning: *byte-array-type* not declared dynamic and thus is not dynamically
 rebindable, but its name suggests otherwise. Please either indicate
 ^:dynamic *byte-array-type* or change the name.
 Warning: *append-to-writer* not declared dynamic and thus is not
 dynamically rebindable, but its name suggests otherwise. Please either
 indicate ^:dynamic *append-to-writer* or change the name.
 nil

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


:arglists question

2011-12-29 Thread vitalyper
Came across the following in one of the clojure libs (congomongo to be
exact)
https://github.com/aboekhoff/congomongo/blob/master/src/somnium/congomongo.clj:464

(defn command
  Executes a database command.
  {:arglists '([cmd {:options nil :from :clojure :to :clojure}])}
  [cmd  {:keys [options from to]
  :or {options nil from :clojure to :clojure}}]
  (let [db (get-db *mongo-config*)
coerced (coerce cmd [from :mongo])]
(coerce (if options
  (.command db ^DBObject coerced (int options))
  (.command db ^DBObject coerced))
[:mongo to])))

My question is why do we have BOTH :arglists metadata and usual fn
args destructuring?
  {:arglists '([cmd {:options nil :from :clojure :to :clojure}])}
  [cmd  {:keys [options from to]
  :or {options nil from :clojure to :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


clojure.math.combinatorics jar

2011-12-27 Thread vitalyper
Do we have this jar in clojars? Searched for it under math but could
not find it.
Found version 0.0.2 in mvnrepository.com but it is not the the version
0.0.3-SNAPSHOT mentioned in
https://github.com/clojure/math.combinatorics/blob/master/pom.xml

-- 
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.math.combinatorics jar

2011-12-27 Thread vitalyper
Do we have this jar in clojars? Searched for it under math but could
not find it.
Found version 0.0.2 in mvnrepository.com but it is not the the version
0.0.3-SNAPSHOT mentioned in
https://github.com/clojure/math.combinatorics/blob/master/pom.xml

-- 
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: Get multiple vals from a map

2011-12-07 Thread vitalyper
Thanks, Alan. It is more general solution which also works for keys
that are not keywords
user= (map {a 1 b 2 c 3} [ a b])
(1 2)

On Dec 1, 5:02 pm, Alan Malloy a...@malloys.org wrote:
 I usually use juxt, but a more correct/robust solution is to use map,
 with the lookup-map as the function:

 (map {:foo 1 :bar 2 :baz 0} [:foo :bar])

 On Dec 1, 12:26 pm, Ulises ulises.cerv...@gmail.com wrote:







  How about using juxt:

  sandbox ((juxt :foo :bar) {:foo 1 :bar 2 :baz 0})
  [1 2]
  sandbox

  This only works, however, if you use keywords for keys (as they are
  functions themselves).

  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


Re: Dynamically Loading Jar Strategy

2011-12-07 Thread vitalyper
You can add jar to a classpath at runtime via the hack below.
http://groups.google.com/group/clojure/browse_thread/thread/95ea6e918c430e/69c0d195defeeed3?lnk=gstq=classpath#69c0d195defeeed3

HTH

On Dec 7, 10:26 am, Pierre-Yves Ritschard p...@spootnik.org wrote:
 Hi,

 I have a use case where a daemon needs to read full namespaces from an
 external jar.
 I can successfuly access the namespace in the jar with tools.namespace/
 find-namespaces-in-jarfile, then from the jarfile, selecting
 appropriate entries, coercing into readers and then loading with load-
 reader.

 This approach breaks as soon as the supplied jar does requires, since
 the jar is not on the classpath. I am a bit surprised that setting a
 classloader in the current thread with setContextClassLoader does not
 work, as my binding for *use-context-classloader* is the default:
 true.

 I could obviously supply a fixed directory that is always in the
 classpath but that would require having two configuration files, which
 I thought I could avoid.

 Is there a way around this, or am I stuck ?

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


Get multiple vals from a map

2011-12-01 Thread vitalyper
Is there something build in for getting multiple vals out of the map?
{:keys [...]} woks in destructuring forms. It is quite easy to build
something with filter and map but I suspect these is a common problem
somebody solved already.
Desired
(get-vals [:a :b] {:a 1 :b 2 :c 3})
(1 2)

-- 
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: Get multiple vals from a map

2011-12-01 Thread vitalyper
Thanks, works in my case.

On Dec 1, 3:26 pm, Ulises ulises.cerv...@gmail.com wrote:
 How about using juxt:

 sandbox ((juxt :foo :bar) {:foo 1 :bar 2 :baz 0})
 [1 2]
 sandbox

 This only works, however, if you use keywords for keys (as they are
 functions themselves).

 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


Re: Use of eval

2011-11-22 Thread vitalyper
Gary,

You are probably removing try/catch as well. ClassNonFoundException is
expected and silenced with catch.

(defn cl-factory
  Returns a Commons Logging-based implementation of the
LoggerFactory
protocol, or
  nil if not available.
  []
  (try
(Class/forName foo.bar)
; eval removed
(catch Exception e nil)))

On Nov 18, 5:16 pm, Gary Trakhman gary.trakh...@gmail.com wrote:
 I get this when i try it in a blank project, removing the eval and the
 quote:

 Unknown location:
   error: java.lang.ClassNotFoundException: org.apache.commons.logging.Log

 core.clj:16:8:
   error: java.lang.ClassNotFoundException: org.apache.commons.logging.Log
 (core.clj:16)

 Compilation failed.

-- 
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: Proper parallelism?

2011-11-22 Thread vitalyper
Andy,

You can also look into using futures (pmap uses future).
In section 11.6.1 of Joy of Clojure there is a recipe how to
dispatch multiple RPC calls in parallel using as-futures macro.
Obviously, this depends on what you want to do with results of your
REST calls.

On Nov 22, 11:16 am, AndyK andy.kri...@gmail.com wrote:
 I have been using Clojure to write tests on RESTful applications.
 Since the requests are independent, parallelizing would speed things
 along. What is the best approach? Using pmap is the obvious first
 step. Afaik, pmap only creates a small pool of threads. Is there more
 to gain by going to the Java API's threading classes (like
 ExecutorService, or building a pool of threads triggered by a
 CountDownLatch)? What experience have folks had with different
 approaches?

 thx

-- 
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: Use of eval

2011-11-22 Thread vitalyper
Gary,

You were right with your initial reply. Sorry I did not get it. Thanks
for your help in understanding this.

On Nov 22, 1:58 pm, Gary Trakhman gary.trakh...@gmail.com wrote:
 Also I think this line doesn't actually do anything:  (Class/forName
 foo.bar)

 It will effectively just ask the classloader to load the class.  You
 removed more than the eval in your referenced code, you removed the code
 that did anything.   That code needs to be there.  It's eval'd because it's
 not guaranteed to be compilable for projects without commons-logging in
 their classpath.

 (defn cl-factory
   Returns a Commons Logging-based implementation of the
 LoggerFactory
 protocol, or
   nil if not available.
   []
   (try
     (Class/forName foo.bar)
     ; eval removed
     (catch Exception e nil)))

-- 
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: Change var in other namespace

2011-11-18 Thread vitalyper
Thanks, Sean. Exactly what I was looking for.
IMO, clojure.tools.logging could of made this easier: log
implementation from classpath by default with override by client when
needed.

On Nov 17, 11:32 pm, Sean Corfield seancorfi...@gmail.com wrote:
 Note: if you just want something that will execute at startup and
 force _all_ logging to use log4j, instead of wrapping code in (binding
 ..) then you probably want something like this:

 (ns your.namespace
   (:require [clojure.tools.logging :as log])
   (:require [clojure.tools.logging.impl :as impl]))

 (alter-var-root (var log/*logger-factory*) (constantly (impl/log4j-factory)))

 This is what we ended with in our code to ensure log4j was selected at
 startup...

 Sean







 On Thu, Nov 17, 2011 at 7:04 PM, Mark Rathwell mark.rathw...@gmail.com 
 wrote:
  You rebind dynamic vars with binding, so your use would look something
  like this:

  (binding [*logger-factory* (log-impl/log4j-factory)]
   (do-stuff-with-the-logger-factory-rebound))

  On Thu, Nov 17, 2011 at 5:17 PM, vitalyper vitaly...@yahoo.com wrote:
  clojure.tools.logging defines *logger-factory* and initializes it with
  first logger implementation on the class path

  (def ^{:doc
   An instance satisfying the impl/LoggerFactory protocol. Used
  internally to
    obtain an impl/Logger. Defaults to the value returned from impl/
  find-factory.
   :dynamic true}
   *logger-factory*
   (impl/find-factory))

  In my own namespace I want to redefine *logger-factory* to log4j one.
  Tried different variations (def, set!, etc) in 1.3.0 with no avail.
  (ns my.foo
   (:gen-class)
   (:use
     [clojure.tools.logging :only (*logger-factory* info debug)])
   (:require
             [clojure.string :as s1]
             [clojure.tools.logging.impl :as log-impl])
  )

  (defn init-logging
   Force log4j factory for core tools logging
   []
   (def *logger-factory* (log-impl/log4j-factory)))
  ; CompilerException java.lang.IllegalStateException: *logger-factory*
  already refers to: #'clojure.tools.logging/*logger-factory* in
  namespace: infrared.common

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


Use of eval

2011-11-18 Thread vitalyper
Came across this code in clojure.tools.logging

(defn cl-factory
  Returns a Commons Logging-based implementation of the LoggerFactory
protocol, or
  nil if not available.
  []
  (try
(Class/forName org.apache.commons.logging.Log)
(eval
  `(do
 (extend org.apache.commons.logging.Log
   Logger
   {:enabled?
(fn [logger# level#]
  (condp = level#
:trace (.isTraceEnabled logger#)
:debug (.isDebugEnabled logger#)
:info  (.isInfoEnabled  logger#)
:warn  (.isWarnEnabled  logger#)
:error (.isErrorEnabled logger#)
:fatal (.isFatalEnabled logger#)
(throw (IllegalArgumentException. (str level#)
:write!
(fn [logger# level# e# msg#]
  (if e#
(condp = level#
  :trace (.trace logger# msg# e#)
  :debug (.debug logger# msg# e#)
  :info  (.info  logger# msg# e#)
  :warn  (.warn  logger# msg# e#)
  :error (.error logger# msg# e#)
  :fatal (.fatal logger# msg# e#)
  (throw (IllegalArgumentException. (str level#
(condp = level#
  :trace (.trace logger# msg#)
  :debug (.debug logger# msg#)
  :info  (.info  logger# msg#)
  :warn  (.warn  logger# msg#)
  :error (.error logger# msg#)
  :fatal (.fatal logger# msg#)
  (throw (IllegalArgumentException. (str
level#))})
 (reify LoggerFactory
   (name [_#]
 org.apache.commons.logging)
   (get-logger [_# logger-ns#]
 (org.apache.commons.logging.LogFactory/getLog (str logger-
ns#))
(catch Exception e nil)))

I do understand what it does with extend and reify but I am not clear
why eval is needed here.

-- 
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: Use of eval

2011-11-18 Thread vitalyper
I don't think you are right - it does compiles without it.
After more thinking my guess is that eval is used to combine extend
and reify in the same function. Let's see if somebody else could shed
a light on this.

On Nov 18, 12:45 pm, Gary Trakhman gary.trakh...@gmail.com wrote:
 My speculation is that the eval is required in the case that commons-logger
 is not in the classpath.  The code wouldn't compile without it.

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


Change var in other namespace

2011-11-17 Thread vitalyper
clojure.tools.logging defines *logger-factory* and initializes it with
first logger implementation on the class path

(def ^{:doc
  An instance satisfying the impl/LoggerFactory protocol. Used
internally to
   obtain an impl/Logger. Defaults to the value returned from impl/
find-factory.
  :dynamic true}
  *logger-factory*
  (impl/find-factory))

In my own namespace I want to redefine *logger-factory* to log4j one.
Tried different variations (def, set!, etc) in 1.3.0 with no avail.
(ns my.foo
  (:gen-class)
  (:use
[clojure.tools.logging :only (*logger-factory* info debug)])
  (:require
[clojure.string :as s1]
[clojure.tools.logging.impl :as log-impl])
)

(defn init-logging
  Force log4j factory for core tools logging
  []
  (def *logger-factory* (log-impl/log4j-factory)))
; CompilerException java.lang.IllegalStateException: *logger-factory*
already refers to: #'clojure.tools.logging/*logger-factory* in
namespace: infrared.common

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