Re: What does the ref *loaded-libs* do?

2018-02-05 Thread Stephen Gilardi
It is there to support the “:reload” and “:reload-all” features of “require” 
and to help separate the concern of loading libs from the concern of tracking 
namespaces.

--Steve

> On Jan 29, 2018, at 6:36 PM, Raymond Huang <12ay.hu...@gmail.com> wrote:
> 
> I was poking around `tools.namespace` and I found it interesting that the 
> implementation of `remove-lib` is:
> 
> ```(defn remove-lib
>   "Remove lib's namespace and remove lib from the set of loaded libs."
>   [lib]
>   (remove-ns lib)
>   (dosync (alter @#'clojure.core/*loaded-libs* disj lib)))
> ```
> 
> 
> I’m wondering if someone can enlighten me to explain why `*loaded-libs*` 
> needs to exist, as opposed to checking `clojure.lang.Namespace` directly?
> 
> This is a question carried over from slack: 
> https://clojurians.slack.com/archives/C03S1KBA2/p151721185721
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: How to configure a library from a file in the project that has it as a dependency?

2016-04-19 Thread Stephen Gilardi
If you end up using a separate config file rather than project.clj, you might 
find Carica https://github.com/sonian/carica  
useful. It allows merging config files on the classpath into one effective 
config hierarchy with predictable overriding behavior.

Sample calls:

(carica/config :db) => {:classname “org.postgresql.Driver”, :subprotocol 
“postgresql”, … }
(carica/config :db :classname) => “org.postgresql.Driver”

A typical use is to have a config file for a server or library in the shipped 
jar file that contains defaults and a runtime classpath that allows that config 
to be overridden by a config file laid down during deployment.

The deployed config file needs to contain keys for the key paths that need to 
be overridden, not the entire hierarchy.

—Steve

> On Apr 19, 2016, at 12:04 PM, Facundo Olano  wrote:
> 
> Hi! I started to use clojure a couple of months ago and now I'm struggling to 
> extract a little library from a larger project I'm working on.
> 
> The lib is a gettext-like tool that allows translating strings based on a 
> translations dictionary. I'd like to be able to include the lib as a 
> dependency of the larger project and point to my translations dictionary from 
> a setting in a configuration file (Ideally I would use project.clj to avoid 
> having a lib specific file just for one setting).
> 
> My problem is I'm not sure how to read a configuration file in my project 
> from the generated JAR of the lib (if that's even possible and not a bad idea 
> for some reason). I tried using configleaf 
>  and it worked while I included 
> the lib as a checkout project but it seems the config file gets freezed to 
> whatever it is when the lib's JAR is packed.
> 
> I wonder if there's a straightforward and idiomatic way to achieve this. 
> "That's a terrible idea" type of answers are also welcome :P
> 
> Thanks, 
> Facundo.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en 
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

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


Re: Complex swap!

2016-02-01 Thread Stephen Gilardi
Here are a few discussions about this issue:

http://dev.clojure.org/jira/browse/CLJ-1454 

http://stackoverflow.com/questions/15441638/alternate-version-of-swap-also-returning-swapped-out-value
 

http://stackoverflow.com/questions/26838348/why-does-clojures-atom-swap-return-the-new-value
 


—Steve

> On Feb 1, 2016, at 1:05 PM, Jochen  wrote:
> 
> Hi…
> 
> in my little project I do some concurrent stuff using atoms. 
> Now, during the last days using swap! I encountered the same problem several 
> times:
> Some result value is produced inside the swap! function besides the updated 
> data that I would like to return.
> I first played with two atoms and considered modeling the entire result as 
> the atom value and even using refs.
> The "fat atom" approach is ugly in this case as the enhanced result is just a 
> local artifact and not of interest outside my calls. Refs/STM looks somewhat 
> big for this.
> But then I saw compare-and-set! and came up with this:
> 
> (defn complex-swap! [atoom get-ref-val f & args]
>   (loop [last-val @atoom]
> (let [result (apply f last-val args)]
>   (if (compare-and-set! atoom last-val (get-ref-val result))
> result
> (recur @atoom)
> 
> 
> It allows to produce an augmented result value, only part of which is the new 
> atom content passing an additional getter function to extract the new value 
> part.
> 
> For example:
> (def my-atom (atom '(1 2 3 4)))
> (complex-swap! my-atom second (partial split-with #(<= % 2)))
> => [(1 2) (3 4)]
> @my-atom
> => (3 4).
>  
> The original swap! would be like this:
> (swap! my-atom (comp second (partial split-with #(<= % 2
> => (3 4)
> @my-atom
> => (3 4)
> 
> Now, is there some even easier way to achieve this or is this the best 
> approach?
> 
> Ciao
> 
> …Jochen
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en 
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

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


Re: ClojureScript compiler says "No such namespace" ?

2015-12-23 Thread Stephen Gilardi
The namespace name is not the same as the dep name.

‘require' clauses use namespace names, for example:

[cljs-time.format :as something]

You can get the namespace name from the ns form at the top of its file, e.g., 
https://github.com/andrewmcveigh/cljs-time/blob/master/src/cljs_time/format.cljs#L1
 

 .

—Steve

> On Dec 23, 2015, at 4:27 PM, fah...@gmail.com wrote:
> 
> Noob question -- what am I doing wrong?
> lein new mies  hello-world ...builds fine
> add the following to project.clj's dependencies, lein deps, builds fine
> [com.andrewmcveigh/cljs-time "0.3.14"]
> add the following to src/hello_world/core.cljs's :require clause
> [com.andrewmcveigh.cljs-time.format :as something]
> Caused by: clojure.lang.ExceptionInfo: No such namespace: 
> com.andrewmcveigh.cljs-time.format, could not locate 
> com/andrewmcveigh/cljs_time/format.cljs, 
> com/andrewmcveigh/cljs_time/format.cljc, or Closure namespace 
> "com.andrewmcveigh.cljs-time.format" {:tag :cljs/analysis-error}
> 
> 
> 
> My core.cljs file ns expression looks like this:
> 
> 
> 
> (ns hello-world.core
>   (:require [clojure.browser.repl :as repl]
> [com.andrewmcveigh.cljs-time.format :as f]))
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en 
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

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


Re: difficulties using extend--'elp!

2015-11-24 Thread Stephen Gilardi
There are a several small things here that need fixing:

- in the “gran” section of your “extend”, you’re defining “blap” which is not 
part of the gran protocol
  - perhaps blip was intended
- the first argument in protocol function declarations refers to the object 
itself, often named “this”
- calls to protocol functions don’t begin with “.”
- the call to (:blip this) had the wrong arity

Here is something similar that prints 6:

(ns aatree.record-play)

(defprotocol gran
  (blip [this x y z]))

(defrecord wackel [])

(defn new-wackel [opts]
  (let [w (->wackel)]
(into w opts)
(assoc w :blip (fn [this x y z] (+ x y z)

(extend wackel
  gran
  {:blip (fn [this x y z]
   ((:blip this) this x y z))})

(println (blip (new-wackel {}) 1 2 3))

- also consider extend-type in preference to extend here for its somewhat 
friendlier syntax.

—Steve

> On Nov 24, 2015, at 11:30 AM, William la Forge  > wrote:
> 
> This is not working for me:
> 
> (ns aatree.record-play)
> 
> (defprotocol gran
>   (blip [x y z]))
> 
> (defrecord wackel [])
> 
> (defn new-wackel [opts]
>   (let [w (->wackel)]
> (into w opts)
> (assoc w :blip (fn [this x y z] (+ x y z)
> 
> (extend wackel
>   gran
>   {:blap (fn [this x y z]
>((:blip this) x y z))})
> 
> (println (.blap (new-wackel {}) 1 2 3))
> 
> I get this: No matching method found: blap for class aatree.record_play.wackel
> 
> I changed the println to this:
> 
> (let [^gran w (new-wackel {})]
>   (println (.blap w 1 2 3)))
> 
> And now I get this: Unable to resolve classname: gran
> 
> Clearly there is something about protocols and/or extend that I do not 
> understand.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com 
> 
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com 
> 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en 
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

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


Re: safety and reusability of clojure.lang.RT, Compiler and co. in multi-classloader environment

2015-09-28 Thread Stephen Gilardi
I haven’t seen discussion of isolating some of the RT data structures while 
sharing others and the executable parts.

In case you haven’t seen these, here are some references about isolated Clojure 
runtimes that may be helpful:

https://github.com/boot-clj/boot  and its 
“pods” facility: https://github.com/boot-clj/boot/tree/master/boot/pod 
 which uses 
https://github.com/projectodd/shimdandy 
 .

More on pods: https://github.com/boot-clj/boot/wiki/Pods 


A presentation about boot (including pods): 
https://www.youtube.com/watch?v=TcnzB2tB-8Q 
 .

—Steve

https://github.com/projectodd/shimdandy 

> On Sep 28, 2015, at 6:08 PM, Georgi Danov  wrote:
> 
> Hi,
>  I am integrating clojure into java micro container. It has hierarchical 
> classloaders and can restart modules on the fly. It's almost REPL for Java :).
> 
>  I have clojure running inside it, but even after reading some of the RT and 
> Compiler classes source code I don't understand well enough how much state is 
> accumulated where (theadLocals, static class fields/Vars, classloader, so 
> on). Given that I don't want to have each module run different clojure 
> version, I would prefer to have the basic things loaded once and shared.
> 
>  I am also not sure what is shareable — I see the RT class has some static 
> init functionality that appears to be safe for sharing the same clojure.jar 
> classloader with all modules, but can't be sure.
>  
>  Would be glad if there is article I have missed that outlines this. 
> 
> Thanks,
> Georgi
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en 
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

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


Re: Anotating functions for pre-processing

2015-08-05 Thread Stephen Gilardi
 I wish I could do that in Clojure:
 
 (defn ^:transactional someFunction [...] ...)
 
 and then have somehow means to decorate someFunction (yes, I am aware there 
 is no container)

The code you proposed does have an effect on the someFunction var (but not the 
function it ends up bound to). That might be enough for you to accomplish what 
you’re after.

user= (defn ^:transactional someFunction [x] (prn x))
#'user/some-function
user= (meta #'some-function)
{:ns #Namespace user, :name someFunction, :file ..., :transactional true, 
:column 1, :line 1, :arglists ([x])}

—Steve

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


Re: Identifying dependency that's pulling in SLF4J

2015-06-08 Thread Stephen Gilardi

 On Jun 8, 2015, at 1:26 PM, Michael Gardner gardne...@gmail.com wrote:
 
 I've started to see unwanted SLF4J console messages from one of my projects. 
 I'm not (directly) using SLF4J, and would like to find out which of my 
 dependencies is. But the dependency tree is a bit large to search by hand. Is 
 there a better way?

Does “lein deps :tree” help?

—Steve

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


Re: clojure.main on a clj file does not show up any println

2014-12-08 Thread Stephen Gilardi

 On Dec 8, 2014, at 9:02 AM, Ganesh Krishnamoorthy ganesh@gmail.com 
 wrote:
 
 I have been trying all my bit on to get my hello world working; Any help is 
 much appreciated...
 
 am trying to run it by 
 java -cp clojure-1.6.0.jar clojure.main hey.clj
 I just get an empty line.
 Below is my file:
 
 (defn -main
   []
   (println Hello World!)
   (println (- 1 1)))

That calling syntax for clojure.main executes the contents of the hey.clj file. 
Your file defines a -main function, but no code will call it. If you add a call 
to your main function, it runs:

(-main)

There are other options for clojure.main.  There’s more info here: 
http://clojure.org/repl_and_main http://clojure.org/repl_and_main and here: 
http://www.beaconhill.com/blog/?p=283 http://www.beaconhill.com/blog/?p=283

—Steve

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


Re: Retrieving the namespace an expression in compiled in

2014-10-23 Thread Stephen Gilardi

 On Oct 23, 2014, at 5:06 PM, James Reeves ja...@booleanknot.com wrote:
 
 Or a macro:
 
 (defn endpoint [config]
   (routes
(GET / [] (resource/url (this-ns) index.html

Perhaps a macro 'ns-path’:

(defn endpoint [config]
  (routes
   (GET / [] (resource/url (ns-path index.html”)

—Steve

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


Re: Modelling in Clojure

2014-10-22 Thread Stephen Gilardi

 Clojure's laziness is restricted to seqs
 and is guaranteed to always produce the same value for the same field.
 
 Nope:
 
 = (def foo (int-array [1 2 2 5 9 3]))
 #'user/foo
 = (def bar (seq foo))
 #'user/bar
 = bar
 (1 2 2 5 9 3)
 = (aset foo 3 3)
 3
 = bar
 (1 2 2 3 9 3)

There’s no laziness in that example. With laziness introduced by map, the 
caching done by lazy seq shows:

user (def foo (int-array [1 2 2 5 9 3]))
#'user/foo
user (def baz (map identity foo))
#'user/baz
user baz
(1 2 2 5 9 3)
user (aset foo 3 3)
3
user baz
(1 2 2 5 9 3)

—Steve

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


Re: Namespace circular dependencies

2014-10-16 Thread Stephen Gilardi
 So, I'm confused. I'm not sure what is allowed and under what circumstances, 
 and I'm not sure what I should be validating here. Zach very reasonably 
 argued that Clojure clearly permits this since Manifold works, but I'm not 
 sure if this is just a happy accident. Looking at the clojure.core code, it 
 seems that there is only circular dependency checking when using load, not 
 when using require.

I took a look at what’s going on in the manifold case. I’m not sure this 
explanation is enough to yield a solution to the problem you’re trying to 
solve, but it should be a good start.

The cyclic load dependency check fails if `load` is asked to load a file while 
that same file has started loading but not yet finished loading. It’s a runtime 
check.

`require` calls `load` conditionally to implement its basic function: “load a 
lib if it isn’t already loaded”. `require`’s processing of a given libspec may 
or may not result in a call to `load`: If the lib is already loaded, it isn’t 
loaded again.

As of commit f11e70726553685bda222ccd37c28addcfc519c7 (29 November 2012, first 
in clojure-1.5.0-beta2), a lib is considered loaded as soon as an ns form for 
the corresponding namespace has been successfully evaluated.

In the case of manifold.stream, the explicit calls to `require` occur after (ns 
manifold.stream …). Since manifold.stream is already considered loaded at that 
point, the indirect calls to (require ‘manifold.stream) that they generate do 
not result in calls to `load` and therefore do not trigger the cyclic load 
dependency check.

—Steve

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


Re: Keyword comparison performance

2014-10-11 Thread Stephen Gilardi

On Oct 11, 2014, at 10:59 AM, Jony Hudson jonyepsi...@gmail.com wrote:

 But if any of these Keyword objects were garbage-collected, I think it would 
 break the parity between identical? and =. 

The Keyword construction and interning mechanism ensures that whenever there 
exists at least once (strong) reference to a given Keyword object, all 
references will be to the same object.

A given Keyword object can only be garbage collected if it's garbage--if there 
are no (strong) references to it currently in existence. That means it's not a 
key or value in any map, it's not in use by any compiled code, it's not the 
value of any local, etc. Without any existing strong reference to it, no 
comparison involving that Keyword object is possible.

If at any point in time there are no strong references to it, it's safe to 
un-intern the Keyword object. If a keyword of that name (and namespace) is 
needed subsequently, a new Keyword object can be created and interned and the 
promised identity and equality semantics will be satisfied from that point 
forward.

--Steve

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


Re: Keyword comparison performance

2014-10-10 Thread Stephen Gilardi

  I've been optimising a piece of code lately, and have come to wonder about 
 the performance of keyword comparison. Specifically, I'm not sure whether the 
 performance I'm seeing is what is expected. The data structures page on 
 clojure.org [1] indicates that keywords provide very fast equality tests. 
 If I micro-benchmark with criterium, then I find the following:
 
 As a baseline, comparing integers with `(= 0 1)` takes around 4ns.
 
 Comparing keywords with `(= :plus :minus)` takes around 30ns.

I ran the same test and saw similar results.

I noticed that using identical? instead of = brings the performance much 
closer to the integer case because identical? does less work.

In most cases, equal keywords are also identical because the keyword objects 
are cached by clojure.lang.Keyword/intern. If you don't need to worry about the 
case of multiple Clojure runtimes being loaded by separate classloaders[1], and 
if you're in control of the code doing the comparison, you could change to 
using identical? for better performance.

Treatment of keyword equality and identity also came up during the development 
of ClojureScript. I found this discussion interesting: 
https://groups.google.com/forum/#!topic/clojurescript/bSFK6CEE3PE .

--Steve

[1] https://groups.google.com/d/msg/clojure/ZW2udohC1lA/6wLcEpQj_LoJ

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


Re: Convert clj-time date-time to UTC

2014-06-14 Thread Stephen Gilardi
This is not quite to your exact specification, but should help you to write 
what you want:

user (defn to-utc [dt]
(t/to-time-zone dt (t/time-zone-for-offset 0)))
#'user/to-utc
user (to-utc (t/from-time-zone (t/date-time 1967 7 31 6 30) 
(t/time-zone-for-id America/Caracas)))
#DateTime 1967-07-31T10:30:00.000Z

--Steve

On Jun 14, 2014, at 10:09 AM, gvim gvi...@gmail.com wrote:

 I want to convert a time specified with a TZ datababse timezone such as 
 America/Caracas into a UTC date-time but I can only find in clj-time 
 from-time-zone and to-time-zone allowing the zone to be specified as a 
 string. I want:
 
 (t/some-utc-func (t/date-time 1967 7 31 6 30) (t/time-zone-for-id 
 America/Caracas))
 
 to give me:
 
 #DateTime 1967-07-31T10:30:00.000-00:00
 
 Even the (t/from-time-zone []) output would do if I could read the UTC date 
 and time straight from it.
 
 gvim
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

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


Re: Convert clj-time date-time to UTC

2014-06-14 Thread Stephen Gilardi
You're welcome.

As another small refinement, I noticed that there's a var for the utc timezone:

(t/time-zone-for-offset 0)

can be replaced with

t/utc

--Steve

On Jun 14, 2014, at 12:49 PM, gvim gvi...@gmail.com wrote:

 On 14/06/2014 16:12, Stephen Gilardi wrote:
 This is not quite to your exact specification, but should help you to
 write what you want:
 
 user (defn to-utc [dt]
 (t/to-time-zone dt (t/time-zone-for-offset 0)))
 #'user/to-utc
 user (to-utc (t/from-time-zone (t/date-time 1967 7 31 6 30)
 (t/time-zone-for-id America/Caracas)))
 #DateTime 1967-07-31T10:30:00.000Z
 
 
 Thanks. Can't think why it's not baked into the library, though, as it must 
 be a common requirement.
 
 gvim
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

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


Re: Confusion about binding *ns* before defining a var

2014-05-30 Thread Stephen Gilardi

On May 30, 2014, at 12:57 AM, ian.tegebo ian.teg...@gmail.com wrote:

 I don't see the reason why def should behave as it currently does; it seems 
 like it should lookup the current thread-binding for *ns*, making the second 
 case's use of eval unnecessary.  Since it doesn't, I'd like to know why it 
 couldn't (or shouldn't) do the thing that seems more intuitive.


One reason is performance.

The compile-time resolution of:

  - symbols into fully qualified symbols, and then
  - fully qualified symbols into direct references to the vars they represent

is important in allowing Clojure code to execute as fast as it does. These are 
relatively time consuming operations. Deferring them to execution time would 
make Clojure code execution slower to an unacceptable degree. Instead, they are 
done once when the code is compiled and in the general case executed many times 
without further lookups.

In your particular example, the code is compiled once, executed, and then not 
used again so the performance distinction doesn't matter. However, the repl and 
eval don't get any special treatment from the compiler, so you see the same 
behavior using them as you do when you load a library full of code using 
:require in an ns form.

Another design choice for the Clojure compiler that impacts your example is 
that each top-level form is completely compiled before any part of it is 
executed [1]. There's a nice writeup of another similar implication of that 
here: http://technomancy.us/143 .

The distinction between compile time and execution time for Clojure code is 
something that rarely has an impact on understanding the behavior of the code. 
You've found a case where the distinction does matter. The doc for def talks 
about the current namespace without giving a detailed description of what 
instant of time current refers to. It turns out to be current at the time 
the code is compiled, not current at the time the code is executed.

In the rare case that the binding of *ns* changes between those times, the 
behavior can be confusing. One way to avoid this confusion is to keep all defs 
at the top level and treat *ns* as something that can be set! or manipulated 
with the associated tools like in-ns, but not bound using bind.

--Steve

[1] Except a top-level do in Clojure 1.1+ as described in the blog post

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


Re: Confusion about binding *ns* before defining a var

2014-05-29 Thread Stephen Gilardi

On May 29, 2014, at 7:11 PM, ian.tegebo ian.teg...@gmail.com wrote:

 user (binding [*ns* (the-ns 'blah)] (defn foo []))
 #'user/foo
 user (binding [*ns* (the-ns 'blah)] (eval '(defn foo [])))
 #'blah/foo

clojure.core/eval evaluates a form by compiling it and then executing the 
compiled code. For a def form, it's the ns that is current when the form is 
compiled that determines in which namespace the resulting var is created.

In the first case, the defn form is compiled before the binding to (the-ns 
'blah) is in effect.

In the second case, the defn form is quoted and remains unevaluated while the 
binding form is compiled. While executing the compiled code for the binding 
form, eval compiles the defn form (and then executes its compiled code). In 
this case, the defn is compiled after the binding to (the-ns 'blah) is in 
effect.

--Steve

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


Re: regex strings

2014-05-27 Thread Stephen Gilardi
clojure.string/replace replaces the portion of the string matched by the regex 
with the replacement. If you add .* to the regex, the regex will match the 
entire input string and the form will evaluate to First.

--Steve

On May 27, 2014, at 11:24 AM, Glen Rubin rubing...@gmail.com wrote:

 I have a string of the general form:
 
 Name: Last,First Middle ID: GA88192
 
 
 I am trying to extract the first name by invoking string.replace function, 
 for example to extract the first name I invoke the following where 
 'nameidstring' is the general form above:
 
 
  (clojure.string/replace nameidstring #Name:\s(\w+){1},(\w+){1} $2)
 
 Unfortunately, this gives me the First name along with ID: GA88192
 
 since i specified a single word {1} in my regex above I don't understand why 
 this is happening.  THank you for any advice
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

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


Re: ArithmeticException from unchecked-add

2014-05-19 Thread Stephen Gilardi

On May 19, 2014, at 2:17 PM, Greg D gregoire.da...@gmail.com wrote:

 user (unchecked-add ^Long(Long/MAX_VALUE) ^Long(Long/MAX_VALUE) )
 ArithmeticException integer overflow  clojure.lang.Numbers.throwIntOverflow 
 (Numbers.java:1424)

The docs for unchecked-add 
(http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/unchecked-add)
 only cover the case of both arguments being primitive longs. Calling with 
other argument types invokes behavior that is not currently documented. That 
may be intentional to allow the behavior to change in the future, or it may be 
an oversight in which case the docs could be improved to document the intended 
behavior for more argument types.

Regarding the current implementation, there is code to handle the case of 
calling unchecked-add with two Long arguments. In that case, unchecked_add 
behaves the same way as + does and throws the overflow exception.

--Steve

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


Re: Is there a term for non-map collections?

2014-05-16 Thread Stephen Gilardi

On May 16, 2014, at 12:53 PM, Mars0i marsh...@logical.net wrote:

 Sometimes I write a function that will work in the intended way only with 
 collections that are not maps.  (For example, suppose I write a function 
 that's supposed to operate on vectors, lists, sets, or lazy sequences of 
 keywords, what do I call its argument?  keyw-coll is too broad, and 
 keyw-seq is too narrow.)

I think I'd use kws or keywords in that case. I'd expect a seq of keywords.

I don't think keyw-seq is too narrow though. The items in a seq on a map are 
map entries or more generically pairs, not keywords.

--Steve

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


Re: Is there a term for non-map collections?

2014-05-16 Thread Stephen Gilardi

On May 16, 2014, at 1:23 PM, Mars0i marsh...@logical.net wrote:

 I think I'd use kws or keywords in that case. I'd expect a seq of 
 keywords.
 
 I don't think keyw-seq is too narrow though. The items in a seq on a map are 
 map entries or more generically pairs, not keywords.
 
 OK, but seq implies that sets aren't appropriate, but as long as I don't 
 care about order, they may be perfectly fine.

Good point. Technically kw-seq is too narrow because you probably have no need 
to restrict your argument to seqs. The distinction is often blurred because 
many Clojure functions that operate on seqs also directly or indirectly call 
seq on their argument. Any coll that's seqable will also work.

I think looking at the word kew-seq as an argument name, I would expect to be 
able to pass in colls that are not seqs but are seqable including vector and 
set.

Revising my earlier thought:

I think I'd use kws or keywords in that case. I'd expect a seq or seqable 
coll whose items are keywords.


--Steve

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


Re: Save map contentns to external file?

2014-05-15 Thread Stephen Gilardi

On May 15, 2014, at 3:35 PM, Steven Jones ple...@gmail.com wrote:

 Thanks, edn looks like the way to go but your example is not quite
 working. The issue appears to be with pr.
 
 (defn foo [] 'foo)
 
 (def data {0 foo,
1 '[a b c]})
 
 (spit filename (pr data))

Use pr-str instead of pr. It returns a string containing the text representing 
data.

 Second despite the documentation that pr output is a readable format,
 when I attempt to read it I get a runtime exception of Unreadable form 
 
 
 (pr foo)
 -- #core$foo edntest.core$foo@7dce092nil
 
 #core$foo edntest.core$foo@7dce092
 -- RuntimeException Unreadable form  clojure.lang.Util.runtimeException 
 (Util.java:219)


There is no built-in way to access an existing function value as readable data. 
Searching the google group history for serializable function yields some 
discussion of the issues involved.

If you have access to the code for the function at the time it's being loaded 
into clojure (read and compiled), you can write code to capture the text of the 
function definition from there.  This lib woks along those lines and might be 
useful to you: https://github.com/technomancy/serializable-fn/

You may also want to consider another representation for function values, 
something like registering them by name and serializing the name could work. It 
depends on how much control you have over the environment around serializing 
and deserializing and how general the capabilities of the serialized code need 
to be.

--Steve

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


Re: How to convert this list into map?

2014-05-10 Thread Stephen Gilardi
As a slight simplification you can take advantage of the fact that apply 
handles in-line arguments as well as a seq of arguments at the end. This also 
works:

user= (apply hash-map :op '(:= :language Clojure))
{:op :=, :language Clojure}

--Steve

On May 10, 2014, at 6:37 PM, Hussein B. hubaghd...@gmail.com wrote:

 That is beautiful! Thanks a lot!
 
 which can be produced by prepending :op to your original list
 
 (conj '(:= :language Clojure) :op)

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


Re: What does ^{} actually translate to?

2014-05-08 Thread Stephen Gilardi

On May 8, 2014, at 8:34 AM, Pascal Germroth funkyco...@gmail.com wrote:

 I'm trying to attach metadata to some values (not the vars holding them).
 I thought ^{x} y was the same as (with-meta y {x}),

There was a recent thread about this here. 
https://groups.google.com/forum/#!searchin/clojure/metadata$20reader/clojure/iyYwwWPgv2U/xh-4SonzudkJ

^ is a reader macro that applies metadata to a target. The target is the result 
of reading the form that immediately follows the metadata form. ^ operates at 
read time, after the target form is read, but before it is evaluated. There are 
some subtleties in your example that make exactly what's happening not obvious. 
As a tool for understanding, read-string on a string can help by giving you 
visibility into the reader's operation alone. This is in contrast to the REPL 
where the result you see is after both read and eval have completed.

 but while it works for f2/f4, f1's metadata is nowhere to be found, while f3 
 works as expected:
 
 (def f1 doc ^{:x 1} (partial inc))
 (meta f1) ; nil, unexpected
 (meta #'f1) ; contains :doc, but not :x, as expected

The target form in this case is (partial inc). Checking (read-string 
(partial inc)) confirms that the reader returns a list containing two 
symbols. The reader macro ^ applied the metadata to that list. The evaluator 
then evaluated that list by invoking the function bound to the var 
clojure.core/partial. That function has no access to the metadata on the list 
that the reader read. After evaluation there is no longer any reference to that 
list or its metadata. They are both dropped.

 (def f2 doc ^{:x 2} #(inc %))
 (meta f2) ; {:x 2}, as expected
 (meta #'f2) ; contains :doc, but not :x, as expected

The target form in this case is #(inc %). (read-string #(inc %)) shows that 
the reader returns a list like this (containing a symbol, a vector, and a list):

(fn* [p1__1925#] (inc p1__1925#))

The name fn* is an implementation detail, you can think of it as fn.

Because fn is a special form, it does have access to the list that was returned 
by the reader and the metadata on it. One thing fn does is transfer the 
metadata on that list to the function object it creates. That's why (meta f2) 
works as you expected.

There was no metadata applied to the symbol f2. If there had been it would have 
been transferred by the special form def to the var it created. Your 
expectation here is probably based on the action of the defn macro which 
transfers metadata in a defn form to the var it creates.

 (def f3 doc (with-meta (partial inc) {:x 3}))
 (meta f3) ; {:x 3}

with-meta operates after (partial inc) is evaluated so it applies the metadata 
to the function object returned by partial.

 (def f4 doc (with-meta #(inc %) {:x 4}))
 (meta f4) ; {:x 4}

same here.

--Steve

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


Re: Contagious BigDecimals?

2014-05-07 Thread Stephen Gilardi

On May 7, 2014, at 12:11 PM, Mars0i marsh...@logical.net wrote:

 To me, the fact that BigDecimal is contagious sometimes but not always, seems 
 confusing in a way that could encourage bugs.  The fact that BigInts are 
 contagious would also lead one to assume that BigDecimals are contagious.

I don't think it's a case of sometimes but not always. Instead there's a 
contagion precedence order such that any type earlier in the order combined 
with a type later in the order yields the type later in the order.

Here's the order: Long  BigInt  Ratio  BigDec  Double

Before applying the contagion order, narrower integer types are promoted to 
Long, and float is promoted to Double.

See for reference the many implementations of opsWith in Numbers.java:
https://github.com/clojure/clojure/blob/clojure-1.6.0/src/jvm/clojure/lang/Numbers.java#L411

--Steve

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


Re: clojure.repl/pst problem

2014-05-07 Thread Stephen Gilardi

On May 7, 2014, at 12:55 PM, Plínio Balduino pbaldu...@gmail.com wrote:

 But the documentation also shows that I can set the depth of stacktrace, what 
 I guess that can be a number of lines:
 
 (pst 5)
 
 IllegalArgumentException No matching field found: getStackTrace for class 
 java.lang.Long  clojure.lang.Reflector.getInstanceField (Reflector.java:271)
 
 Nope.

I see the behavior you see with Clojure 1.5.1.

With Clojure 1.6.0 I get 5 lines of stack trace.

--Steve

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


Re: ClassCastException: Object arguments

2014-05-04 Thread Stephen Gilardi
 How do you call a method which accepts Object arguments?
 
 String/format | 
 http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#format(java.lang.String,
  java.lang.Object...)
 
 user= (String/format %s foo)
 ClassCastException java.lang.String cannot be cast to [Ljava.lang.Object;  
 user/
 eval668 (NO_SOURCE_FILE:1)


String/format takes a variable number of arguments in Java. At the JVM level, 
that's represented as an array of Objects.

The JVM level class name for an array of objects is shown in the exception: 
[Ljava.lang.Object

Here's an example of calling String/format correctly:

https://github.com/clojure/clojure/blob/clojure-1.6.0/src/clj/clojure/core.clj#L5284

(String/format fmt (to-array args)

In the case of String/format itself it may be easier to call 
clojure.core/format instead, but the same pattern applies elsewhere.

If you need an array whose elements have a type more specific than Object, use 
clojure.core/into-array.

--Steve

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


Re: Basic question: metadata reader

2014-05-03 Thread Stephen Gilardi
 I just read:
 
 http://clojure.org/reader
 
 Metadata (^)
 Metadata is a map associated with some kinds of objects: Symbols, Lists, 
 Vector, Sets, Maps, tagged literals returning an IMeta, and record, type, and 
 constructor calls. The metadata reader macro first reads the metadata and 
 attaches it to the next form read (see with-meta to attach meta to an object):
 ^{:a 1 :b 2} [1 2 3] yields the vector [1 2 3] with a metadata map of {:a 1 
 :b 2}.
 
 Ok, but how the reader works?


The description above is literally how it works: The metadata reader macro 
first reads the metadata and attaches it to the next form read.

Reader macros are implemented within the reader. They are distinct from 
defmacro macros.

The implementation is here:
https://github.com/clojure/clojure/blob/clojure-1.6.0/src/jvm/clojure/lang/LispReader.java#L706

The reader reads from an input stream; it:

  - reads the metadata object, meta [L716]
  - reads the object that follows it, o [L724]
  - figures out how to apply meta to o based on the interface(s) o implements 
[L725.L731]
  - applies meta to o [L733,L741]

--Steve

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


Re: Cleaner solution, anyone?

2014-05-01 Thread Stephen Gilardi
 I wrote a blog post discussing Thomson's Paradox, and simulated it in Clojure-
 http://pizzaforthought.blogspot.in/2014/05/and-infinity-beyond.html
 
 The state function defined towards the end is not very functional. 
 Could someone guide me towards a cleaner approach?

Here's an option:

(defn state [t]
  (reduce (fn [[v0 t0] [v1 dt]]
(cond (zero? dt) (reduced unknown)
  ( t0 t) (reduced v0)
  :else [v1 (+ t0 dt)]))
  [true 0]
  (thomsons-lamp)))
 
cljs.user= (state 0)
true
cljs.user= (state 0.99)
true
cljs.user= (state 1)
false
cljs.user= (state 1.49)
false
cljs.user= (state 1.5)
true
cljs.user= (state 1.)
true
cljs.user= (state 1.9)
false
cljs.user= (state 2)
unknown
cljs.user= 

--Steve

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


Re: puzzled by RuntimeException

2014-04-23 Thread Stephen Gilardi
 Just FYI, some background on keywords that start with a number...
 
 The reader docs (http://clojure.org/reader) states that symbols (and keywords 
 follow symbols in these rules) must begin with a non-numeric character.


Thanks, Alex. The REPL-y and sjacket issues cited the Clojure issues in Jira 
and I looked through them.

There seems to be an assumption in the discussion I've seen that the current 
description of keywords at http://clojure.org/reader means that the characters 
*after* the leading colon in a keyword have to follow the rules for a symbol.

I think another reasonable way to interpret the description of keywords is that 
the spelling of a keyword *including the leading colon* has to follow the rules 
for a symbol -- with the obvious exception that a symbol's spelling *cannot* 
begin with a colon. Since a colon is always non-numeric, keywords *always* pass 
the begins with a non-numeric character test.

When I looked in the past at what it takes to parse a token in Clojure, I 
concluded that the syntax of numbers vs. non-numbers (including the syntax for 
numbers with a radix component) was chosen such that a token represents a 
number if and only if it has a leading numeric character. I've always 
interpreted the no leading numeric character rule for the spelling of symbols 
(and keywords, including the leading colon) as in support of that simple 
distinction. More generally, the reader can classify a token by its leading 
character, or leading 2 characters in the case of a leading #.

I don't see a similarly compelling reason to disallow numeric characters 
immediately after the leading colon in a keyword.

--Steve

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


Re: puzzled by RuntimeException

2014-04-22 Thread Stephen Gilardi

On Apr 22, 2014, at 5:37 PM, Greg D gregoire.da...@gmail.com wrote:

 I believe this is a problem in REPL-y, which is used when using 'lein repl'.
 
 I used Cider to start a nREPL server, then used 'leing repl :connect' to get 
 the REPL-y interface.
 
 The problem was evident in the latter, but not the former.  I opened an issue 
 for REPL-y.
 
 Thanks again, Steve

You're welcome!

Following on your evidence, I tried running REPL-y from a checkout and found 
that the current head of master (0.3.1-SNAPSHOT) doesn't throw the exception, 
but the current release (0.3.0) does.

I used git bisect to find the commit that changed the behavior and found this:

https://github.com/trptcolin/reply/issues/132 (Reader error on number-like 
keywords in maps)

The fix is here: https://github.com/cgrand/sjacket/pull/16 (Number-like 
keywords)

So, to avoid the exception you saw when using number-like keywords with lein 
repl, REPL-y needs a release and leiningen needs to pick it up.

... and we got a view of a slice of the Clojure lib ecosystem... three layers 
deep. Neat.

Cheers,

--Steve

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


Re: puzzled by RuntimeException

2014-04-21 Thread Stephen Gilardi

 The sequence in the transcript below shows runtime exceptions when a numeric 
 keyword is followed by a list starting with a symbol or character.
 
 Would anyone help me with a reason for the failing cases?
 
 user= (clojure-version)
 1.6.0
 user= '(:42 a)
 (:42 a)
 user= '(:42 a)
 (:42 a)
 user= '(:42 \a)
 (:42 \a)
 user= '(:42 nil)
 (:42 nil)
 user= '(:42 true)
 (:42 true)
 user= '(:42 :43)
 (:42 :43)
 user= '(:42 (a))
 
 RuntimeException EOF while reading, starting at line 1  
 clojure.lang.Util.runtimeException (Util.java:221)
 
 RuntimeException Unmatched delimiter: )  clojure.lang.Util.runtimeException 
 (Util.java:221)
 user= '(:42 (a))
 (:42 (a))
 user= '(:42 (\a))

I tried to duplicate this result with the clojure.main repl, but was unable to 
do so. All entries in your post read in without raising an exception.

I used this command line to launch the repl:

% java -cp ~/.m2/repository/org/clojure/clojure/1.6.0/clojure-1.6.0.jar 
clojure.main

--Steve

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


Re: Data Literals: How to handle read errors?

2014-04-13 Thread Stephen Gilardi

On Apr 13, 2014, at 8:31 AM, Thomas Heller th.hel...@gmail.com wrote:

 [...] confusing error messages.
 
 user= (pr-str #time/local-datetime [2014 4 1 0 0 2 999])
 
 [...]
 RuntimeException Unmatched delimiter: )  clojure.lang.Util.runtimeException 
 (Util.java:221)

Using default #inst reader gives the same behavior.

This is an artifact of how the repl currently works. Its input is a stream of 
characters to which it applies the read, eval, and print operations in a loop. 
There is prompt-handling code in the repl that makes it feel turn oriented in 
most cases, but this case isn't handled. It does not currently implement on 
exception in read, flush the rest of the pending user input and re-prompt.

Here's an example with a vanilla clojure 1.6.0 (java -jar the clojure 
1.6.0.jar) that may clarify what's going on:

user= (println 1 2 3 #inst 4 5 6 7 8 9)
RuntimeException Unrecognized date/time syntax: 4  
clojure.instant/fn--6236/fn--6237 (instant.clj:118)
5
6
7
8
9
RuntimeException Unmatched delimiter: )  clojure.lang.Util.runtimeException 
(Util.java:221)

The start of the list (println 1 2 3 reads fine, then the #inst read throws 
an exception. After the exception, the repl starts working on the remainder of 
the input characters as if it were fresh user input. It sees integers and 
prints them. When it hits ), there's no corresponding ( pending, so it 
throws again.

--Steve

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


Re: Is it possible to give an atomic message?

2014-04-12 Thread Stephen Gilardi

On Apr 12, 2014, at 7:24 AM, Cecil Westerhof cldwester...@gmail.com wrote:

 2014-04-12 11:40 GMT+02:00 Max Penet m...@qbits.cc:
 Be aware that SimpleDateFormat is not threadsafe though.
 
 What should I use instead of SimpleDateFormat then?  

One solution to that facet of the problem is to use a ThreadLocal instance of 
SimpleDateFormat.

There's an example of that here: 
https://github.com/clojure/clojure/blob/clojure-1.6.0/src/clj/clojure/instant.clj#L160

--Steve

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


Re: list all functions in namespace?

2014-04-04 Thread Stephen Gilardi
On Apr 4, 2014, at 7:53 PM, Christopher Howard cmhowa...@alaska.edu wrote:

 Is there some trick Clojure command to list all functions defined in a 
 namespace?

http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/ns-publics 
is a good start.

--Steve

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


Re: How to update an atom return the change?

2014-03-20 Thread Stephen Gilardi
There was a stackoverflow question recently that requested a solution for a 
similar problem:

https://stackoverflow.com/questions/22409638/remove-first-item-from-clojure-vector-atom-and-return-it

One solution there is similar to this:

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

This will return the correct old-value and new-value which you can diff.

Another note: 

 (swap! state #(update-in % [:teams] make-team))

can be written more succinctly:

(swap! state update-in [:teams] make-team)

--Steve

On Mar 20, 2014, at 6:28 PM, Jakub Holy jakub.h...@iterate.no wrote:

 I have couple of times run into a situation where I want to update a state 
 map held in an atom
 and return the change, not the new value. I haven't found a good way to do it 
 so either I am missing
 something obvious or there are more idiomatic ways to achieve what I need. 
 Could you advise me?
 
 A concrete example: In ma webapp I want to assign a unique random ID to each 
 user. Creating that ID is simple:
 
 (def state (atom {:teams {}}))
 
 ;; Remove already used IDs from a lazy seq of random IDs (= unique), take 
 the 1st one
 (defn unique-rand-id [id-set]
   (first (remove id-set (repeatedly #(rand-int Integer/MAX_VALUE))
 
 ;; Add a new team with a unique random ID to the teams map
 (defn make-team [teams]
   (let [id (unique-rand-id (set (keys teams)))]
 (assoc teams id {})))
 
 ;; Create a new team; TODO: How to get the new team's ID?!
 (swap! state #(update-in % [:teams] make-team))
 
 So I can generate and remember a new unique random ID but there is no way to 
 find out
 what ID it was (I cannot just take diff of state before and after since other 
 threads could
 have also added new IDs to it in the meanwhile.)
 
 Any advice is appreciated. Thank you!
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

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


Re: Is it possible to get Clojure files in Spotlight search?

2014-02-19 Thread Stephen Gilardi
I'm aware of one Mac application that declares to OS X that it handles Clojure 
source files: Light Table http://www.lighttable.com/.

In its info.plist, Light Table declares .clj .cljs and .edn to map to 
Document Type Name Clojure Source and marks itself as the default Editor 
for them.

However, in contrast to its Document Type entry for Javascript Source file, it 
does not declare any Document Content Type UTIs values for them.

Wikipedia has a good article on the UTI system 
(https://en.wikipedia.org/wiki/Uniform_Type_Identifier). It's possible that 
Light Table could be changed to associate the file extensions above with the 
UTI public.source-code. That might give the effect you're after.

--Steve

On Feb 19, 2014, at 4:10 AM, Matt Mower matt.mo...@gmail.com wrote:

 Hi.
 
 I recently bought a nice OSX app called Tembo which makes spotlight searching 
 a more pleasant experience. In particular it has a Source Code grouping 
 which is handy but know nothing about Clojure files.
 
 I spoke to the author of Tembo and quote his response here
 
 Tembo relies on the Universal Type Identifier hierarchy to map files to 
 groups.
 It hard-codes only very few exception. In the case of source code, there 
 is currently no exception.
 
 It will probably not be possible to hard-code an exception for clj/cljs
 Tembo works only with UTIs. The application owning the clj file extension 
 will need to provide the mapping from file extension to UTI
 When doing so, it can also specify which high level UTI this conforms to. 
 I.e. it can declare it to be source code.
 
 Googling the file extension, I found this: 
 http://softnoise.wordpress.com/tag/quicklook/
 
 It is a hack to have a QuickLook plug-in declare the UTI. This should be 
 good enough and should get QuickLook working.
 You probably won't have Spotlight indexing the file contents though.
 
 I had a look at the QLColourCode plugin but it doesn't build for me in Xcode4 
 and doesn't appear to be maintained. There's also a suggestion that it 
 stopped working in the 10.6-10.7 transition.
 
 Do any Clojure users on OSX have a working solution for this problem?
 
 Kind regards,
 
 Matt
 
 p.s. I realise this is a Mac specific question but I figured I had a better 
 shot of finding an answer among Clojure using Mac folk.
 
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.

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


Re: set!

2013-03-13 Thread Stephen Gilardi
The repl's thread binding for those vars is set here:

  https://github.com/clojure/clojure/blob/master/src/clj/clojure/main.clj#L267

using this macro:

  https://github.com/clojure/clojure/blob/master/src/clj/clojure/main.clj#L85

Users of your library would need to do something similar, possibly wrapping a 
call to clojure.main/repl within a clojure.core/with-bindings form, to allow 
the same set! ability for your vars.

--Steve

On Mar 13, 2013, at 5:47 PM, Mark Engelberg mark.engelb...@gmail.com wrote:

 On Wed, Mar 13, 2013 at 2:36 PM, Michael Klishin 
 michael.s.klis...@gmail.com wrote:
 alter-var-root works fine for that purpose, e.g.
 https://github.com/michaelklishin/monger/blob/master/src/clojure/monger/core.clj#L168-171
 
 Thanks.  That's probably what I'll end up doing.  Still, it would be nice to 
 understand whether it's possible to achieve the same effect as Clojure core's 
 settable vars. 

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




Re: Why can't I use/require namespaces not associated with files?

2011-11-18 Thread Stephen Gilardi



why does the existance of a namespace not suffice to use or require it?
Currently, with clojure 1.3, it has to be associated with a class or
clojure file.



The primary purpose of both use and require is to load code from a file in 
classpath.



So while I can't use or require it, I can refer it. However, what I
really want to do is to require it with some short alias.
Unfortunately, refer doesn't support an :as option.


For the purpose you describe, alias should work. (:as uses alias to do its job)

user (doc alias)
-
clojure.core/alias
([alias namespace-sym])
 Add an alias in the current namespace to another
 namespace. Arguments are two symbols: the alias to be used, and
 the symbolic name of the target namespace. Use :as in the ns macro in 
preference
 to calling this directly.

--Steve


--
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: (. Classname-symbol (method-symbol args*))

2008-11-15 Thread Stephen Gilardi

In my opinion, idiomatic Clojure for this is:

(.println System/out smile)

--Steve

On Saturday, November 15, 2008, at 09:32PM, .Bill Smith [EMAIL PROTECTED] 
wrote:

Clojure doesn't know what to do with System.out; you need to express
that as (. System out).  Of course (.. System out (println wtf)) is
equivalent to (. (. System out) (println wtf))

I hope that helps.

Bill


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: reader macros

2008-11-15 Thread Stephen Gilardi

Clojure does not currently allow programs to define new reader macros. That is 
unlikely to change.

There are more details here:

http://groups.google.com/group/clojure/search?group=clojureq=reader+macroqt_g=Search+this+group

There is a clever technique described on the wiki that allows Clojure Shebang 
scripts:

http://en.wikibooks.org/wiki/Clojure_Programming#Shebang_Scripting_in_Clojure

(There's a link there that points to a posting that explains how it works.)

--Steve
 
On Saturday, November 15, 2008, at 07:52PM, Jeff Rose [EMAIL PROTECTED] 
wrote:

Hi, I'm finding comments talking about reader macros, but nothing about 
defining them.  Does anyone know of an example for adding new read 
macros?  I'd like to define a #! macro that passes over the rest of the 
line so we can use clojure scripts just as easily as a ruby script would 
be.  If anyone knows another way to do this, that would be great too.

Thanks,
Jeff


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---