Re: Prototype code for enhanced CIDER code completion for Java methods

2018-10-16 Thread Aaron Cohen
This seems like it could be done using threading.

(-> "my-string"
   (.ch<-- completion should give you good results here, for only
String methods


(-> (new MyType)
  (.<-- completion should give you only methods of MyType


; One interesting case is the following:
(def foo "hello")

; foo's type isn't known, so would need to be hinted
(-> ^String foo
(.to  <-- good completions again, because of the type hint

I think you won't be able to get all the way to your jvm macro, but likely
pretty close, and it's much more idiomatic...

The doto macro is also useful in a similar way, and often what you want
when using some of the more byzantine java libraries.

(All of the above works in Cursive, I'm not sure about how it works in
CIDER, but I assume it's equivalent).

--Aaron



On Tue, Oct 16, 2018 at 8:30 PM 'somewhat-functional-programmer' via
Clojure  wrote:

> Comments inline...  I really appreciate you taking the time to look at
> this.  I think I am still imprecise in my language -- I hope the comments
> below doesn't come across as too tedious :-)...
>
> ‐‐‐ Original Message ‐‐‐
> On Tuesday, October 16, 2018 7:46 PM, Timothy Baldridge <
> tbaldri...@gmail.com> wrote:
>
> As you say, this is a limitation in the code completer. In Cursive this
> problem doesn't exist to this extent, when I type `(.get` the completer
> responds with a list of methods and classes that could be completed to that
> method, starting with classes in the namespace I'm currently editing.
>
>
> I think we are saying the same thing here.  I believe compliment (the
> library CIDER/other clojure tooling uses for code completion) does what we
> are describing (showing Java methods and fields from multiple Java types
> that are imported into the namespace currently being edited (or type hinted
> in locals/function definitions).  My point is I want more -- I want the
> completion list to only include methods and fields from the type I as a
> developer know that I have.
>
> Like a Java IDE:
> MyType a = new MyType();
> Now typing "a." yields just completions valid for MyType, and not 5 other
> types I've used nearby.
>
> Yes, this takes static analysis, or perhaps some indexing and
> introspection. But changing the syntax is never really going to gain
> traction here, as manually typing the name of every method just so my
> editor can produce a list seems like me conforming to my tool rather than
> my tool learning to work with me.
>
>
> Just to make sure I'm completely clear -- I'm *not* advocating a change to
> clojure lang -- only proposing a macro/library.  The prototype macro I
> wrote simply transforms the (Type:method ...) syntax into the (.
> instance-expr member-symbol) that (.method ...) macroexpands into anyhow.
> This is not intended to replace (.method obj args) notation.
>
> I'm not sure what you mean by "manually typing the name of every method
> just so my editor can produce a list".
>
> The way this works is, you type "(MyType:" and get presented with a list
> of completions that are *only* applicable to MyType -- there's no manually
> typing lists of methods and fields anywhere.  And, the way this works for
> me in CIDER, I type "(My" and I get "(MyType", then I add a ":", and
> now I get completions just for MyType -- it also shows me the Java
> signature of the methods as I highlight a potential completion.  There's no
> manually seeding the list anywhere...
>
> The imported classes in the current namespace are stored in the mappings
> attribute. It seems like an editor should be able to install hooks into
> that and index the methods on the classes to provide this feedback.
> https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Namespace.java#L123
>
>
>
> Yes I agree -- and I believe that's exactly what the existing tooling
> already does -- I just want more precision.
>
> Some of my motivation has been working with monstrously large class
> libraries in Java.  GIS libraries in Java are notoriously class/method
> heavy and after importing many of these classes into a namespace,
> completion that cannot narrow down to the exact type I'm using for the
> reasons we agree on -- simply is painful to work with.
>
> On Tue, Oct 16, 2018 at 1:26 PM 'somewhat-functional-programmer' via
> Clojure  wrote:
>
>> I apologize for diving into a solution in my first email -- let me give a
>> little more of the background as to what I am trying to accomplish.
>>
>> I'm proposing an additional syntax for Java interop for the purpose of
>> allowing support for more precise code-completion of Java fields and
>> methods in Clojure tooling.  The new syntax proposal is why I'm emailing
>> this list rather than directly going to the project owners of the projects
>> I've modified to support this.  If there is high resistance to any
>> additional syntax for Java interop, there's not much reason to try to
>> convince the project owners of cider-nrepl and compliment to support
>> something just for my 

Re: Cyclic namespace dependencies!

2016-12-30 Thread Aaron Cohen
You already know this has been discussed a lot over the years.

I just wanted to cite the best reasoning that I've seen from Rich about why
Clojure does it the way that it does, which I believe is the argument that
surrounded an blog post fro Steve Yegge that Rich responded to and some
excellent discussion surrounding it on hackernews and the mailing list:
https://news.ycombinator.com/item?id=2466731

On hackernews, Rich made a post that I believe is the best "last word"
explaining his reasoning, which I'll quote here:

The issue is not single-pass vs multi-pass. It is instead, what constitutes
> a compilation unit, i.e., a pass over what?
>
> Clojure, like many Lisps before it, does not have a strong notion of a
> compilation unit. Lisps were designed to receive a set of
> interactions/forms via a REPL, not to compile files/modules/programs etc.
> This means you can build up a Lisp program interactively in very small
> pieces, switching between namespaces as you go, etc. It is a very valuable
> part of the Lisp programming experience. It implies that you can stream
> fragments of Lisp programs as small as a single form over sockets, and have
> them be compiled and evaluated as they arrive. It implies that you can
> define a macro and immediately have the compiler incorporate it in the
> compilation of the next form, or evaluate some small section of an
> otherwise broken file. Etc, etc. That "joke from the 1980's" still has
> legs, and can enable things large-unit/multi-unit compilers cannot. FWIW,
> Clojure's compiler is two-pass, but the units are tiny (top-level forms).
>
> What Yegge is really asking for is multi-unit (and larger unit)
> compilation for circular reference, whereby one unit can refer to another,
> and vice versa, and the compilation of both units will leave hanging some
> references that can only be resolved after consideration of the other, and
> tying things together in a subsequent 'pass'. What would constitute such a
> unit in Clojure? Should Clojure start requiring files and defining
> semantics for them? (it does not now)
>
> Forward reference need not require multi-pass nor compilation units.
> Common Lisp allows references to undeclared and undefined things, and
> generates runtime errors should they not be defined by then. Clojure could
> have taken the same approach. The tradeoffs with that are as follows:
>
> 1) less help at compilation time 2) interning clashes
>
> While #1 is arguably the fundamental dynamic language tradeoff, there is
> no doubt that this checking is convenient and useful. Clojure supports
> 'declare' so you are not forced to define your functions in any particular
> order.
>
> #2 is the devil in the details. Clojure, like Common Lisp, is designed to
> be compiled, and does not in general look things up by name at runtime.
> (You can of course design fast languages that look things up, as do good
> Smalltalk implementations, but remember these languages focus on dealing
> with dictionary-carrying objects, Lisps do not). So, both Clojure and CL
> reify names into things whose addresses can be bound in the compiled code
> (symbols for CL, vars for Clojure). These reified things are 'interned',
> such that any reference to the same name refers to the same object, and
> thus compilation can proceed referring to things whose values are not yet
> defined.
>
> But, what should happen here, when the compiler has never before seen bar?
>
> (defn foo [] (bar))
>
> or in CL:
>
> (defun foo () (bar))
>
> CL happily compiles it, and if bar is never defined, a runtime error will
> occur. Ok, but, what reified thing (symbol) did it use for bar during
> compilation? The symbol it interned when the form was read. So, what
> happens when you get the runtime error and realize that bar is defined in
> another package you forgot to import. You try to import other-package and,
> BAM!, another error - conflict, other-package:bar conflicts with
> read-in-package:bar. Then you go learn about uninterning.
>
> In Clojure, the form doesn't compile, you get a message, and no var is
> interned for bar. You require other-namespace and continue.
>
> I vastly prefer this experience, and so made these tradeoffs. Many other
> benefits came about from using a non-interning reader, and interning only
> on definition/declaration. I'm not inclined to give them up, nor the
> benefits mentioned earlier, in order to support circular reference.
>
> Rich
>

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

Re: [moderated] I don't understand what (:t :t) means

2016-12-26 Thread Aaron Cohen
(:t :t) is a function invocation. Clojure always attempts to invoke the
first element of a list as a function unless told not to, this is one of
the fundamental behaviours of a lisp.

In this case, clojure will attempt to invoke the keyword ":t" as a
function. Keywords are actually invokable in clojure, their behaviour is to
look themselves up in the specified collection.

For instance: (:t {:t "Here", :r "There"}) would return "Here".

In your example, the parameter is not a collection though, it's the same
keyword again, ":t". Attempting to do a collection look up using a
non-collection is defined to return nil.

Thus, (:t :t) -> nil

If you wish to create a structure by preventing clojure from using the
first element as a function, you must "quote" your example, ie, (quote (:t
:t)) or '(:t :t) then the structure would be a list with two elements.

--Aaron

On Mon, Dec 26, 2016 at 10:17 AM, Stuart Sierra  wrote:

> As a moderator, I am posting this message on behalf of a new forum user,
> below. I have edited the message for appropriate language. –Stuart S.
>
>
> From: silver1 silver1 
> Date: Mon, 26 Dec 2016 22:11:17 +0800
> Subject: I don't understand (:t :t)mean ,please help me !!
>
> hello,everyOne,i'm a new clojure learner.
> I don't know what the structure of (:t :t)!
> when i use coll? list? vector? set? map? seq? they all return false!!
> what is the structure of (:t :t)? thank you very much!
>
> --
> 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: Java interop: dealing with Java implementation instances vs interfaces

2016-10-17 Thread Aaron Cohen
My guess is that you're getting a message related to there being no
overload of the Producer.send method that accepts a String.

In your Java code, you're calling String.getBytes you need to do the same
in you Clojure code.

--Aaron

On Sun, Oct 16, 2016 at 2:42 AM, hiskennyness  wrote:

> Not sure if this is a Java question or Clojure question, but I think it is
> the latter.
>
> I am trying to use the Yahoo pulsar library https://mvnrepository.
> com/artifact/com.yahoo.pulsar/pulsar-client/1.14 from Clojure.
>
> It is going OK in general, but a couple times now trying to replicate Java
> code such as:
>
> Producer producer = client.createProducer("persistent://sample/
> standalone/ns1/my-topic");
>
> ..with:
>
>   (let [prod (.createProducer client "persistent://sample/
> standalone/ns1/ktopic")]
> )
>
> ...all goes well except I end up with prod bound to an instance of
> ProducerImpl.
>
> My Java is zilch but I presume the Java code binding the impl to a var
> type Producer is why the code can then execute:
>
> producer.send("my-message".getBytes());
>
> ...whereas I get an error about send not being defined when I do:
>
> (.send prod "Hi Mom")
>
> I looked around for a way to "cast" the impl to a Producer but came up
> empty.
>
> I did find a public sendAsync on ProducerImpl and that almost worked but
> then I ran into the same impl vs interface issue with another class
> (MessageBuilder) and decided I better figure this issue out once and for
> all.
>
> Any ideas?
>
> -kt
>
>
>
> --
> 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: Mutual Recursion Doesn't Compile

2016-03-31 Thread Aaron Cohen
On Thu, Mar 31, 2016 at 1:36 PM, Lucas Sloan <
predictably.defenestra...@gmail.com> wrote:

> I have some mutually recursive code as follows:
>
>
Depending on your preferences, either forward declare using "declare" or
use "letfn".

Your next question will likely be, "How do I make mutually recursive
functions not run out of stack space?" and the answer for that is
"trampoline".

https://clojuredocs.org/clojure.core/declare
https://clojuredocs.org/clojure.core/letfn
https://clojuredocs.org/clojure.core/trampoline

--Aaron

-- 
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 make a function of a map argument ?

2015-10-23 Thread Aaron Cohen
I think you might find the following blog post helpful:
http://blog.jayfields.com/2011/01/clojure-select-keys-select-values-and.html

What you are asking for is basically (clojure.string/join (select-values
my-map vals)) where select-values is defined in several ways in the linked
blog post.

For code golf points, the briefest example from the blog that would work
for your purposes might be:

(defn select-values [m ks] (map m ks))

So:

user=> (def my-map { :name "roelof", :city "big-secret" })

user=> (clojure.string/join ", " (map my-map [:name :city]))
"roelof, big-secret"


On Fri, Oct 23, 2015 at 7:49 AM, r/ Wobben  wrote:

> Hello,
>
> As a challenge I need to convert a map structure to a csv structure.
>
> So ( { :name "roelof", :city secret }) need to be converted to roelof,
> secret.
>
> I think I can use something like (map clojure.string/join  ..) for it but
> it seems I have to make a function out of the :name roelof part to get
> roelof back.
>
> I could use  get for then I do not know how to call 1 records of the whole
> map.
>
> Can someone explain in simple English how I can solve this one ?
>
> --
> 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: [ANN] paren-soup 0.1.1, a browser-based editor for CLJS

2015-09-08 Thread Aaron Cohen
For me, the instarepl column seems to be unreadable because all the results
have horizontal scrollbars that entirely obscure the results.

On Tue, Sep 8, 2015 at 4:38 PM, Zach Oakes  wrote:

> This is a ClojureScript viewer and editor you can embed in any website. I
> hope to make it better than CodeMirror for those who don't need polyglot
> support. I announced it last week but it was pretty much unusable because
> it didn't have paren completion. Now it is slightly more usable. Here are
> the features:
>
>- Syntax highlighting
>- Rainbow delimiters
>- Automatic indentation
>- InstaREPL (à la Light Table)
>
> Code: https://github.com/oakes/paren-soup
> Demo: http://oakes.github.io/paren-soup
>
> I use the new ClojureScript eval capability for the instarepl, and the new
> CLJS version of tools.reader to provide highlighting and indentation. The
> downside to using tools.reader is that reader errors break both of those
> things, which is why paren completion was strictly necessary! It is still
> pretty flawed, but hopefully I'll be able to make this production-ready
> eventually.
>
> --
> 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: [ANN] paren-soup 0.1.1, a browser-based editor for CLJS

2015-09-08 Thread Aaron Cohen
I should have given you that information up front, sorry.

I just tried it in Windows 10 using both Edge and Chrome and both have
scrollbars. Earlier I was using Chrome in Windows 7.

I was able to fix it in the inspector using "overflow: hidden":

.paren-soup .instarepl .result {
position: relative;
overflow: hidden;
background-color: lightgreen;
outline: 1px solid;
}


On Tue, Sep 8, 2015 at 8:46 PM, Zach Oakes  wrote:

> I'm bad at CSS, but it looks like there isn't a standard way to hide
> scrollbars in browsers without removing the ability to scroll. Are you
> using Windows? Maybe I can boot up a VM and try things out to fix this
> issue.
>
>
> On Tuesday, September 8, 2015 at 5:05:32 PM UTC-4, Zach Oakes wrote:
>>
>> Yeah I should've tested on a non-Mac. That should just be a CSS change if
>> there is a way to make scrollbars disappear. I'll look into it soon.
>
> --
> 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: [ANN] Glow version 0.1.2 released - a parser and syntax highlighter for Clojure source code.

2015-08-18 Thread Aaron Cohen
I'm curious why you chose to write your own parser rather than use
clojure.tools.analyzer https://github.com/clojure/tools.analyzer?

On Tue, Aug 18, 2015 at 10:53 AM, W. David Jarvis venant...@gmail.com
wrote:

 Hey all -

 I'm happy to announce the release of version 0.1.2 of Glow
 https://github.com/venantius/glow, the syntax highlighting library I
 open-sourced about a month ago.

 This release comes with a number of massive changes as to the underlying
 nature of the library. In essence, I've moved away from a
 regular-expression driven approach in favor of using a lexical parser to
 build up a parse tree from the input string, which is then transformed into
 a syntax-highlighted string.

 This has two advantages. First, it avoids a major problem I was having
 with the regular expression approach in the form of a StackOverflowError
 when attempting to identify long string literals within the input string.
 Second, it produces an intermediate parse tree which can be transformed
 using fairly standard Instaparse transformations to achieve arbitrary
 formatting output (handy if, for instance, one wanted to produce HTML
 output or hiccup templates).

 It has some disadvantage as well. It's somewhat slower, though I believe
 the code to be more maintainable and comprehensible. It also requires the
 input source code to be valid and parseable Clojure code, which you can
 think of as either an advantage or a disadvantage :P

 Although I had hoped initially to use Instaparse for the project's parser,
 I ended up getting considerably better performance from ANTLR / clj-antlr,
 and so that's the path I've gone down. You can take a look at the ANTLR
 Clojure grammar Glow uses here
 https://github.com/venantius/glow/blob/master/resources/parsers/Clojure.g4
 - I believe it to be comprehensive, and it handles a number of edge cases
 that the grammar in the main ANTLR grammar repo does not.

 As always, I hope you get some usage out of this, and please do files
 issues, PRs, etc (project page: https://github.com/venantius/glow) - or
 just tweet at me @venantius https://twitter.com/venantius.

 Cheers,

  - V

 --
 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 exclude compile-time dependencies from uberjar?

2015-06-30 Thread Aaron Cohen
My understanding is that those dependencies should go into the dev
profile, which won't be included in the uberjar.

On Tue, Jun 30, 2015 at 4:56 AM, Robin Heggelund Hansen 
skinney...@gmail.com wrote:

 I'm trying to get the smallest uberjar as possible. Currently I have a
 bunch of dependencies for compiling server resources (clojurescript,
 garden...) that are required at compile-time, but don't have to be in the
 uberjar. How can I create an uberjar without bundling these resources?

 Thanks!

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

2015-06-26 Thread Aaron Cohen
I took a swing at this using prismatic schema:

(ns schema-test.core
  (:require [schema.core :as s]
[schema.utils :as utils]
[schema.coerce :as coerce])
  (:import schema.core.NamedSchema))

(def Alternate (s/named [s/Keyword] alternate))

(def Path (s/named [(s/either s/Keyword Alternate)] path))

(def T [(s/either s/Keyword Path)])


(def example [ :a   [:a :b :c][:a  [:b1 :b2] :c ] ] )

(defn annotater [schema]
  (s/start-walker
   (fn [s]
 (let [walk (s/walker s)]
   (fn [x]
 (if (and (instance? clojure.lang.IObj x) (instance?
schema.core.NamedSchema s))
   (with-meta (walk x) {:schema (.name s)})
   (walk x)
   schema))

(defn annotate [schema data] ((annotater schema) data))

(def r (annotate T example))

(map meta r) ; = (nil {:schema path} {:schema path})

(meta (nth (nth r 2) 1)) ; = {:schema alternate}


On Thu, Jun 25, 2015 at 12:35 PM, Brian Marick mar...@exampler.com wrote:

 Suppose we have a structure like this:

[ :a   [:a :b :c][:a  [:b1 :b2] :c ] ]

 That is a *required* list. It consists of keywords and *paths* (nested
 vector like [:a :b :c] above). A path consists of keywords and *alternates*
 (a twice-nested vector like [:b1 :b2]) above.

 It's easy to descend this by hand and keep track of which type of vector
 you're dealing with. However, this sort of thing comes up enough that it
 would be convenient if there were a function that takes a grammar and a
 structure and returns that structure annotated (metadata?) with type
 information. Coupled with Specter https://github.com/nathanmarz/specter,
 that would make a good number of data transformations easy-peasy.

 Is there such a library? Or a library I can build on? A quick scan shows a
 lot of parsers for dealing with strings, but we've already got one of
 those: it's called `read`.

 @marick

 --
 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: a simple question about Arrays.asList

2015-05-21 Thread Aaron Cohen
Since Arrays.asList is a variadic method, the Java compiler is magically
creating an array behind the scenes for you when you write Java code
invoking it.

Clojure does variadic functions differently for native clojure code.

To do interop with a Java variadic method have to create the array yourself:
(java.util.Arrays/asList (make-array Object 1 2 3))

Why are you trying to use Arrays#asList btw? There are probably better ways
to do what you're trying to do.

--Aaron

On Thu, May 21, 2015 at 5:08 PM, webber tokomakoma...@gmail.com wrote:

 I am trying to use java.util.Arrays/asList in Clojure.

 (java.util.Arrays/asList 1 2 3)

 CompilerException java.lang.IllegalArgumentException: No matching method:
 asList, compiling:(NO_SOURCE_PATH:1:1)

 (java.util.Arrays/asList 1)

 ClassCastException java.lang.Long cannot be cast to [Ljava.lang.Object;
  user/eval7195 (NO_SOURCE_FILE:1)

 What should I do to work 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
 ---
 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: Border cases for doseq

2015-02-25 Thread Aaron Cohen
As penance, here's an example that is closer to what I was describing:

(require '[clojure.java.jdbc :as j])
(require '[clojure.pprint :as pp])

(def db-spec
{:subprotocol derby
 :classname org.apache.derby.jdbc.EmbeddedDriver
 :subname testDb
 :create true})

(j/db-do-commands db-spec
(j/create-table-ddl :fruit
[:name varchar(32) :primary :key]
[:appearance varchar(32)]
[:cost :int]
[:grade :real]))

(j/db-do-commands db-spec
(j/create-table-ddl :vegetables
[:name varchar(32) :primary :key]
[:appearance varchar(32)]
[:cost :int]
[:grade :real]))

;; Print the columns from all application tables
(pp/print-table [:table_name :column_name :type_name :column_size]
   (j/with-db-metadata [md db-spec]
  (j/metadata-result (.getColumns md nil APP nil nil


-

This produces:

| :table_name | :column_name | :type_name | :column_size |
|-+--++--|
|   FRUIT | NAME |VARCHAR |   32 |
|   FRUIT |   APPEARANCE |VARCHAR |   32 |
|   FRUIT | COST |INTEGER |   10 |
|   FRUIT |GRADE |   REAL |   23 |
|  VEGETABLES | NAME |VARCHAR |   32 |
|  VEGETABLES |   APPEARANCE |VARCHAR |   32 |
|  VEGETABLES | COST |INTEGER |   10 |
|  VEGETABLES |GRADE |   REAL |   23 |

On Wed, Feb 25, 2015 at 1:41 PM, Aaron Cohen aa...@assonance.org wrote:

 On Wed, Feb 25, 2015 at 1:35 PM, Cecil Westerhof cldwester...@gmail.com
 wrote:

 2015-02-25 19:23 GMT+01:00 Aaron Cohen aa...@assonance.org:

 On Wed, Feb 25, 2015 at 1:08 PM, Cecil Westerhof cldwester...@gmail.com
  wrote:



 2015-02-25 18:14 GMT+01:00 Andy Fingerhut andy.finger...@gmail.com:

 doseq does not have anything precisely like C/Java/Perl/etc.'s 'break'
 or 'continue'.  The closest thing might be the :while keyword.  You can 
 see
 some one example of its use near the end of the examples on this page:
 http://clojuredocs.org/clojure.core/doseq

 The best way I know to get such behavior is to use Clojure's loop,
 where if/when/whatever-conditional-statements-you-wish can used to control
 explicitly to do another loop iteration using recur, or not.


 ​I made the following with loop:
 (defn do-show-table
   [table]
   (loop [all-tables (show-tables db-spec)]
 (let [this-table (get (first all-tables) :table_name)]
   (if (= all-tables ())
   (printf Table not found: %s\n table)
 (if (= (lower-case table) (lower-case this-table))
 (let [format %-20s %-30s %-5s %-5s %-20s\n]
   (printf Table %s:\n table)
   (printf format Field Type Null? Key Default)
   (doseq [{:keys [field type null key default]}
  (jdbc/query db-spec [(str SHOW COLUMNS FROM 
 table)])]


 Please don't get into the habit of doing db queries like this, you're
 one Little Bobby Tables away from an sql injection. In this case you
 should do (jdbc/query db-spec [SHOW COLUMNS FROM ? table]).


 ​That gives:
 JdbcSQLException Syntax error in SQL statement SHOW COLUMNS FROM ?;
 expected identifier; SQL statement:
 SHOW COLUMNS FROM ? [42001-184]  org.h2.engine.SessionRemote.done
 (SessionRemote.java:622)
 ​

 ​That is why I do it in this way. As I understood it this has to do with
 that with a 'show columns from' the table can not be supplied. (I first
 tried Yesql, only when that did not work I went to JDBC.)​



 I see, sorry to jump the gun and be incorrect while doing so.


-- 
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: Border cases for doseq

2015-02-25 Thread Aaron Cohen
On Wed, Feb 25, 2015 at 1:35 PM, Cecil Westerhof cldwester...@gmail.com
wrote:

 2015-02-25 19:23 GMT+01:00 Aaron Cohen aa...@assonance.org:

 On Wed, Feb 25, 2015 at 1:08 PM, Cecil Westerhof cldwester...@gmail.com
 wrote:



 2015-02-25 18:14 GMT+01:00 Andy Fingerhut andy.finger...@gmail.com:

 doseq does not have anything precisely like C/Java/Perl/etc.'s 'break'
 or 'continue'.  The closest thing might be the :while keyword.  You can see
 some one example of its use near the end of the examples on this page:
 http://clojuredocs.org/clojure.core/doseq

 The best way I know to get such behavior is to use Clojure's loop,
 where if/when/whatever-conditional-statements-you-wish can used to control
 explicitly to do another loop iteration using recur, or not.


 ​I made the following with loop:
 (defn do-show-table
   [table]
   (loop [all-tables (show-tables db-spec)]
 (let [this-table (get (first all-tables) :table_name)]
   (if (= all-tables ())
   (printf Table not found: %s\n table)
 (if (= (lower-case table) (lower-case this-table))
 (let [format %-20s %-30s %-5s %-5s %-20s\n]
   (printf Table %s:\n table)
   (printf format Field Type Null? Key Default)
   (doseq [{:keys [field type null key default]}
  (jdbc/query db-spec [(str SHOW COLUMNS FROM 
 table)])]


 Please don't get into the habit of doing db queries like this, you're one
 Little Bobby Tables away from an sql injection. In this case you should
 do (jdbc/query db-spec [SHOW COLUMNS FROM ? table]).


 ​That gives:
 JdbcSQLException Syntax error in SQL statement SHOW COLUMNS FROM ?;
 expected identifier; SQL statement:
 SHOW COLUMNS FROM ? [42001-184]  org.h2.engine.SessionRemote.done
 (SessionRemote.java:622)
 ​

 ​That is why I do it in this way. As I understood it this has to do with
 that with a 'show columns from' the table can not be supplied. (I first
 tried Yesql, only when that did not work I went to JDBC.)​



I see, sorry to jump the gun and be incorrect while doing so.

-- 
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: Border cases for doseq

2015-02-25 Thread Aaron Cohen
On Wed, Feb 25, 2015 at 1:08 PM, Cecil Westerhof cldwester...@gmail.com
wrote:



 2015-02-25 18:14 GMT+01:00 Andy Fingerhut andy.finger...@gmail.com:

 doseq does not have anything precisely like C/Java/Perl/etc.'s 'break' or
 'continue'.  The closest thing might be the :while keyword.  You can see
 some one example of its use near the end of the examples on this page:
 http://clojuredocs.org/clojure.core/doseq

 The best way I know to get such behavior is to use Clojure's loop, where
 if/when/whatever-conditional-statements-you-wish can used to control
 explicitly to do another loop iteration using recur, or not.


 ​I made the following with loop:
 (defn do-show-table
   [table]
   (loop [all-tables (show-tables db-spec)]
 (let [this-table (get (first all-tables) :table_name)]
   (if (= all-tables ())
   (printf Table not found: %s\n table)
 (if (= (lower-case table) (lower-case this-table))
 (let [format %-20s %-30s %-5s %-5s %-20s\n]
   (printf Table %s:\n table)
   (printf format Field Type Null? Key Default)
   (doseq [{:keys [field type null key default]}
  (jdbc/query db-spec [(str SHOW COLUMNS FROM 
 table)])]


Please don't get into the habit of doing db queries like this, you're one
Little Bobby Tables away from an sql injection. In this case you should
do (jdbc/query db-spec [SHOW COLUMNS FROM ? table]).

I think you would be well-served by a general clojure principle here of
trying to get the data you're are dealing within into values as quickly
as possible, and then working with those.

Rather than inter-mixing your querying and display as you're doing here, I
would design this as a query to fill some maps describing your tables, and
then use clojure.pprint/print-table to print out the resulting map when
desired.

--Aaron





  (printf format field type null key default))
   (println))
   (recur (rest all-tables)))

 It solves both problems.


 On Wed, Feb 25, 2015 at 8:59 AM, Cecil Westerhof cldwester...@gmail.com
 wrote:

 At the moment I have the following function:
 (defn do-show-table
   [table]
   (doseq [{:keys [table_name]} (show-tables db-spec)]
  (when (= (lower-case table) (lower-case table_name))
(let [format %-20s %-30s %-5s %-5s %-20s\n]
  (printf format Field Type Null? Key Default)
  (doseq [{:keys [field type null key default]}
   (jdbc/query db-spec [(str SHOW COLUMNS FROM 
 table)])]
 (printf format field type null key default))

 In this case it is not very important, because the outer sequence will
 not be very big. But I would like to leave the doseq at the moment that the
 when is executed. It will be done 0 or 1 times, so after it is done, there
 is no use in continuing the sequence walk.

 The second part is that I would like to do an action if it is done 0
 times after the doseq. Is this possible?


 --
 Cecil Westerhof

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


Reducers question

2015-02-09 Thread Aaron Cohen
I'm not sure if the 4-arity fold function is working as expected. My
understanding is that it should be equivalent to the 3-arity version, but
with specified parallelism.

However:

(r/fold r/cat r/append! [1 2 3]) = [1 2 3]

(r/fold 1 r/cat r/append! [1 2 3]) = #Cat
clojure.core.reducers.Cat@4b2ae664

I don't actually understand how this is possible from reading the source
code.

--Aaron

-- 
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: [ANN] Clojure 1.7.0-alpha5 now available

2015-01-22 Thread Aaron Cohen
This is a different though related problem to
http://dev.clojure.org/jira/browse/CLJ-1315

That problem was trying to solve require un-necessarily importing
classes, your example is a type hint with a similar issue.

I do think you're correct, it looks like a reasonable change, but it would
require some investigative work to see if it breaks anything.

--Aaron


On Thu, Jan 22, 2015 at 1:23 PM, Adam Clements adam.cleme...@gmail.com
wrote:

 Just to follow up, doing the obvious (though perhaps naïve) fix of
 changing forName to forNameNonLoading in the referenced maybeClass does
 seem to fix the issue and I can now AOT compile my application without
 needing the binaries for this machine. I don't know whether this change
 would have any other repercussions though.


 On Thu Jan 22 2015 at 17:49:37 Adam Clements adam.cleme...@gmail.com
 wrote:

 I think I am seeing static initialisers being run at AOT time when the
 class is used as a type hint tag. This isn't a regression from previous
 versions of clojure, but with the forNameNonLoading changes that have gone
 in recently I was under the impression that this shouldn't be a problem any
 more.

 My specific case has a static initialiser which loads a native library
 (and I don't have the appropriate binary architecture for the machine doing
 the compilation).

 The function definition
 (defn some-function [^com.my_class.ExampleWhichLoadsNative x] ...)

 fails at AOT compile time with the (abridged) stack trace containing:
 ...
 at clojure.lang.Compiler.analyzeSeq(Compiler.java:6715)
 at clojure.lang.Compiler.analyze(Compiler.java:6499)
 at clojure.lang.Compiler.analyzeSeq(Compiler.java:6696)
 at clojure.lang.Compiler.analyze(Compiler.java:6499)
 at clojure.lang.Compiler.access$200(Compiler.java:38)
 at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:560)
 at clojure.lang.Compiler.analyzeSeq(Compiler.java:6708)
 at clojure.lang.Compiler.analyze(Compiler.java:6499)
 at clojure.lang.Compiler.analyze(Compiler.java:6460)
 at clojure.lang.Compiler.compile1(Compiler.java:7285)
 at clojure.lang.Compiler.compile(Compiler.java:7356)
 at clojure.lang.RT.compile(RT.java:406)
 ...
 Caused by:
 ...
 my class clinit
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:274)
 at clojure.lang.RT.classForName(RT.java:2127)
 at clojure.lang.RT.classForName(RT.java:2136)
 at clojure.lang.Compiler$HostExpr.maybeClass(Compiler.java:1000)
 at clojure.lang.Compiler$HostExpr.tagToClass(Compiler.java:1092)
 at clojure.lang.Compiler.tagClass(Compiler.java:8187)
 at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5218)
 at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3900)
 at clojure.lang.Compiler.analyzeSeq(Compiler.java:6706)
 ...

 On Wed Jan 21 2015 at 23:58:28 Alan Moore kahunamo...@gmail.com wrote:

 Sweet - thanks for the reply. I hope I didn't sound impatient... I'm
 very grateful for your hard work on it. I'd offer to help but I'm sure it
 is beyond me and my crazy-mad Clojure skillz(tm). I think I'll leave the
 hard stuff to the real experts :-)

 Alan


 On Wednesday, January 21, 2015 at 6:07:13 AM UTC-8, Alex Miller wrote:

 I am actively working on an updated set of patches, hopefully for
 inclusion in the next alpha.

 Alex

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


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

Re: Loading native libs from Clojure

2014-05-13 Thread Aaron Cohen
System.loadLibrary in java has counter-intuitive behaviour. It examines the
stack to figure out what class invoked it, then loads the native library
into the Classloader of that class. At the REPL, this classloader is
usually a transient instance of DynamicClassLoader, which isn't very
helpful in terms of actually having access to the library once it's been
loaded.

This is why the function clojure.lang.RT/loadLibrary exists. Since RT is
loaded by clojure's parent classloader, any libraries loaded using that
method end up in the correct place.

TLDR: use (clojure.lang.RT/loadLibrary ...) instead of
(java.lang.System/loadLibrary ...)

--Aaron



On Tue, May 13, 2014 at 3:00 PM, Gary Verhaegen gary.verhae...@gmail.comwrote:

 Hi everyone,

 I have recently been working on something [0] that required (consisted
 mainly of, really) loading native dlls. I have encountered a
 surprising (to me) behaviour: calling (System/load path) from Clojure
 correctly loaded the library, but did not link the JNI methods,
 whereas just switching to Java did link everything correctly.

 I spent more time on this than I care to admit, but in the end what
 worked was creating a Java class with a single static method that
 called System.load [1] and calling that from Clojure [2].

 So my question is: is that somehow expected behaviour, or should I
 file a bug report (after I investigate a bit more so I can provide
 more details)?


 [0] https://github.com/gaverhae/naughtmq
 [1]
 https://github.com/gaverhae/naughtmq/blob/master/src/naughtmq/PrivateLoader.java
 [2]
 https://github.com/gaverhae/naughtmq/blob/master/src/naughtmq/core.clj#L89

 --
 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: probably a noobie question: apparent memory leak

2014-03-29 Thread Aaron Cohen
On Sat, Mar 29, 2014 at 10:09 AM, Ryan Waters ryan.or...@gmail.com wrote:

 I have some code that blows up the heap and I'm not sure why.  I've
 reduced it down to the following.

 I've tried to make sure the atom doesn't have boundless growth and I
 didn't think 'while' hangs on to the head of sequences so I'm embarrassed
 to say I'm stumped.


 (defn leaks-memory
   []
   (let [mem (atom [])
 chunksize 1000
 threshold 2000]
   (while true
 (swap! mem conj (rand-int 100))

 ; every 'chunksize' item past 'threshold'
 (when (and (= 0 (mod (count @mem) chunksize))
( (count @mem) threshold))
   (swap! mem subvec chunksize)

 (doc subvec)

Returns a persistent vector of the items in vector from
start (inclusive) to end (exclusive). If end is not supplied,
defaults to (count vector). This operation is O(1) and very fast, as
the resulting vector shares structure with the original and no
trimming is done.

subvec is fast, but it's not saving you any memory.

-- 
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: dependencies from github

2014-03-27 Thread Aaron Cohen
I think you have 1 minor misunderstanding about how lein is working here.

Lein isn't checking not-really-trusted-package out of github, it's
retrieving the corresponding artifact from a maven-style repository.

If version doesn't end in -SNAPSHOT, then lein (deferring to the way
maven works) will retrieve that dependency to your local
$HOME/.m2/repository/not-really-trusted-package/version directory, and
never update it again (because it doesn't have a SHAPSHOT suffix).

In addition, all of the repositories that lein is configured with by
default have a policy of never updating non-SNAPSHOT versions, so it's not
really possible for that artifact to change out from under you. That's the
whole point of the maven/lein repeatable builds philosophy.

--Aaron


On Thu, Mar 27, 2014 at 5:16 AM, t x txrev...@gmail.com wrote:

 Hi,

 ## Context:

   * I'm using lein.
   * In my project.clj, I have something like:

 :dependencies[ [org.clojure/clojure 1.5.1]
   [org.clojure/clojurescript 0.0.-2173]
   [not-really-trusted-package version]]

   Now, I don't like pulling not-really-trusted-package, which can
 change under me. Instead I'd prefer to:

   (1) git fork the not-really-trusted package to
 github/txrev319/not-really-trusted
   (2) have lein pull from github/txrev319/not-really-trusted

 ## Question:

   How do I achieve the above?

 Thanks!

 (I still don't trust the package, but atleast I want to use the same
 untrusted package every time.)

 --
 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: [ANN] Clojure 1.6

2014-03-25 Thread Aaron Cohen
Great job!

Sorry I didn't catch this in the RC, but the release notes state that:

   - CLJ-1099 http://dev.clojure.org/jira/browse/CLJ-1099 If non-seq
   passed where seq is needed, error message now is an ExceptionInfo with the
   instance value, retrievable via ex-data.

I think that change was just reverted because of the performance impact.

--Aaron

-- 
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: Why do I have to register an ImageReader?

2014-02-27 Thread Aaron Cohen
On Thu, Feb 27, 2014 at 3:44 PM, larry google groups 
lawrencecloj...@gmail.com wrote:

 I tried this too:

 (ns tma-make-thumbnails.make-images
   (:import
(java.util UUID)
(javax.imageio ImageIO)
(java.awt.image BufferedImage)
(javax.imageio ImageReader))



 (defn get-file-as-image [filename]
   {:pre [(= (type filename) java.lang.String)
  (fs/exists? filename)
  (fs/file? (io/as-file filename))]
:post [(do (pp/pprint %) true)
   (= (type %) java.awt.image.BufferedImage)]}
   (.read ImageIO (io/as-file filename)))


This is trying to invoke the read method of the Class instance
representing javax.imageio.ImageIO. This is surely not what you want.


 but that only gives me:

 Exception in thread Thread-1 java.lang.IllegalArgumentException: No
 matching method found: read for class java.lang.Class

 I don't get why ImageIO is java.lang.Class after I imported it.





 On Thursday, February 27, 2014 3:09:53 PM UTC-5, larry google groups wrote:

 I have no background with Java so I tend to suffer pain when dealing with
 it. I am trying to create a thumbnail for an image, but my code dies on the
 :post assertion of this function:

 (defn get-file-as-image [filename]
   {:pre [(= (type filename) java.lang.String)
  (fs/exists? filename)
  (fs/file? (io/as-file filename))]
:post [(do (pp/pprint %) true)
   (= (type %) BufferedImage)]}
   (javax.imageio.ImageIO/read (io/as-file filename)))



This is the correct syntax for invoking a static method of a class. I'm not
sure why it's not working for you. What kind of file are you trying to load?

-- 
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 do I have to register an ImageReader?

2014-02-27 Thread Aaron Cohen
 of images. It was causing the problems. I had no error handling for
 non-images.



 On Thursday, February 27, 2014 3:52:09 PM UTC-5, Aaron Cohen wrote:

 On Thu, Feb 27, 2014 at 3:44 PM, larry google groups 
 lawrenc...@gmail.com wrote:

 I tried this too:

 (ns tma-make-thumbnails.make-images
   (:import
(java.util UUID)
(javax.imageio ImageIO)
(java.awt.image BufferedImage)
(javax.imageio ImageReader))



 (defn get-file-as-image [filename]
   {:pre [(= (type filename) java.lang.String)
  (fs/exists? filename)
  (fs/file? (io/as-file filename))]
:post [(do (pp/pprint %) true)
   (= (type %) java.awt.image.BufferedImage)]}
   (.read ImageIO (io/as-file filename)))


 This is trying to invoke the read method of the Class instance
 representing javax.imageio.ImageIO. This is surely not what you want.


 but that only gives me:

 Exception in thread Thread-1 java.lang.IllegalArgumentException: No
 matching method found: read for class java.lang.Class

 I don't get why ImageIO is java.lang.Class after I imported it.





 On Thursday, February 27, 2014 3:09:53 PM UTC-5, larry google groups
 wrote:

 I have no background with Java so I tend to suffer pain when dealing
 with it. I am trying to create a thumbnail for an image, but my code dies
 on the :post assertion of this function:

 (defn get-file-as-image [filename]
   {:pre [(= (type filename) java.lang.String)
  (fs/exists? filename)
  (fs/file? (io/as-file filename))]
:post [(do (pp/pprint %) true)
   (= (type %) BufferedImage)]}
   (javax.imageio.ImageIO/read (io/as-file filename)))



 This is the correct syntax for invoking a static method of a class. I'm
 not sure why it's not working for you. What kind of file are you trying to
 load?


  --
 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: Why do I have to register an ImageReader?

2014-02-27 Thread Aaron Cohen
 gets written to disk?









 On Thursday, February 27, 2014 4:09:10 PM UTC-5, larry google groups
 wrote:


 Ah, I see what happened. There was a Microsoft Word document in my
 folder of images. It was causing the problems. I had no error handling for
 non-images.



 On Thursday, February 27, 2014 3:52:09 PM UTC-5, Aaron Cohen wrote:

 On Thu, Feb 27, 2014 at 3:44 PM, larry google groups 
 lawrenc...@gmail.com wrote:

 I tried this too:

 (ns tma-make-thumbnails.make-images
   (:import
(java.util UUID)
(javax.imageio ImageIO)
(java.awt.image BufferedImage)
(javax.imageio ImageReader))



 (defn get-file-as-image [filename]
   {:pre [(= (type filename) java.lang.String)
  (fs/exists? filename)
  (fs/file? (io/as-file filename))]
:post [(do (pp/pprint %) true)
   (= (type %) java.awt.image.BufferedImage)]}
   (.read ImageIO (io/as-file filename)))


 This is trying to invoke the read method of the Class instance
 representing javax.imageio.ImageIO. This is surely not what you want.


 but that only gives me:

 Exception in thread Thread-1 java.lang.IllegalArgumentException:
 No matching method found: read for class java.lang.Class

 I don't get why ImageIO is java.lang.Class after I imported it.





 On Thursday, February 27, 2014 3:09:53 PM UTC-5, larry google groups
 wrote:

 I have no background with Java so I tend to suffer pain when dealing
 with it. I am trying to create a thumbnail for an image, but my code 
 dies
 on the :post assertion of this function:

 (defn get-file-as-image [filename]
   {:pre [(= (type filename) java.lang.String)
  (fs/exists? filename)
  (fs/file? (io/as-file filename))]
:post [(do (pp/pprint %) true)
   (= (type %) BufferedImage)]}
   (javax.imageio.ImageIO/read (io/as-file filename)))



 This is the correct syntax for invoking a static method of a class.
 I'm not sure why it's not working for you. What kind of file are you 
 trying
 to load?


  --
 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: Looking for a reference binary parsing

2014-01-27 Thread Aaron Cohen
Have you already looked into using https://code.google.com/p/mp4parser/ ?



On Fri, Jan 24, 2014 at 10:08 AM, Kashyap CK ckkash...@gmail.com wrote:

 Hi,
 I need to write a parser for MP4 - essentially, read an MP4 file and
 create an in-memory representation of its structure.
 I'd appreciate it very much if I could get some suggestions on libraries
 that I could use for this.
 Is there a https://github.com/youngnh/parsatron like library that works
 on binary files as well?
 Regards,
 Kashyap

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


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


Re: Clojure can't import some Java classes

2013-12-27 Thread Aaron Cohen
I have the sneaking suspicion that this may be as simple as changing

https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L697

to:

final static Method forNameMethod = Method.getMethod(Class
*classForNameNonLoading*(String));


and making classForNameNonLoading public at
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L2074

static *public *Class classForNameNonLoading(String name)


I should try it myself, but may not get to it this weekend.


On Fri, Dec 27, 2013 at 5:19 PM, Zach Oakes zsoa...@gmail.com wrote:

 Yeah I tried this with RoboVM, but there are so many classes that needed
 to be stubbed that it turned into an endless rabbit hole, so I gave up. It
 may be a good solution for those who just have one or two problematic
 classes, though.


 On Thursday, December 26, 2013 8:37:44 PM UTC-5, Colin Fleming wrote:

 In case anyone is interested in a workaround for this, I managed to fix
 my compilation by stubbing out the problematic classes and putting the
 stubs ahead of the real classes in the classpath when I compile. Where
 those stubs return other objects that are required during static
 initialisation, I create those classes with Mockito. I feel dirty all over
 but it does work.

 I'm also tinkering with a fork of Clojure in the background that uses ASM
 Types instead of Class objects. It's still a long way from done but it's
 looking like that might provide a solution for compilation, at least. I'll
 report back if I ever get it working.


 On 15 December 2013 14:05, Colin Fleming colin.ma...@gmail.com wrote:

 I've just spent some time today looking at the compiler code, and
 unfortunately I think the answer is no. When a symbol is imported,
 Clojure currently instantiates the Class object using Class.forName() and
 stores that in the namespace's mapping. At the point the Class is
 instantiated, static initializers are run. So the only way to avoid that is
 not instantiate the Class and store something else in the mapping.

 Alex's suggestion above to store the string representing the class name
 and load the class on demand might work for REPL style development but
 won't work for AOT compilation since reflection is used to find fields,
 methods etc on the class during compilation. The only solution that I can
 see that would work for AOT would be to store some sort of class wrapper
 object which reads the class bytecode to get that information without
 instantiating the class.

 However both of these suggestions break a fairly fundamental assumption
 - that importing a class creates a mapping from its name to a Class object.
 I have no idea what sort of code might be out there making that assumption,
 but it's probably fair to assume there could be a lot of it. At some point
 I might look into creating a fork of Clojure I just use to AOT compile.


 On 12 December 2013 03:41, Robin Heggelund Hansen skinn...@gmail.comwrote:

 Is this something that is fixable?

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.com

 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com

 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+u...@googlegroups.com.

 For more options, visit https://groups.google.com/groups/opt_out.



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

Re: Clojure can't import some Java classes

2013-10-23 Thread Aaron Cohen
I'm not sure if this is related to the original problem.

 How is the setFactory method expected to be invoked, through some sort of
dependency injection framework?


On Wed, Oct 23, 2013 at 7:06 AM, Colin Fleming
colin.mailingl...@gmail.comwrote:

 I've also had a lot of problems with def'ed forms. For example, if I do
 this:

 (def no-spacing (Spacing/createSpacing 0 0 0 false 0))

 Which looks like this:

   public static Spacing createSpacing(int minSpaces,
   int maxSpaces,
   int minLineFeeds,
   boolean keepLineBreaks,
   int keepBlankLines) {
 return myFactory.createSpacing(minSpaces, maxSpaces, minLineFeeds,
 keepLineBreaks, keepBlankLines);
   }

 myFactory is injected at some earlier point:

   static void setFactory(SpacingFactory factory) {
 myFactory = factory;
   }

 But during compilation that obviously hasn't happened and I get an NPE
 during compilation. It's a little annoying that there really seems to be no
 good way to create this value at namespace load time if I'm AOT compiling.
 I can obviously defer it using defn with memoize or something, but that
 seems clunky for what doesn't seem like that crazy a use case.


 On 23 October 2013 15:21, Zach Oakes zsoa...@gmail.com wrote:

 Here's the error I get when I import LibGDX's Timer class:

 http://pastebin.com/q7wys8yi


 On Tuesday, October 22, 2013 9:55:16 PM UTC-4, Alex Miller wrote:

 I'd love to see a stack trace when that happens (could even be triggered
 by dumping stack in your static initializer if nothing else).

 On Saturday, October 12, 2013 3:17:50 AM UTC-5, Wujek Srujek wrote:

 So you are saying compilation is trying to instantiate class and run
 static initializers? This seems very backward, are you sure?


 On Sat, Oct 12, 2013 at 8:30 AM, Zach Oakes zso...@gmail.com wrote:

 I should add, I am aware I can bring in a class dynamically with
 Class/forName, and that is what I ended up doing for the Timer class.
 However, this is not always practical, and sometimes is simply not an
 option if aot-compilation is required.


 On Saturday, October 12, 2013 2:28:38 AM UTC-4, Zach Oakes wrote:

 I recently learned that merely importing a Java class in Clojure
 causes static initializers to be run. Sometimes, this causes compilation
 errors, because they are written with the assumption that they will only 
 be
 run during runtime.

 I ran into this just now while trying to make a simple Clojure game
 with LibGDX. After simply importing its Timer class, I began getting
 compilation errors. The stack trace shows it is due to a static
 initializerhttps://github.com/libgdx/libgdx/blob/511b557c1a2d23bf8110a05b0ef54cc20b7f958d/gdx/src/com/badlogic/gdx/utils/Timer.java#L32attempting
  to instantiate the class!

 I also ran into this recently while trying to use RoboVM. My question
 is, do I have any options? I haven't found many discussions about this 
 here
 or elsewhere. This surprises me, because it seems like something more
 people should be running into.

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


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


  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, 

Re: Clojure can't import some Java classes

2013-10-23 Thread Aaron Cohen
So, is this a correct summary of the problem?

Importing a class in clojure causes static initializers to run. This
differs from Java where static initializers don't run until the first
'initialization' (either the invocation of a constructor, or invocation of
a 'main' method) of a class. In some cases, this makes it impossible to
create the environment that java classes expect to be present before they
are initialized.

On Tuesday, October 22, 2013, Zach Oakes wrote:

 Here's the error I get when I import LibGDX's Timer class:

 http://pastebin.com/q7wys8yi

 On Tuesday, October 22, 2013 9:55:16 PM UTC-4, Alex Miller wrote:

 I'd love to see a stack trace when that happens (could even be triggered
 by dumping stack in your static initializer if nothing else).

 On Saturday, October 12, 2013 3:17:50 AM UTC-5, Wujek Srujek wrote:

 So you are saying compilation is trying to instantiate class and run
 static initializers? This seems very backward, are you sure?


 On Sat, Oct 12, 2013 at 8:30 AM, Zach Oakes zso...@gmail.com wrote:

 I should add, I am aware I can bring in a class dynamically with
 Class/forName, and that is what I ended up doing for the Timer class.
 However, this is not always practical, and sometimes is simply not an
 option if aot-compilation is required.


 On Saturday, October 12, 2013 2:28:38 AM UTC-4, Zach Oakes wrote:

 I recently learned that merely importing a Java class in Clojure
 causes static initializers to be run. Sometimes, this causes compilation
 errors, because they are written with the assumption that they will only 
 be
 run during runtime.

 I ran into this just now while trying to make a simple Clojure game
 with LibGDX. After simply importing its Timer class, I began getting
 compilation errors. The stack trace shows it is due to a static
 initializerhttps://github.com/libgdx/libgdx/blob/511b557c1a2d23bf8110a05b0ef54cc20b7f958d/gdx/src/com/badlogic/gdx/utils/Timer.java#L32attempting
  to instantiate the class!

 I also ran into this recently while trying to use RoboVM. My question
 is, do I have any options? I haven't found many discussions about this 
 here
 or elsewhere. This surprises me, because it seems like something more
 people should be running into.



-- 
-- 
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: Possible bug in LockingTransaction

2013-09-11 Thread Aaron Cohen
On Wed, Sep 11, 2013 at 2:47 AM, Brandon Ibach brandon.l.ib...@gmail.comwrote:

 I have found what appears to be a bug in LockingTransaction, albeit one
 that probably wouldn't occur often.  But, I suppose that's a given for a
 previously undiscovered problem in oft-used code that hasn't changed for
 some while. :)

 I'm using the Clojure 1.4 library strictly from Java code and I have a
 fairly simple transaction which dispatches an action to an agent (send, not
 send-off).  When called from a JUnit test, such that we jump right in to
 things, skipping some of the initialization we normally do in our app, I
 get a ConcurrentModificationException from inside Locktransaction.run()
 while it is iterating through the actions list, dispatching the actions
 after committing the transaction.

 How are you calling send without the rest of clojure having been
initialized?



 Based on some debugging, here's what seems to be happening:

 1. My transaction is run, dispatching an action to an agent.
 2. The transaction completes and is successfully committed.
 3. LockingTransaction does post-commit cleanup, freeing locks and putting
 a stop() to the transaction, which nulls the transaction's Info object
 reference.
 4. Notifications are sent and we start iterating the list of actions to be
 dispatched.
 5. The run() method calls Agent.dispatchAction().  Because the thread's
 transaction is no longer running (due to the Info object being null) and
 no action is being processed on the thread (so its nested vector is
 null), the action is enqueue()d with the agent.
 6. As part of the enqueue process, the action is consed onto the agent's
 ActionQueue.  Here's where the unique circumstances come into play.
a. At this point, we haven't really interacted with the Clojure
 runtime, specifically the RT class, so its initiation machinery kicks in.
b. Down in the depths, it executes a transaction to add a library to
 its list of loaded libraries.
c. The still-existing-but-not-running thread-local transaction, with
 its existing action list intact, fires up, runs and commits.
d. The post-commit stuff runs, including a nested attempt to dispatch
 that same action, again, which apparently succeeds.
e. The action list is cleared before exiting the run() method.
 7. Upon returning way back up the stack to our
 not-quite-finished-post-processing transaction, we continue iterating the
 now-cleared action list, which promptly throws the
 ConcurrentModificationException.

 A quick perusal of the LockingTransaction code shows that the only
 interaction with the action list is adding an item to it in the enqueue()
 method, iterating it in the post-processing section of run() and clearing
 it in the finally clause of that section, so it's easy to see how a
 transaction started by any of the action-dispatching machinery would cause
 problems.  Any such activity in the actions themselves would not be an
 issue, since they'd occur on other threads, but the dispatch stuff all runs
 on the same thread.  The few moving parts that occur in this code seem
 fairly safe, as long as the runtime is already initialized, but if that
 occurs during this phase, I think all bets are off.



-- 
-- 
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: Eval vs the repl

2013-08-28 Thread Aaron Cohen
What repl are you using? I think it's doing something weird.

java -cp clojure-1.5.1.jar clojure.main
user= [do (inc 1)]
2
user ^{:line 11, :column 20} []
ClassCastException java.lang.Long cannot be cast to java.lang.Integer
 clojure.lang.Compiler.eval (Compiler.java:6597)

--Aaron

-- 
-- 
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: eval/macros with functions with metadata

2013-08-28 Thread Aaron Cohen
I'm not sure if you'll consider this hacky or not.

 (def ^:dynamic *fn-helper*)

(defn eval-at-one [f] (binding [*fn-helper* f] (eval '(*fn-helper* 1


On Wed, Aug 28, 2013 at 1:28 PM, Jamie Brandon ja...@scattered-thoughts.net
 wrote:

 You will also run into problems if your functions close over any data:

 user (let [f (fn [] 1)] (eval `(~f)))
 1
 nil
 user (let [x 1 f (fn [] x)] (eval `(~f)))
 IllegalArgumentException No matching ctor found for class
 user$eval38616$f__38617  clojure.lang.Reflector.invokeConstructor
 (Reflector.java:163)

 I'm struggling with this as well, I'm definitely interested in finding
 a non-hacky way to pass closures through eval without leaking memory.

 Perhaps something like:

 (let [x 1
f (fn [] x)
f-sym (gensym)]
   (intern *ns* gensym (weak-ref f))
   (with-meta (eval `(fn [] (do-stuff-with @~f))) {::strong-ref f}))

 So that way f will be freed up when the resulting fn is gced.

 On 28 August 2013 17:59, Ben Wolfson wolf...@gmail.com wrote:
  On Wed, Aug 28, 2013 at 9:27 AM, Jamie Brandon
  ja...@scattered-thoughts.net wrote:
 
 
  If you aren't worried about leaking memory, a possible workaround is
  to intern the fn in some namespace and then put the symbol in the
  macro output.
 
 
  Hrm, I hope it doesn't come to that---as long as I'm creating the
 functions
  with their metadata, I can make things work, because I can add extra
  information to the with-meta call or do extra things when making the
 call.
  What I'd like, though, is for it to be possible to copy the metadata
 over to
  a new function by client code, just using the regular (with-meta (fn
 [blah]
  blah) (meta old-fn)) mechanism. But then the sneaky symbol, or whatever
  extra thing, in the metadata, that's used in the form to be eval-ed is
  pointing to the original function, not the one passed in. Maybe just
  providing a utility for fixing up the metadata is the right move, though
  it's kidn of dissatisfying.
 
 
  --
  Ben Wolfson
  Human kind has used its intelligence to vary the flavour of drinks,
 which
  may be sweet, aromatic, fermented or spirit-based. ... Family and social
  life also offer numerous other occasions to consume drinks for pleasure.
  [Larousse, Drink entry]
 
  --
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
 your
  first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google Groups
  Clojure group.
  To unsubscribe from this group and stop receiving emails from it, send an
  email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https://groups.google.com/groups/opt_out.

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


-- 
-- 
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: eval/macros with functions with metadata

2013-08-28 Thread Aaron Cohen
How about this alternative?

(deftype Wrapper [f]
  clojure.lang.IFn
  (invoke [this] (f))
  (invoke [this a] (f a))
  ; repeat until you get bored
)

(defn e [f]
  (let [wr (Wrapper. f)]
(eval `(~wr 1

(e inc)

(e (with-meta (fn [x] (+ 4 x)) {}))



On Wed, Aug 28, 2013 at 1:59 PM, Jamie Brandon ja...@scattered-thoughts.net
 wrote:

 That sort of works for my use case.

 What I want to do is define a grammar...

 (def num-graph
   (graph
  num ~(or ~succ ~zero)
  succ (succ ^x ~num)
  zero zero))

 ... attach actions 

 (def num-out
   (output-in num-graph
  'zero (fnk [] 0)
  'succ (fnk [x] (inc x

 ... and compile the result ...

 strucjure.regression.tests (graph-view 'num num-out)
 (clojure.core/letfn
  [(num ...)
   (succ ...)
   (zero ...)]
  (clojure.core/fn
   [input__2288__auto__]
 (num input__2288__auto__)))

 This works fine as long as the fnks dont close over anything, but
 that's very limiting.

 If I eval that code and *then* wrap it in (binding ...) I can have
 closures but that now means that I can't do call-site compilation.
 I'll have to poke around a bit more...

 On 28 August 2013 18:32, Aaron Cohen aa...@assonance.org wrote:
  I'm not sure if you'll consider this hacky or not.
 
   (def ^:dynamic *fn-helper*)
 
  (defn eval-at-one [f] (binding [*fn-helper* f] (eval '(*fn-helper* 1
 
 
  On Wed, Aug 28, 2013 at 1:28 PM, Jamie Brandon
  ja...@scattered-thoughts.net wrote:
 
  You will also run into problems if your functions close over any data:
 
  user (let [f (fn [] 1)] (eval `(~f)))
  1
  nil
  user (let [x 1 f (fn [] x)] (eval `(~f)))
  IllegalArgumentException No matching ctor found for class
  user$eval38616$f__38617  clojure.lang.Reflector.invokeConstructor
  (Reflector.java:163)
 
  I'm struggling with this as well, I'm definitely interested in finding
  a non-hacky way to pass closures through eval without leaking memory.
 
  Perhaps something like:
 
  (let [x 1
 f (fn [] x)
 f-sym (gensym)]
(intern *ns* gensym (weak-ref f))
(with-meta (eval `(fn [] (do-stuff-with @~f))) {::strong-ref f}))
 
  So that way f will be freed up when the resulting fn is gced.
 
  On 28 August 2013 17:59, Ben Wolfson wolf...@gmail.com wrote:
   On Wed, Aug 28, 2013 at 9:27 AM, Jamie Brandon
   ja...@scattered-thoughts.net wrote:
  
  
   If you aren't worried about leaking memory, a possible workaround is
   to intern the fn in some namespace and then put the symbol in the
   macro output.
  
  
   Hrm, I hope it doesn't come to that---as long as I'm creating the
   functions
   with their metadata, I can make things work, because I can add extra
   information to the with-meta call or do extra things when making the
   call.
   What I'd like, though, is for it to be possible to copy the metadata
   over to
   a new function by client code, just using the regular (with-meta (fn
   [blah]
   blah) (meta old-fn)) mechanism. But then the sneaky symbol, or
 whatever
   extra thing, in the metadata, that's used in the form to be eval-ed is
   pointing to the original function, not the one passed in. Maybe just
   providing a utility for fixing up the metadata is the right move,
 though
   it's kidn of dissatisfying.
  
  
   --
   Ben Wolfson
   Human kind has used its intelligence to vary the flavour of drinks,
   which
   may be sweet, aromatic, fermented or spirit-based. ... Family and
 social
   life also offer numerous other occasions to consume drinks for
   pleasure.
   [Larousse, Drink entry]
  
   --
   --
   You received this message because you are subscribed to the Google
   Groups Clojure group.
   To post to this group, send email to clojure@googlegroups.com
   Note that posts from new members are moderated - please be patient
 with
   your
   first post.
   To unsubscribe from this group, send email to
   clojure+unsubscr...@googlegroups.com
   For more options, visit this group at
   http://groups.google.com/group/clojure?hl=en
   ---
   You received this message because you are subscribed to the Google
   Groups
   Clojure group.
   To unsubscribe from this group and stop receiving emails from it, send
   an
   email to clojure+unsubscr...@googlegroups.com.
   For more options, visit https://groups.google.com/groups/opt_out.
 
  --
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google
 Groups
  Clojure group.
  To unsubscribe from this group and stop receiving emails from it, send
 an
  email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https

Re: eval/macros with functions with metadata

2013-08-28 Thread Aaron Cohen
Sorry, that one doesn't work. It worked in my repl, but I must have been
using old code.


On Wed, Aug 28, 2013 at 2:27 PM, Aaron Cohen aa...@assonance.org wrote:

 How about this alternative?

 (deftype Wrapper [f]
   clojure.lang.IFn
   (invoke [this] (f))
   (invoke [this a] (f a))
   ; repeat until you get bored
 )

 (defn e [f]
   (let [wr (Wrapper. f)]
 (eval `(~wr 1

 (e inc)

 (e (with-meta (fn [x] (+ 4 x)) {}))



 On Wed, Aug 28, 2013 at 1:59 PM, Jamie Brandon 
 ja...@scattered-thoughts.net wrote:

 That sort of works for my use case.

 What I want to do is define a grammar...

 (def num-graph
   (graph
  num ~(or ~succ ~zero)
  succ (succ ^x ~num)
  zero zero))

 ... attach actions 

 (def num-out
   (output-in num-graph
  'zero (fnk [] 0)
  'succ (fnk [x] (inc x

 ... and compile the result ...

 strucjure.regression.tests (graph-view 'num num-out)
 (clojure.core/letfn
  [(num ...)
   (succ ...)
   (zero ...)]
  (clojure.core/fn
   [input__2288__auto__]
 (num input__2288__auto__)))

 This works fine as long as the fnks dont close over anything, but
 that's very limiting.

 If I eval that code and *then* wrap it in (binding ...) I can have
 closures but that now means that I can't do call-site compilation.
 I'll have to poke around a bit more...

 On 28 August 2013 18:32, Aaron Cohen aa...@assonance.org wrote:
  I'm not sure if you'll consider this hacky or not.
 
   (def ^:dynamic *fn-helper*)
 
  (defn eval-at-one [f] (binding [*fn-helper* f] (eval '(*fn-helper* 1
 
 
  On Wed, Aug 28, 2013 at 1:28 PM, Jamie Brandon
  ja...@scattered-thoughts.net wrote:
 
  You will also run into problems if your functions close over any data:
 
  user (let [f (fn [] 1)] (eval `(~f)))
  1
  nil
  user (let [x 1 f (fn [] x)] (eval `(~f)))
  IllegalArgumentException No matching ctor found for class
  user$eval38616$f__38617  clojure.lang.Reflector.invokeConstructor
  (Reflector.java:163)
 
  I'm struggling with this as well, I'm definitely interested in finding
  a non-hacky way to pass closures through eval without leaking memory.
 
  Perhaps something like:
 
  (let [x 1
 f (fn [] x)
 f-sym (gensym)]
(intern *ns* gensym (weak-ref f))
(with-meta (eval `(fn [] (do-stuff-with @~f))) {::strong-ref f}))
 
  So that way f will be freed up when the resulting fn is gced.
 
  On 28 August 2013 17:59, Ben Wolfson wolf...@gmail.com wrote:
   On Wed, Aug 28, 2013 at 9:27 AM, Jamie Brandon
   ja...@scattered-thoughts.net wrote:
  
  
   If you aren't worried about leaking memory, a possible workaround is
   to intern the fn in some namespace and then put the symbol in the
   macro output.
  
  
   Hrm, I hope it doesn't come to that---as long as I'm creating the
   functions
   with their metadata, I can make things work, because I can add extra
   information to the with-meta call or do extra things when making the
   call.
   What I'd like, though, is for it to be possible to copy the metadata
   over to
   a new function by client code, just using the regular (with-meta (fn
   [blah]
   blah) (meta old-fn)) mechanism. But then the sneaky symbol, or
 whatever
   extra thing, in the metadata, that's used in the form to be eval-ed
 is
   pointing to the original function, not the one passed in. Maybe just
   providing a utility for fixing up the metadata is the right move,
 though
   it's kidn of dissatisfying.
  
  
   --
   Ben Wolfson
   Human kind has used its intelligence to vary the flavour of drinks,
   which
   may be sweet, aromatic, fermented or spirit-based. ... Family and
 social
   life also offer numerous other occasions to consume drinks for
   pleasure.
   [Larousse, Drink entry]
  
   --
   --
   You received this message because you are subscribed to the Google
   Groups Clojure group.
   To post to this group, send email to clojure@googlegroups.com
   Note that posts from new members are moderated - please be patient
 with
   your
   first post.
   To unsubscribe from this group, send email to
   clojure+unsubscr...@googlegroups.com
   For more options, visit this group at
   http://groups.google.com/group/clojure?hl=en
   ---
   You received this message because you are subscribed to the Google
   Groups
   Clojure group.
   To unsubscribe from this group and stop receiving emails from it,
 send
   an
   email to clojure+unsubscr...@googlegroups.com.
   For more options, visit https://groups.google.com/groups/opt_out.
 
  --
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google
 Groups

Re: eval/macros with functions with metadata

2013-08-28 Thread Aaron Cohen
This is a little hard for me to follow because I'm not sure what graph or
output-in are doing.

If the letfn is being generated by your compilation step, why can't that go
inside of your generated fn rather than outside it?

(clojure.core/fn
  [input__2288__auto__]
(clojure.core/letfn
 [(num ...)
  (succ ...)
  (zero ...)]
(num input__2288__auto__)))


On Wed, Aug 28, 2013 at 1:59 PM, Jamie Brandon ja...@scattered-thoughts.net
 wrote:

 That sort of works for my use case.

 What I want to do is define a grammar...

 (def num-graph
   (graph
  num ~(or ~succ ~zero)
  succ (succ ^x ~num)
  zero zero))

 ... attach actions 

 (def num-out
   (output-in num-graph
  'zero (fnk [] 0)
  'succ (fnk [x] (inc x

 ... and compile the result ...

 strucjure.regression.tests (graph-view 'num num-out)
 (clojure.core/letfn
  [(num ...)
   (succ ...)
   (zero ...)]
  (clojure.core/fn
   [input__2288__auto__]
 (num input__2288__auto__)))

 This works fine as long as the fnks dont close over anything, but
 that's very limiting.

 If I eval that code and *then* wrap it in (binding ...) I can have
 closures but that now means that I can't do call-site compilation.
 I'll have to poke around a bit more...

 On 28 August 2013 18:32, Aaron Cohen aa...@assonance.org wrote:
  I'm not sure if you'll consider this hacky or not.
 
   (def ^:dynamic *fn-helper*)
 
  (defn eval-at-one [f] (binding [*fn-helper* f] (eval '(*fn-helper* 1
 
 
  On Wed, Aug 28, 2013 at 1:28 PM, Jamie Brandon
  ja...@scattered-thoughts.net wrote:
 
  You will also run into problems if your functions close over any data:
 
  user (let [f (fn [] 1)] (eval `(~f)))
  1
  nil
  user (let [x 1 f (fn [] x)] (eval `(~f)))
  IllegalArgumentException No matching ctor found for class
  user$eval38616$f__38617  clojure.lang.Reflector.invokeConstructor
  (Reflector.java:163)
 
  I'm struggling with this as well, I'm definitely interested in finding
  a non-hacky way to pass closures through eval without leaking memory.
 
  Perhaps something like:
 
  (let [x 1
 f (fn [] x)
 f-sym (gensym)]
(intern *ns* gensym (weak-ref f))
(with-meta (eval `(fn [] (do-stuff-with @~f))) {::strong-ref f}))
 
  So that way f will be freed up when the resulting fn is gced.
 
  On 28 August 2013 17:59, Ben Wolfson wolf...@gmail.com wrote:
   On Wed, Aug 28, 2013 at 9:27 AM, Jamie Brandon
   ja...@scattered-thoughts.net wrote:
  
  
   If you aren't worried about leaking memory, a possible workaround is
   to intern the fn in some namespace and then put the symbol in the
   macro output.
  
  
   Hrm, I hope it doesn't come to that---as long as I'm creating the
   functions
   with their metadata, I can make things work, because I can add extra
   information to the with-meta call or do extra things when making the
   call.
   What I'd like, though, is for it to be possible to copy the metadata
   over to
   a new function by client code, just using the regular (with-meta (fn
   [blah]
   blah) (meta old-fn)) mechanism. But then the sneaky symbol, or
 whatever
   extra thing, in the metadata, that's used in the form to be eval-ed is
   pointing to the original function, not the one passed in. Maybe just
   providing a utility for fixing up the metadata is the right move,
 though
   it's kidn of dissatisfying.
  
  
   --
   Ben Wolfson
   Human kind has used its intelligence to vary the flavour of drinks,
   which
   may be sweet, aromatic, fermented or spirit-based. ... Family and
 social
   life also offer numerous other occasions to consume drinks for
   pleasure.
   [Larousse, Drink entry]
  
   --
   --
   You received this message because you are subscribed to the Google
   Groups Clojure group.
   To post to this group, send email to clojure@googlegroups.com
   Note that posts from new members are moderated - please be patient
 with
   your
   first post.
   To unsubscribe from this group, send email to
   clojure+unsubscr...@googlegroups.com
   For more options, visit this group at
   http://groups.google.com/group/clojure?hl=en
   ---
   You received this message because you are subscribed to the Google
   Groups
   Clojure group.
   To unsubscribe from this group and stop receiving emails from it, send
   an
   email to clojure+unsubscr...@googlegroups.com.
   For more options, visit https://groups.google.com/groups/opt_out.
 
  --
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google
 Groups
  Clojure group.
  To unsubscribe from this group and stop receiving

Re: In-order triggering of watches on mutable state

2013-07-31 Thread Aaron Cohen
A watcher fn has 4 parameters: key, reference, old-state, new-state

If you use old-state and new-state rather than the reference, you should
not see your problem.

--Aaron


On Wed, Jul 31, 2013 at 11:00 AM, Michael Drogalis madrush...@gmail.comwrote:

 Problem:

 I have a ref representing a queue of people in line.
 I add a watch to the ref to print out the contents of the queue whenever
 it changes.
 Naturally, and expected, the following can happen if queuing happens in
 rapid succession:

 Queue: []
 add Mike to queue
 add John to queue

 console: Queue is Mike, John
 console: Queue is Mike

 I'd like to write a UI for this program, but I clearly can't reliably
 render based on the result delivered
 by the add-watch hook. What's the solution for this problem?

 --
 --
 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: End user applications

2013-06-13 Thread Aaron Cohen
What about Overtone? http://overtone.github.io/


On Thu, Jun 13, 2013 at 5:01 AM, Wolodja Wentland babi...@gmail.com wrote:

 Hi all,

 I was recently trying to find some applications written in Clojure that are
 meant for end users. The aim was to find those that would be interesting
 to a
 user even though the user does not know anything about Clojure or that the
 application is written in it.

 Given that Clojure is not that young anymore I was a bit surprised to find
 only Riemann [0] and Semira [1] out there among thousands of libraries or
 development tools.

 Can you think of others? What are Clojure's killer applications ?

 [0] http://riemann.io/
 [1] https://github.com/remvee/semira/
 --
 Wolodja babi...@gmail.com

 4096R/CAF14EFC
 081C B7CD FF04 2BA9 94EA  36B2 8B7F 7D30 CAF1 4EFC


-- 
-- 
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: 'amap' issue after extending a protocol to a primitive array type

2013-06-13 Thread Aaron Cohen
Are you sure?

user= (defprotocol A (foo [a b]))
A
user= (extend-protocol A (Class/forName [D) (foo [a b] [a b]))
nil
user= (pprint (foo (double-array [1 2 3]) 1))
[[1.0, 2.0, 3.0] 1]
user= (pprint (amap (float-array [1 2 3]) i ret (float (* 2 (aget ret
i)
[2.0, 4.0, 6.0]

My guess is you're not remembering to cast to the appropriate type in your
loop expression in amap.

For instance:
user= (amap (float-array [1 2 3]) i ret i)
IllegalArgumentException No matching method found: aset
 clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)

Whereas you need:
user= (amap (float-array [1 2 3]) i ret (float i))
#float[] [F@6a636064

--Aaron

On Thu, Jun 13, 2013 at 12:57 PM, Jim - FooBar(); jimpil1...@gmail.comwrote:

  more weirdness!


 try this at your REPL:

 -extend any protocol to some primitive array type - let's say 'doubles'
 -while in the same namespace, try to use amap passing it an array of
 floats and also type-hint it with ^floats
 *
 **IllegalArgumentException No matching method found: aset
 clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)*

 the same would have happened if the protocol had been extended to floats
 and tried to use amap with doubles. In fact any combination of primitive
 types will fail. Only the type that has been extended will work. In the
 above case that would be doubles. If we extended the protocol to longs then
 only longs would work and so forth...

 I'm almost certain that this is not intentional...any opinions?

 Jim

 --
 --
 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: while loop

2013-06-13 Thread Aaron Cohen
I like the StackOverflow answer for this:

http://stackoverflow.com/questions/5419125/using-java-api-from-clojure-reading-zip-file

(defn entries [zipfile]
  (enumeration-seq (.entries zipfile)))
(defn walkzip [fileName]
  (with-open [z (java.util.zip.ZipFile. fileName)]
 (doseq [e (entries z)]
(println (.getName e)



On Thu, Jun 13, 2013 at 1:25 PM, Leon Barrett lbarr...@climate.com wrote:

 Yeah, Clojure's while construct isn't really good at stuff like that. A
 loop is the basic thing I reach for, and I'd probably write it as:

 (loop []
   (when-let [entry (.getNextEntry stream)]
 (println entry)
 (recur)))


 On Thursday, June 13, 2013 10:20:22 AM UTC-7, Josh Kamau wrote:

 Hi there ;

 How do i implement the following in clojure

 while((entry = stream.getNextEntry())!=null)   {

System.out.println(entry.**getName());

   }

 NOTE: calling getNextEntry moves the curse to the next entry.

 CONTEXT: I am trying to list the contents of a .zip file using 
 http://docs.oracle.com/javase/**6/docs/api/java/util/zip/**ZipInputStream.html
  http://docs.oracle.com/javase/6/docs/api/java/util/zip/ZipInputStream.html


 Regards.

 Josh


   --
 --
 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: bug in 'extend-protocol' ???

2013-06-13 Thread Aaron Cohen
On Thu, Jun 13, 2013 at 1:52 PM, Jim - FooBar(); jimpil1...@gmail.com
 wrote:

 or can you perhaps show an example of successfully extending any protocol
 to at least 2 primitive array types?


You can call extend-protocol several times:

user= (defprotocol A (foo [a b]))
A
user= (extend-protocol A (Class/forName [D) (foo [a b] [a b]))
nil
user= (extend-protocol A (Class/forName [F) (foo [a b] [a b]))
nil
user= (foo (double-array [1 2 3]) 1)
[#double[] [D@5a12d46c 1]
user= (foo (float-array [1 2 3]) 1)
[#float[] [F@5e310a07 1]

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
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: Aw: Re: How to convert a VTK example from java to clojure?

2013-04-26 Thread Aaron Cohen
You no longer need any of this. All you should need is to use
(clojure.lang.RT/loadLibrary vtkwhatever)

That will ensure that the native libs end up in the correct classloader.


On Fri, Apr 26, 2013 at 3:46 AM, Nils Blum-Oeste
nblumoe...@googlemail.comwrote:

 Great, thanks a lot. Fixed the issues I had.
 However I wonder where 'wall-hack-method' lives now, as clojure-contrib
 has been split.
 This (old) thread suggests it has also been renamed to call-method
 https://groups.google.com/forum/?fromgroups=#!topic/clojure-dev/tKzqnJWpz-k

 So is this still included in one of the clojure-contrib libraries?

 On Tuesday, June 21, 2011 11:19:44 PM UTC+2, Aaron Cohen wrote:

 OK, I've gotten it working on my computer, and it turns out to be a
 slightly complicated problem.

 What is happening is that the vtk java files and your clojure code are
 using different classloaders (clojure uses its own classloader).

 System/loadLibrary is kind of crippled in that it always loads the
 library into the ClassLoader of the _invoking class's_ classLoader. I
 was hoping it would use the Thread's context classloader, but it does
 not.

 There isn't any straightforward way to load a library using a
 particular classloader either, so you have 2 options.

 1) Make a java class that exposes a loadLibrary method. This java
 class will be in the same classLoader as VTK and as a result,
 loadLibrary calls from there will be visible to VTK.

 public class Loader {

public static void loadLibrary(String lib) {
 // Hack to load a library outside of Clojure's classloader
 System.loadLibrary(lib);
}

 }

 2) Expose the package-private Runtime/loadLibrary0 method and call it.

 ; This function is in clojure-contrib, reproduced here for convenience
 (defn wall-hack-method
   Calls a private or protected method.
params is a vector of class which correspond to the arguments to the
 method
obj is nil for static methods, the instance object otherwise
the method name is given as a symbol or a keyword (something Named)
   [class-name method-name params obj  args]
   (- class-name (.getDeclaredMethod (name method-name) (into-array
 Class params))
 (doto (.setAccessible true))
 (.invoke obj (into-array Object args

 (defn load-lib [class lib]
 Loads a native library in the same classLoader as \class\ was
 loaded in. \lib\ is a string with the OS-appropriate name of the
 library. For instance, to load libvtk.so on Linux, lib should be
 \vtk\
 (wall-hack-method java.lang.Runtime loadLibrary0 [Class String]
 (Runtime/getRuntime) class lib))

 ; Load vtkCommonJava library in the same classLoader as vtkConeSource
 (load-lib vtkConeSource vtkCommonJava)

 

 I actually think clojure should probably add a method to its RT class
 that does option 1 above, that way there's a straightforward way to
 load native libraries in the correct classloader.

 --Aaron


 On Tue, Jun 21, 2011 at 4:10 PM, Antonio Recio amdx...@gmail.com wrote:
  All the vtk libraries that I need are in /usr/local/lib/vtk-5.9/ and are
  executable.
  Java and c++ examples work fine.
 
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clo...@googlegroups.com

  Note that posts from new members are moderated - please be patient with
 your
  first post.
  To unsubscribe from this group, send email to
  clojure+u...@**googlegroups.com

  For more options, visit this group at
  http://groups.google.com/**group/clojure?hl=enhttp://groups.google.com/group/clojure?hl=en

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To 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

Re: [GSoC 2013] CinC

2013-04-16 Thread Aaron Cohen
As a mentor, what should I be doing at this point?

I've been contacted by a couple of interested students so far, checking to
see if I'm still interested in mentoring this (I am!)

I'm just not sure what my current next step should be.

--Aaron


On Tue, Apr 9, 2013 at 8:54 PM, Daniel Solano Gómez cloj...@sattvik.comwrote:

 Hello,

 On Wed Apr 10 00:04 2013, Bronsa wrote:
  Actually, I would be interested in doing this if still available :)

 Well, now that we have been accepted as a mentoring organization, now is
 the time to start getting in touch with potential mentors and develop a
 proposal.  The student application period won't open until April 22, but
 there is no reason to wait until then.

 Sincerely,

 Daniel



  On Mon, Mar 4, 2013 at 6:53 PM, Aaron Cohen aa...@assonance.org wrote:
 
   On Mon, Mar 4, 2013 at 11:26 AM, abp abp...@gmail.com wrote:
  
   Is this work related?
  
   http://clojurewest.org/sessions#martin
   https://github.com/kanaka/clojurescript
  
  
   Nope, completely unrelated, though similar work.
  
   --Aaron
  
   --
   --
   You received this message because you are subscribed to the Google
   Groups Clojure group.
   To post to this group, send email to clojure@googlegroups.com
   Note that posts from new members are moderated - please be patient with
   your first post.
   To unsubscribe from this group, send email to
   clojure+unsubscr...@googlegroups.com
   For more options, visit this group at
   http://groups.google.com/group/clojure?hl=en
   ---
   You received this message because you are subscribed to the Google
 Groups
   Clojure group.
   To unsubscribe from this group and stop receiving emails from it, send
 an
   email to clojure+unsubscr...@googlegroups.com.
   For more options, visit https://groups.google.com/groups/opt_out.
  
  
  
 
  --
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
 your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google
 Groups Clojure group.
  To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https://groups.google.com/groups/opt_out.
 
 


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




Re: [GSoC 2013] CinC

2013-03-04 Thread Aaron Cohen
I think there probably is pretty easily a few months work there.

If more work were needed, it would be interesting to try to get the
clojurescript and clojure compilers using the same front-end. I'm fairly
confident that's at least a summer's work. :)

--Aaron


On Sat, Mar 2, 2013 at 11:05 AM, Ambrose Bonnaire-Sergeant 
abonnaireserge...@gmail.com wrote:

 Is there enough to do here for a few months work? I've added a new project
 here:

 http://dev.clojure.org/display/community/Project+Ideas#ProjectIdeas-ClojureinClojure

 Feel free to change it Aaron.

 Thanks,
 Ambrose

 On Sat, Mar 2, 2013 at 2:11 PM, Aaron Cohen aa...@assonance.org wrote:

 I'd really like to see this happen actually.

 If there's interest I'd be happy to help or mentor.

 The current status is that I have a commit that needs finishing to
 implement letfn and I believe that was the last major special form that
 needed implementing in the compiler.

 Next up would be figuring out how to bootstrap a little better. It would
 also be nice to pull in the work that's been done recently on the reader in
 clojure and datastructures in clojure.


 On Sat, Mar 2, 2013 at 12:50 AM, Ambrose Bonnaire-Sergeant 
 abonnaireserge...@gmail.com wrote:

 Hi,

 I think completing Aaron Cohen's CinC implementation would be a
 fantastic GSoC 2013 project.

 https://github.com/remleduff/CinC

 Is Aaron willing to mentor this project? If the core.typed proposal
 isn't chosen, I would be interested in
 this project also as a student.

 Thoughts?

 Thanks,
 Ambrose


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




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




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




Re: how to get SHA1 of a string?

2013-03-04 Thread Aaron Cohen
On Mon, Mar 4, 2013 at 11:12 AM, larry google groups 
lawrencecloj...@gmail.com wrote:

  expects its argument to be a byte array:
 http://docs.oracle.com/javase/6/docs/api/java/security/MessageDigest
 
  which can be obtained from a string using String#getBytes.


 I appreciate your suggestion. For most of the attempts that I have
 made, I have used this code:

  nonce (DigestUtils/md5Hex (random-string 32))
  nonce-encoded-base64 (Base64/encodeBase64 (.getBytes nonce))


Is this used somewhere?


  date-formatter (new SimpleDateFormat -MM-dd'T'HH:mm:ss'Z')
  created (.format date-formatter (new Date))
  digest-as-string (apply str nonce created secret)


(str binary-array) returns the toString of the array, which is something
like [B@5d5d0293. That has nothing to do with the contents of the array.
I think you want the base64 encoded string here.

--Aaron

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




Re: [GSoC 2013] CinC

2013-03-04 Thread Aaron Cohen
On Mon, Mar 4, 2013 at 11:26 AM, abp abp...@gmail.com wrote:

 Is this work related?

 http://clojurewest.org/sessions#martin
 https://github.com/kanaka/clojurescript


Nope, completely unrelated, though similar work.

--Aaron

-- 
-- 
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: how to get SHA1 of a string?

2013-03-04 Thread Aaron Cohen
I think you should try to avoid the string concatenation games. I'm not
sure what your current code is, but I suspect you're still ending up with
array toString's slipping in.

How about the following?

On Mon, Mar 4, 2013 at 1:31 PM, larry google groups 
lawrencecloj...@gmail.com wrote:

 So, right now I am using this code:

  (let [username (get-in @um/interactions [:omniture-api-
 credentials :username])
   secret (get-in @um/interactions [:omniture-api-credentials :shared-
 secret])
   nonce (DigestUtils/md5Hex (str (math/round (* (rand 1 ) 100
   nonce-encoded-base64 (Base64/encodeBase64 (.getBytes nonce))
   date-formatter (new SimpleDateFormat -MM-dd'T'HH:mm:ss)
   formatter gmt-timezone)
   created (.format date-formatter (new Date))


   nonce-bytes (.getBytes nonce)
   created-bytes (.getBytes created)
   secret-bytes (.getBytes secret)
   digest (- (java.security.MessageDigest/getInstance sha1)
.reset
(.update nonce-bytes)
(.update create-bytes)
(.update secret-bytes)
.digest)
digest-base64 (Base64/encodeBase64 digest)

;; Should UsernameToken Username really be unquoted in the following line?
;; All the other variable names are quoted
header (apply str  UsernameToken Username=\  username

;; You may want digest-base64 here?
  \PasswordDigest=\ digest


  \ Nonce=\ nonce-encoded-base64
  \Created=\ created \)]
 header)

-- 
-- 
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: how to get SHA1 of a string?

2013-03-04 Thread Aaron Cohen
On Mon, Mar 4, 2013 at 1:54 PM, larry google groups 
lawrencecloj...@gmail.com wrote:


 PasswordDigest=r+HWjSAk8AUvo/QmKKfbqQFnJ18=
 Nonce=NmQxNGUwZjVlMjFhYjE1MzQ4MjUxYTA1MTg1YzE3ZTg=

 The developer at Omniture reminded me of the characters allowed into
 Base64:

   You can tell a given string is base64 encoded because it can only
 have 64 specific characters in the string:
 A-Z
 a-z
 0-9
 +
 /
 That's 26 + 26 + 10 + 2 = 64
 http://en.wikipedia.org/wiki/Base64


 I assume that means that if I see a = in the string, then it is not
 really Base64 encoded?


Every Base64 encoded string I've ever seen ends with at least one =. I
believe it's used for padding.

-- 
-- 
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: how to get SHA1 of a string?

2013-03-04 Thread Aaron Cohen
Ah darn, thanks for the catch. The following is uglier but should work I
guess. :\

digest (.digest
   (doto (java.security.MessageDigest/getInstance sha1)
 .reset
 (.update nonce-bytes)
 (.update created-bytes)
 (.update secret-bytes)))


On Mon, Mar 4, 2013 at 2:25 PM, Frank Siebenlist frank.siebenl...@gmail.com
 wrote:

  digest (- (java.security.MessageDigest/getInstance sha1)
  .reset
  (.update nonce-bytes)
  (.update create-bytes)
  (.update secret-bytes)
  .digest)


 There may be an issue with this snippet of code as .update does not
 return anything… i.e. nil.

 -FS.



 On Mar 4, 2013, at 11:06 AM, larry google groups 
 lawrencecloj...@gmail.com wrote:

 
  ;; Should UsernameToken Username really be unquoted in the following
 line?
  ;; All the other variable names are quoted
 
  Apparently, yes. The developer at Omniture reviewed it and said my
  only problem was the way the passwordDigest was created.
 
 
 
  On Mar 4, 2:02 pm, Aaron Cohen aa...@assonance.org wrote:
  I think you should try to avoid the string concatenation games. I'm not
  sure what your current code is, but I suspect you're still ending up
 with
  array toString's slipping in.
 
  How about the following?
 
  On Mon, Mar 4, 2013 at 1:31 PM, larry google groups 
 
  lawrencecloj...@gmail.com wrote:
  So, right now I am using this code:
 
   (let [username (get-in @um/interactions [:omniture-api-
  credentials :username])
secret (get-in @um/interactions [:omniture-api-credentials :shared-
  secret])
nonce (DigestUtils/md5Hex (str (math/round (* (rand 1 ) 100
nonce-encoded-base64 (Base64/encodeBase64 (.getBytes nonce))
date-formatter (new SimpleDateFormat -MM-dd'T'HH:mm:ss)
formatter gmt-timezone)
created (.format date-formatter (new Date))
 
 nonce-bytes (.getBytes nonce)
 created-bytes (.getBytes created)
 secret-bytes (.getBytes secret)
 digest (- (java.security.MessageDigest/getInstance sha1)
  .reset
  (.update nonce-bytes)
  (.update create-bytes)
  (.update secret-bytes)
  .digest)
  digest-base64 (Base64/encodeBase64 digest)
 
  ;; Should UsernameToken Username really be unquoted in the following
 line?
  ;; All the other variable names are quoted
  header (apply str  UsernameToken Username=\  username
 
  ;; You may want digest-base64 here?
\PasswordDigest=\ digest
 
\ Nonce=\ nonce-encoded-base64
\Created=\ created \)]
   header)
 
  --
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
 your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
  ---
  You received this message because you are subscribed to the Google
 Groups Clojure group.
  To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https://groups.google.com/groups/opt_out.
 
 

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




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




Re: how to get SHA1 of a string?

2013-03-04 Thread Aaron Cohen
I'm not familiar with the class, but it seems that
MessageDigest/getInstance might retrieve some shared instance that could
theoretically need to be reset, no?


On Mon, Mar 4, 2013 at 2:43 PM, Frank Siebenlist frank.siebenl...@gmail.com
 wrote:

 That should work.

 No need for .reset though as the initially constructed MessageDigest is
 already in its initial state.

 Be careful with .digest as it implicitly resets the MessageDigest, and
 calling it a second time gives you the digest of the initial state which is
 not what you want.

 (all that incidental complexity is why I started to write that
 functional interface ;-) )

 -FS.


 On Mar 4, 2013, at 11:32 AM, Aaron Cohen aa...@assonance.org wrote:

  Ah darn, thanks for the catch. The following is uglier but should work I
 guess. :\
 
  digest (.digest
 (doto (java.security.MessageDigest/getInstance sha1)
   .reset
   (.update nonce-bytes)
   (.update created-bytes)
   (.update secret-bytes)))
 
 
  On Mon, Mar 4, 2013 at 2:25 PM, Frank Siebenlist 
 frank.siebenl...@gmail.com wrote:
   digest (- (java.security.MessageDigest/getInstance sha1)
   .reset
   (.update nonce-bytes)
   (.update create-bytes)
   (.update secret-bytes)
   .digest)
 
 
  There may be an issue with this snippet of code as .update does not
 return anything… i.e. nil.
 
  -FS.
 
 
 
  On Mar 4, 2013, at 11:06 AM, larry google groups 
 lawrencecloj...@gmail.com wrote:
 
  
   ;; Should UsernameToken Username really be unquoted in the
 following line?
   ;; All the other variable names are quoted
  
   Apparently, yes. The developer at Omniture reviewed it and said my
   only problem was the way the passwordDigest was created.
  
  
  
   On Mar 4, 2:02 pm, Aaron Cohen aa...@assonance.org wrote:
   I think you should try to avoid the string concatenation games. I'm
 not
   sure what your current code is, but I suspect you're still ending up
 with
   array toString's slipping in.
  
   How about the following?
  
   On Mon, Mar 4, 2013 at 1:31 PM, larry google groups 
  
   lawrencecloj...@gmail.com wrote:
   So, right now I am using this code:
  
(let [username (get-in @um/interactions [:omniture-api-
   credentials :username])
 secret (get-in @um/interactions [:omniture-api-credentials :shared-
   secret])
 nonce (DigestUtils/md5Hex (str (math/round (* (rand 1 ) 100
 nonce-encoded-base64 (Base64/encodeBase64 (.getBytes nonce))
 date-formatter (new SimpleDateFormat -MM-dd'T'HH:mm:ss)
 formatter gmt-timezone)
 created (.format date-formatter (new Date))
  
  nonce-bytes (.getBytes nonce)
  created-bytes (.getBytes created)
  secret-bytes (.getBytes secret)
  digest (- (java.security.MessageDigest/getInstance sha1)
   .reset
   (.update nonce-bytes)
   (.update create-bytes)
   (.update secret-bytes)
   .digest)
   digest-base64 (Base64/encodeBase64 digest)
  
   ;; Should UsernameToken Username really be unquoted in the
 following line?
   ;; All the other variable names are quoted
   header (apply str  UsernameToken Username=\  username
  
   ;; You may want digest-base64 here?
 \PasswordDigest=\ digest
  
 \ Nonce=\ nonce-encoded-base64
 \Created=\ created \)]
header)
  
   --
   --
   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

Re: how to get SHA1 of a string?

2013-03-04 Thread Aaron Cohen
Frank pointed out this mistake in my code a little farther in the thread.
Sorry for the confusion.

digest (.digest
   (doto (java.security.MessageDigest/getInstance sha1)
 .reset
 (.update nonce-as-bytes)
 (.update created-as-bytes)
 (.update secret-as-bytes)))


On Mon, Mar 4, 2013 at 3:07 PM, larry google groups 
lawrencecloj...@gmail.com wrote:



 I have a feeling you may be correct, so I copy and pasted your code
 into mine:

   (let [username (get-in @um/interactions [:omniture-api-
 credentials :username])
 secret (get-in @um/interactions [:omniture-api-
 credentials :shared-secret])
 random-number (math/round (* (rand 1 ) 100))
 nonce (DigestUtils/md5Hex (str random-number))
 nonce-encoded-base64 (base64-encode (.getBytes
 nonce))
 date-formatter (new SimpleDateFormat -MM-
 dd'T'HH:mm:ss)
 created (.format date-formatter (new Date))
 nonce-as-bytes (.getBytes nonce)
 created-as-bytes (.getBytes created)
 secret-as-bytes (.getBytes secret)
 digest (- (java.security.MessageDigest/
 getInstance sha1)
.reset
(.update nonce-as-bytes)
(.update created-as-bytes)
(.update secret-as-bytes)
.digest)
 header (apply str  UsernameToken Username=\
 username  \ PasswordDigest=\ digest \ Nonce=\ nonce-encoded-
 base64 \ Created=\ created \)]
 header)



 but now I get a null pointer exception here:

 digest (- (java.security.MessageDigest/
 getInstance sha1)
.reset
(.update nonce-as-bytes)
(.update created-as-bytes)
(.update secret-as-bytes)
.digest)





 On Mar 4, 2:02 pm, Aaron Cohen aa...@assonance.org wrote:
  I think you should try to avoid the string concatenation games. I'm not
  sure what your current code is, but I suspect you're still ending up with
  array toString's slipping in.
 
  How about the following?
 
  On Mon, Mar 4, 2013 at 1:31 PM, larry google groups 
 
  lawrencecloj...@gmail.com wrote:
   So, right now I am using this code:
 
(let [username (get-in @um/interactions [:omniture-api-
   credentials :username])
 secret (get-in @um/interactions [:omniture-api-credentials :shared-
   secret])
 nonce (DigestUtils/md5Hex (str (math/round (* (rand 1 ) 100
 nonce-encoded-base64 (Base64/encodeBase64 (.getBytes nonce))
 date-formatter (new SimpleDateFormat -MM-dd'T'HH:mm:ss)
 formatter gmt-timezone)
 created (.format date-formatter (new Date))
 
 nonce-bytes (.getBytes nonce)
 created-bytes (.getBytes created)
 secret-bytes (.getBytes secret)
 digest (- (java.security.MessageDigest/getInstance sha1)
  .reset
  (.update nonce-bytes)
  (.update create-bytes)
  (.update secret-bytes)
  .digest)
  digest-base64 (Base64/encodeBase64 digest)
 
  ;; Should UsernameToken Username really be unquoted in the following
 line?
  ;; All the other variable names are quoted
  header (apply str  UsernameToken Username=\  username
 
  ;; You may want digest-base64 here?
\PasswordDigest=\ digest
 
\ Nonce=\ nonce-encoded-base64
\Created=\ created \)]
   header)

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

Re: [GSoC 2013] CinC

2013-03-01 Thread Aaron Cohen
I'd really like to see this happen actually.

If there's interest I'd be happy to help or mentor.

The current status is that I have a commit that needs finishing to
implement letfn and I believe that was the last major special form that
needed implementing in the compiler.

Next up would be figuring out how to bootstrap a little better. It would
also be nice to pull in the work that's been done recently on the reader in
clojure and datastructures in clojure.


On Sat, Mar 2, 2013 at 12:50 AM, Ambrose Bonnaire-Sergeant 
abonnaireserge...@gmail.com wrote:

 Hi,

 I think completing Aaron Cohen's CinC implementation would be a fantastic
 GSoC 2013 project.

 https://github.com/remleduff/CinC

 Is Aaron willing to mentor this project? If the core.typed proposal isn't
 chosen, I would be interested in
 this project also as a student.

 Thoughts?

 Thanks,
 Ambrose


-- 
-- 
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: Loading in jars with dependencies at runtime into separate classloaders with independent classpaths

2013-02-19 Thread Aaron Cohen
This is the problem that OSGI tries to address and that the long-delayed
module system hopefully coming in JDK8 should handle (Project Jigsaw).

I think currently OSGI might be your best bet if you truly need it, though
there is quite a bit of work to get spun up on that.

You may get lucky and be able to use :exclusions in your project.clj to
make sure only the newest version of any dependency is used (assuming the
new version doesn't break backwards compatibility).

If you're brave, you could download an early-release of JDK8 and see how
Project Jigsaw works for you.

It is possible to spin your own solution using Classloaders, but probably a
lot of work.


On Mon, Feb 18, 2013 at 1:47 PM, Adam Clements adam.cleme...@gmail.comwrote:

 I'm working on a web api wrapper around a number of java/clojure
 libraries. One problem that I have run into is transitive dependency
 conflicts, especially when some of the projects are older than others.

 What I want to do is have each API endpoint's final handler function in
 its own classloader, with its own dependencies, ideally downloaded at
 runtime. That way none of them will interfere with one another and I can
 add new API endpoints without restarting the entire api server process.

 Is this possible? I have come across pomegranate for dependency resolution
 and classlojure for evaling in other classloaders, but I can't find any
 examples of doing both at once, and my experiments have so far been
 unsuccessful.

 Any hints would be much appreciated,

 Thanks,
 Adam

 --
 --
 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: Using local jar

2013-02-16 Thread Aaron Cohen
I'm not sure if this is your problem, but a newbie might not realize one
thing from that blog post.

After doing all the steps there, you still have to add the dependency for
that artifact in your project.clj

I don't know how you named your local jar, but for their example you would
need to add

:dependencies [

[jaad/jaad 0.8.3]]


On Sat, Feb 16, 2013 at 6:00 PM, Jarod jaaroddeerfi...@yahoo.com wrote:

 Hi.  This is a really basic question, as I'm new to Clojure and Java.  I'm
 trying to use a jar file for Stanford's NLP software that isn't available
 on Maven.  I successfully ran the commands from this website:

 www.pgrs.net/2011/10/30/using-local-jars-with-leiningen/

 to create a local maven repository, but how do I access the methods in the
 jar now?  I created a project using leiningen with eclipse and
 counterclockwise and I add the following to core.clj in the src directory
 to import the jar:

 (import 'stanford-corenlp)

 where stanford-corenlp is the name of the directory in the local maven
 repository.  However, I get the error:

 ClassNotFoundException stanford-corenlp  java.net.URLClassLoader$1.run
 (URLClassLoader.java:217)

 Thanks in advance for your help.

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 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: Using local jar

2013-02-16 Thread Aaron Cohen
Also, reading further on the blog, for lein2 you need to change


mvn install:install-file -Dfile=jaad-0.8.3.jar -DartifactId=jaad
-Dversion=0.8.3 -DgroupId=jaad -Dpackaging=jar
-DlocalRepositoryPath=maven_repository


to

mvn deploy:deploy-file -Dfile=jaad-0.8.3.jar -DartifactId=jaad
-Dversion=0.8.3 -DgroupId=jaad -Dpackaging=jar
-Durl=file:maven_repository



On Sat, Feb 16, 2013 at 7:13 PM, Aaron Cohen aa...@assonance.org wrote:

 I'm not sure if this is your problem, but a newbie might not realize one
 thing from that blog post.

 After doing all the steps there, you still have to add the dependency for
 that artifact in your project.clj

 I don't know how you named your local jar, but for their example you would
 need to add

 :dependencies [
 
 [jaad/jaad 0.8.3]]


 On Sat, Feb 16, 2013 at 6:00 PM, Jarod jaaroddeerfi...@yahoo.com wrote:

 Hi.  This is a really basic question, as I'm new to Clojure and Java.
  I'm trying to use a jar file for Stanford's NLP software that isn't
 available on Maven.  I successfully ran the commands from this website:

 www.pgrs.net/2011/10/30/using-local-jars-with-leiningen/

 to create a local maven repository, but how do I access the methods in
 the jar now?  I created a project using leiningen with eclipse and
 counterclockwise and I add the following to core.clj in the src directory
 to import the jar:

 (import 'stanford-corenlp)

 where stanford-corenlp is the name of the directory in the local maven
 repository.  However, I get the error:

 ClassNotFoundException stanford-corenlp  java.net.URLClassLoader$1.run
 (URLClassLoader.java:217)

 Thanks in advance for your help.

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 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: new, macros and Can't eval locals

2013-02-14 Thread Aaron Cohen
Yes, since this is runtime you should use reflection.

(let [a java.lang.RuntimeException]
   (.newInstance a))

Alternatively, you can use eval:

(let [a java.lang.RuntimeException]
  (eval (list 'new a)))


On Thu, Feb 14, 2013 at 4:53 PM, AtKaaZ atk...@gmail.com wrote:

 I figure since new is expecting a class at compiletime, we can never pass
 it a class that we evaluate at runtime(those locals), ergo = impossible to
 macro around new like that

 like this = impossible:
 *(let [a java.lang.RuntimeException]
  (macro-that-eventually-calls-new a))*

 maybe someone could suggest another way? clojure.reflect ?



 On Thu, Feb 14, 2013 at 10:40 PM, AtKaaZ atk...@gmail.com wrote:

 thanks for the reply,

 = *(defmacro mew [cls  args]
  `(new ~cls ~@args))*
 #'runtime.q/mew
 =* (let [a java.lang.RuntimeException]
  (mew a)
  )*

 CompilerException java.lang.IllegalArgumentException: Unable to resolve
 classname: a, compiling:(NO_SOURCE_PATH:2:3)

 that would be the equivalent macro of what *new* is doing
 it's like
 *(new a)*
 CompilerException java.lang.IllegalArgumentException: Unable to resolve
 classname: a, compiling:(NO_SOURCE_PATH:2:3)


 This is the goal:

 The goal is to can write this form:
 =  *(let [a java.lang.RuntimeException]
  (new a))*

 but I think it's impossible, at least by using new it is


 On Thu, Feb 14, 2013 at 10:34 PM, Andy Fingerhut 
 andy.finger...@gmail.com wrote:


 On Feb 14, 2013, at 1:27 PM, AtKaaZ wrote:

 The goal is to can write this form:
 = *(let [a java.lang.RuntimeException]
  (new a)
  )*
 CompilerException java.lang.IllegalArgumentException: Unable to resolve
 classname: a, compiling:(NO_SOURCE_PATH:2:3)

 attempt with macro:
 =* (defmacro mew [cls  restt]
  `(new ~(eval cls) ~@restt)
  )*
 #'runtime.q/mew


 This is probably your closest attempt.  Try this variation on the above:

 (defmacro mew [cls  args]
   `(new ~cls ~@args))

 user= (macroexpand-1 '(mew java.lang.RuntimeException))
 (new java.lang.RuntimeException)

 Andy

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






 --
 Please correct me if I'm wrong or incomplete,
 even if you think I'll subconsciously hate it.




 --
 Please correct me if I'm wrong or incomplete,
 even if you think I'll subconsciously hate 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
 ---
 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: How to invoke java method obtained using clojure.reflect

2013-02-12 Thread Aaron Cohen
You're actually probably better off using clojure's reflector
(clojure.lang.Reflector/invokeStaticMethod ...) or
(clojure.lang.Reflector/invokeInstanceMethod
...)

That way you get type coercions that match clojure's behaviour.


On Tue, Feb 12, 2013 at 9:16 AM, juan.facorro juan.faco...@gmail.comwrote:

 Awesome :)

 On Tuesday, February 12, 2013 9:51:01 AM UTC-3, Meikel Brandmeyer
 (kotarak) wrote:

 Hi,

 if you want to resort to eval you can define your own function on the fly.

 (defn call-fn
   [ args]
   {:arglists ([class method  args])}
   (let [o (gensym)
 [class method  args] (map symbol args)]
 (eval
   `(fn [~o ~@args]
  (. ~(with-meta o {:tag class})
 (~method ~@args))

 user= (set! *warn-on-reflection* true)
 true
 user= (def f (call-fn java.io.File renameTo dest))
 #'user/f
 user= (f (java.io.File. foo) (java.io.File. bar))
 false

 Kind regards
 Meikel

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 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: Installing Clojure on Windows 7

2013-01-24 Thread Aaron Cohen
On Thu, Jan 24, 2013 at 12:56 PM, sampson.jo...@googlemail.com wrote:

 Apparently installing a development environment for Clojure on Windows 7
 is very difficult. What is the best way, that has a chance that it might
 work?

 I'm curious if you have any more specific reasons for this statement?

-- 
-- 
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: Is contributing to clojurescript is intentionally made hard ?

2013-01-21 Thread Aaron Cohen
(Thanks for the apology Brandon. For those confused, he was responding to a
private email I sent him that said: I feel like you read my email until
you found something to nitpick, and then ignored the rest of it.)

On Sat, Jan 19, 2013 at 5:57 PM, Brandon Bloom snprbo...@gmail.com wrote:

  contributions to clojure are definitely less easy to make than to
 projects
  that willy-nilly accept any pull request.

 False dichotomy. Accepting pull requests does not mean you need to be
 willy-nilly about it.

 You know how people carefully optimize their signup forms and checkout
 flows? They do this because there's a (very large) category of people who
 simply give up when things aren't immediately obvious. Granted, this
 category is much smaller among the class of folks skilled enough to create
 a desirable Clojure patch. However, the fact that this topic keeps coming
 up suggests that maybe that group is large enough to pay attention too.


This is only a valid comparison if the goal for Clojure was gather as many
contributors as possible. If the goal is minimize maintainer effort, or
maximize maintainer pleasure, or maximize maintainer/submitter pleasure,
then the results are less comparable. Are we at the right point on the
axis? Maybe not, but Clojure has managed to collect quite a few
contributions over its life, so all I know is that we at least are not at a
complete minima.


 As the Clojure implementations evolve, fewer and fewer people will
 discover issues large enough to justify diving into the code base to fix
 them. Most people just work around the issues. If somebody takes the
 initiative to properly fix an issue, we shouldn't add yet another hurdle
 discouraging them from contributing.


I don't believe this is truly a likely scenario. In my experience there are
always minor bugs to be fixed.

However, I do think there is some sort of function that could be graphed of
patch size/complexity vs maintainer effort. The problem is that as patch
complexity drops to zero, maintainer effort does NOT, it drops to some
minimum. (Also, as patch size grows linearly, I would guess that maintainer
effort grows at some exponential). So, a contribution that is truly
valuable in terms of saving a maintainer effort actually has a fairly
narrow window of complexity.

This by the way, is why getting Rich's buy in before you start coding is
valuable.

(I sympathize with your dislike of JIRA by the way)

-- 
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: Is contributing to clojurescript is intentionally made hard ?

2013-01-19 Thread Aaron Cohen
Being the maintainer of an open source problem is a hard task.

Contributing to a project is not a process that begins and ends with code
submissions. In fact, it's often more work for a maintainer to accept a
patch or pull request than it is for him or her to write the equivalent
code himself.

Clojure is hardly the only project that doesn't accept pull requests. The
Linux Kernel and Guava are two that immediately come to mind. For Guava's
rationale, you might read the following:
https://plus.google.com/113026104107031516488/posts/ZRdtjTL1MpM Their
reasons are not identical to Rich's, but the sentiment is similar.

Does this mean you shouldn't even try to contribute? No, of course not.
But, contributions to clojure are definitely less easy to make than to
projects that willy-nilly accept any pull request.



On Sat, Jan 19, 2013 at 3:02 PM, Alexey Petrushin 
alexey.petrus...@gmail.com wrote:

 +1


 On Saturday, January 19, 2013 11:47:56 PM UTC+4, Andy Fingerhut wrote:


 On Jan 18, 2013, at 3:52 PM, Sean Corfield wrote:

  On Fri, Jan 18, 2013 at 1:33 PM, Andy Fingerhut
  andy.fi...@gmail.com wrote:
  The issue that Clojure, its contrib libraries, and ClojureScript do
 not accept github pull requests has been brought up several times before on
 this email list in the past.  Feel free to search the Google group for
 terms like pull request.  Short answer: Rich Hickey prefers a workflow of
 evaluating patches, not pull requests.  It is easier for him.
 
  My understanding is that with pull requests it becomes much harder to
  provide accountability for Intellectual Property which is a legal
  concern, and that's why we have a Contributor's Agreement. The patch
  process naturally falls out of the legal CA-covered process since each
  patch is clearly identified as belonging to a specific contributor -
  and submitting a patch comes with the responsibility of vouching for
  the legal status of that submission. Github's pull request process
  makes it all too easy to incorporate code that belongs to a Github
  account holder who is not covered by the legal agreement and places
  the burden of verification on screeners to verify the IP ownership.
 
  But let's not re-hash the issue of the CA. Folks can just read the
  archives and there's really nothing new to add...

 I won't rehash the issue, but will provide direct pointers to a couple of
 posts that led me to believe my statements above.

 Here is a link to the whole thread, with many posts on the
 then-just-being-started clojure-doc.org web site (which I'm pleased to
 see has certainly come a long way since early Oct 2012):

 https://groups.google.com/**forum/?fromgroups=#!topic/**
 clojure/jWMaop_eVaQhttps://groups.google.com/forum/?fromgroups=#!topic/clojure/jWMaop_eVaQ

 Scan a down to Jay Fields post from Oct 6 2012, and then to Rich Hickey's
 response later the same day.  I don't have any inside info about Rich's
 preferences for patches outside of such public messages, but it definitely
 seems to be due to workflow preference issues, not legal issues.

 Andy

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


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

Re: Is contributing to clojurescript is intentionally made hard ?

2013-01-19 Thread Aaron Cohen
Also, another blog post dealing with the open source code contribution
issue: http://www.igvita.com/2011/12/19/dont-push-your-pull-requests/


On Sat, Jan 19, 2013 at 5:38 PM, Aaron Cohen aa...@assonance.org wrote:

 Being the maintainer of an open source problem is a hard task.

 Contributing to a project is not a process that begins and ends with code
 submissions. In fact, it's often more work for a maintainer to accept a
 patch or pull request than it is for him or her to write the equivalent
 code himself.

 Clojure is hardly the only project that doesn't accept pull requests. The
 Linux Kernel and Guava are two that immediately come to mind. For Guava's
 rationale, you might read the following:
 https://plus.google.com/113026104107031516488/posts/ZRdtjTL1MpM Their
 reasons are not identical to Rich's, but the sentiment is similar.

 Does this mean you shouldn't even try to contribute? No, of course not.
 But, contributions to clojure are definitely less easy to make than to
 projects that willy-nilly accept any pull request.



 On Sat, Jan 19, 2013 at 3:02 PM, Alexey Petrushin 
 alexey.petrus...@gmail.com wrote:

 +1


 On Saturday, January 19, 2013 11:47:56 PM UTC+4, Andy Fingerhut wrote:


 On Jan 18, 2013, at 3:52 PM, Sean Corfield wrote:

  On Fri, Jan 18, 2013 at 1:33 PM, Andy Fingerhut
  andy.fi...@gmail.com wrote:
  The issue that Clojure, its contrib libraries, and ClojureScript do
 not accept github pull requests has been brought up several times before on
 this email list in the past.  Feel free to search the Google group for
 terms like pull request.  Short answer: Rich Hickey prefers a workflow of
 evaluating patches, not pull requests.  It is easier for him.
 
  My understanding is that with pull requests it becomes much harder to
  provide accountability for Intellectual Property which is a legal
  concern, and that's why we have a Contributor's Agreement. The patch
  process naturally falls out of the legal CA-covered process since each
  patch is clearly identified as belonging to a specific contributor -
  and submitting a patch comes with the responsibility of vouching for
  the legal status of that submission. Github's pull request process
  makes it all too easy to incorporate code that belongs to a Github
  account holder who is not covered by the legal agreement and places
  the burden of verification on screeners to verify the IP ownership.
 
  But let's not re-hash the issue of the CA. Folks can just read the
  archives and there's really nothing new to add...

 I won't rehash the issue, but will provide direct pointers to a couple
 of posts that led me to believe my statements above.

 Here is a link to the whole thread, with many posts on the
 then-just-being-started clojure-doc.org web site (which I'm pleased to
 see has certainly come a long way since early Oct 2012):

 https://groups.google.com/**forum/?fromgroups=#!topic/**
 clojure/jWMaop_eVaQhttps://groups.google.com/forum/?fromgroups=#!topic/clojure/jWMaop_eVaQ

 Scan a down to Jay Fields post from Oct 6 2012, and then to Rich
 Hickey's response later the same day.  I don't have any inside info about
 Rich's preferences for patches outside of such public messages, but it
 definitely seems to be due to workflow preference issues, not legal issues.

 Andy

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




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

Re: resolving a var when AOT-ed returns nil?

2013-01-16 Thread Aaron Cohen
My first guess would be *ns* is different when you try it at the repl.

To verify, try (ns-resolve 'PAnnotator.core (symbol ...



On Wed, Jan 16, 2013 at 1:31 PM, Jim - FooBar(); jimpil1...@gmail.comwrote:

 Hi everyone,

 Does anyone have a clue why this would perfectly run on the repl but  will
 throw NPE when run from the jar or via lein2 run (aot-ed)?

 ;;there exist global vars of the form  'xxx-NER-tags'
 ;;first the repl everything works as expected...I get the map back

 PAnnotator.core= (var-get (resolve (symbol (str (:for-lib opts)
 -tags
 {:middle  , :closing  END, :opening START:, :order [:entity
 :token]}

 Where (:for-lib opts) returns custom-NER ...

 Now when this is aot-ed and run either via the cmd or the jar it fails
 with NPE at var-get which is called with nil! For some reason resolving a
 symbol brings back nil and then of course (var-get nil) will throw...

 any ideas...It's been 2 hours since I did anything useful due to this...
 btw I am on Clojure 1.5-RC1...

 as always, thanks a lot...

 Jim





 --
 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+unsubscribe@**googlegroups.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/**group/clojure?hl=enhttp://groups.google.com/group/clojure?hl=en


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

Re: CLJS: protocol interfaces don't seem to support variable args in the arglist, like [ opts]

2013-01-16 Thread Aaron Cohen
On Wed, Jan 16, 2013 at 12:53 PM, Frank Siebenlist 
frank.siebenl...@gmail.com wrote:

 Thanks for the confirmation.

 I know that destructuring is supported in protocols as I'm using with much
 pleasure - kind of assumed it would work as it wasn't documented not to
 work ;-)


I don't believe this is true. You may think it is working, but you probably
are just ending up with a function that has a parameter named .

https://groups.google.com/forum/?fromgroups=#!topic/clojure/HyoSBEfEF4w

-- 
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: CLJS: protocol interfaces don't seem to support variable args in the arglist, like [ opts]

2013-01-16 Thread Aaron Cohen
Aha, yep, whoops.

--Aaron


On Wed, Jan 16, 2013 at 3:54 PM, Alan Malloy a...@malloys.org wrote:

 On Wednesday, January 16, 2013 11:17:41 AM UTC-8, Aaron Cohen wrote:

 On Wed, Jan 16, 2013 at 12:53 PM, Frank Siebenlist 
 frank.si...@gmail.comwrote:

 Thanks for the confirmation.

 I know that destructuring is supported in protocols as I'm using with
 much pleasure - kind of assumed it would work as it wasn't documented not
 to work ;-)


 I don't believe this is true. You may think it is working, but you
 probably are just ending up with a function that has a parameter named .

 https://groups.google.com/**forum/?fromgroups=#!topic/**
 clojure/HyoSBEfEF4whttps://groups.google.com/forum/?fromgroups=#!topic/clojure/HyoSBEfEF4w


 He said destructuring is working (which is true), not that varargs are
 working (which would not be true).

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


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

Re: All the ways to define metadata (and ^:static)

2013-01-09 Thread Aaron Cohen
On Wed, Jan 9, 2013 at 9:24 AM, Philip Potter philip.g.pot...@gmail.comwrote:

 On 9 January 2013 08:37,  wujek.sru...@gmail.com wrote:
 You're quite right, this changed in 1.3. It's even the first entry in
 the 1.3 changelog:

 https://github.com/clojure/clojure/blob/clojure-1.3.0/changes.txt

 which reads:

 1.1 Earmuffed Vars are No Longer Automatically Considered Dynamic

 The old convention was that vars surrounded with *earmuffs* were
 automatically considered dynamic and appropriate for a (binding [...])
 form. Now, everything must be explicitly made dynamic using ^:dynamic.


Just to be pedantic: in the past, ALL vars were dynamic, regardless of
earmuffs. There was a short period of time during the change of the default
where vars named with earmuffs were treated as if they had ^:dynamic
metadata (and they spit out a warning to developers that this behavior was
temporary).

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

Re: All the ways to define metadata (and ^:static)

2013-01-09 Thread Aaron Cohen
On Wed, Jan 9, 2013 at 10:17 AM, Wujek Srujek wujek.sru...@gmail.comwrote:

 So take this definition from master:

 (def

  ^{:arglists '([x])
:doc Return true if x implements ISeq
:added 1.0
:static true}
  seq? (fn ^:static seq? [x] (instance? clojure.lang.ISeq x)))

 static is used twice here. What is / was the difference? Is it correct to say 
 that it is now just noise in the code and could be stripped away? Is it 
 correct to say it has nothing to do with 'dynamic', contrary to what the last 
 SO post in the topic you linked to implies?


^:static really had/has nothing to do with ^:dynamic. It was an experiment
Rich was doing to improve performance by generating a static Class
method as opposed to an instance of IFn. So, ^:static here is referring to
the static keyword from Java.

The ^:static metadata had to be there during the definition of the function
itself for the compiler to know to emit a static method, so the first
:static true in your example is unnecessary. If it wasn't there though,
during runtime (:static (meta #'seq)) would be nil which might be confusing.

Those hoops are only necessary because defn hasn't been defined yet at that
point of core.clj.

--Aaron

-- 
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: deploying clojure/compojure web apps

2013-01-09 Thread Aaron Cohen
On Wed, Jan 9, 2013 at 4:27 PM, John Gabriele jmg3...@gmail.com wrote:

 On Wednesday, January 9, 2013 4:08:50 PM UTC-5, Phil Hagelberg wrote:


 John Gabriele writes:


 and this in main.clj:

 (defn -main [ [port]]
   (let [port (Integer. (or port (System/getenv PORT) 5000))]
 (jetty/run-jetty #'app {:port port :join? false}



What namespace is main.clj defining? It needs to have :gen-class added to
it.

Minimally, it could be

(ns my-webapp.main
   [[some dependencies here]]
   :gen-class)

You could also move -main into my-webapp.handler (and add :gen-class to
that ns declaration).


~~~clojure
 (defproject my-webapp 0.1.0-SNAPSHOT
   :description FIXME: write description
   :url http://example.com/FIXME;
   :dependencies [[org.clojure/clojure 1.4.0]
  [compojure 1.1.3]
  [ring/ring-jetty-adapter 1.1.6]]
   :plugins [[lein-ring 0.7.5]]
   :ring {:handler my-webapp.handler/app}
   :profiles
   {:dev {:dependencies [[ring-mock 0.1.3]]}}


  :main my-webapp.main


 )
 ~~~

 I'm guessing there's a `:main` missing in there. What should its value be?


Yes, it needs to be whatever the name of the namespace is that contains
your -main function. That namespace must have :gen-class in its definition.

-- 
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: Are strings expensive for memory on the JVM?

2013-01-05 Thread Aaron Cohen
On Sat, Jan 5, 2013 at 6:40 AM, Marko Topolnik marko.topol...@gmail.comwrote:


 On Saturday, January 5, 2013 12:35:27 PM UTC+1, Christian Sperandio wrote:

 About the String's expensiveness, working a lot with this kind of
 objects, it's big enough. In fact, that depends if you have a lot of small
 strings then the used memory space can become important.
 For instance, the word Bazinga takes almost 60 bytes in memory (for a
 32bits JVM) in which 24 bytes are used by internal String object. That
 space is bigger in 64 bits JVM. You can have more information from Internet
 (like http://blog.nirav.name/**2011/11/optimizing-string-**
 memory-footprint-in.htmlhttp://blog.nirav.name/2011/11/optimizing-string-memory-footprint-in.html
 ).

 Thus, when I need a lot of string chunks I often prefer use a characters
 array. It reduces the used memory footprint.


 It is good to know that, as of Java 7 Update 6, the String overhead has
 been reduced by two ints (should be 8 bytes): there is no more sharing of
 the *char[]* and, consequently, no more *offset* and *count* variables.


While it's true those fields aren't used any more, I was under the
impression at least one of those got replaced by the field used to cache
the new more-secure hashCode.

-- 
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: how to get the 'else' from if-not?

2013-01-04 Thread Aaron Cohen
Seems to work for me:

user= (make-user-nice-name { :username bazookajoe})
bazookajoe
user= (make-user-nice-name {:first_name Joe :username bazookajoe})
bazookajoe
user= (make-user-nice-name {:first_name Joe :last_name Blow :username
bazookajoe})
Joe Blow
user= (make-user-nice-name {:first_name Joe :last_name Blow})
Joe Blow

# This is the only suspicious behavior, but it's doing what you asked it to
user= (make-user-nice-name {:first_name Joe})
nil


On Fri, Jan 4, 2013 at 11:12 PM, larry google groups 
lawrencecloj...@gmail.com wrote:


 This function gives me a nicely formatted name if the user has supplied a
 first_name or a last_name, however, if there is no first_name and no
 last_name then I get nothing at all. But the username is there in the
 record. Can someone tell me what I did wrong? Why is the username not
 getting set as the value of user-nice-name?


 (defn make-user-nice-name [map-of-profile]
   (let [user-nice-name
 (if-not (or (nil? (:first_name map-of-profile)) (nil? (:last_name
 map-of-profile)))
   (apply str (:first_name map-of-profile)   (:last_name
 map-of-profile))
   (:username map-of-profile))]
 user-nice-name))

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

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

Re: how to get the 'else' from if-not?

2013-01-04 Thread Aaron Cohen
This is also where I love destructuring to make the code structure more
clear:

(defn make-user-nice-name [{:keys [first_name last_name username]}]
(if (and first_name last_name)
(str first_name   last_name)
username))


On Fri, Jan 4, 2013 at 11:26 PM, Sean Corfield seancorfi...@gmail.comwrote:

 Seems to work just fine for me:

 user (defn make-user-nice-name [map-of-profile]
   (let [user-nice-name
 (if-not (or (nil? (:first_name map-of-profile)) (nil?
 (:last_name map-of-profile)))
   (apply str (:first_name map-of-profile)   (:last_name
 map-of-profile))
   (:username map-of-profile))]
 user-nice-name))
 #'user/make-user-nice-name
 user (make-user-nice-name {:username seanc})
 seanc
 user (make-user-nice-name {:username seanc :first_name Sean})
 seanc
 user (make-user-nice-name {:username seanc :first_name Sean
 :last_name Corfield})
 Sean Corfield
 user (make-user-nice-name {:username seanc :last_name Corfield})
 seanc

 FWIW, I think it would be more readable (and more idiomatic) like this:

 (defn make-user-nice-name [map-of-profile]
   (if (and (:first_name map-of-profile) (:last_name map-of-profile))
 (str (:first_name map-of-profile)   (:last_name map-of-profile))
 (:username map-of-profile)))


 On Fri, Jan 4, 2013 at 8:12 PM, larry google groups
 lawrencecloj...@gmail.com wrote:
 
  This function gives me a nicely formatted name if the user has supplied a
  first_name or a last_name, however, if there is no first_name and no
  last_name then I get nothing at all. But the username is there in the
  record. Can someone tell me what I did wrong? Why is the username not
  getting set as the value of user-nice-name?
 
 
  (defn make-user-nice-name [map-of-profile]
(let [user-nice-name
  (if-not (or (nil? (:first_name map-of-profile)) (nil? (:last_name
  map-of-profile)))
(apply str (:first_name map-of-profile)   (:last_name
  map-of-profile))
(:username map-of-profile))]
  user-nice-name))
 
  --
  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



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

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

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


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

Re: Creating a dynamic var

2013-01-03 Thread Aaron Cohen
The issue here is that the documentation for intern says that it:

 Finds or creates a var named by the symbol name in the namespace
 ns (which can be a symbol or a namespace), setting its root binding
 to val if supplied. The namespace must exist. The var will adopt any
 metadata from the name symbol.  Returns the var.


It seems reasonable to me that intern should respect the metadata
being copied when it does the create.



On Thu, Jan 3, 2013 at 1:12 PM, Timothy Baldridge tbaldri...@gmail.comwrote:

 There's about 3-4 CLJ tickets related to this. The issue is that  :dynamic
 is only read once: when the var is created. If you need to change a var to
 be dynamic, you can set it manually with .setDynamic.

 Personally I think it's simply an artifact of how defs are created, and
 it's never been enough of a pain to anyone to suggest a better solution.

 What's being asked for is some sort of trigger. When :dynamic is set in
 the metadata call setDynamic. This seems like a bad idea to me.

 Timothy Baldrige


 On Thu, Jan 3, 2013 at 10:44 AM, Brian Marick mar...@exampler.com wrote:

 Why does this:

 (def ^{:dynamic true} bar 33)

 … work to create a dynamic var, but this:

 (intern *ns* (with-meta 'foo {:dynamic true}) 33)

 … doesn't? (Looking more for the justification than mechanics.)

 
 Occasional consulting on programming technique
 Contract programming in Ruby and Clojure
 Latest book: /Functional Programming for the Object-Oriented Programmer/
 https://leanpub.com/fp-oo

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




 --
 “One of the main causes of the fall of the Roman Empire was that–lacking
 zero–they had no way to indicate successful termination of their C
 programs.”
 (Robert Firth)

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


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

Re: Need help in geeting cemerick/friend working with openid

2012-12-19 Thread Aaron Cohen
On Wed, Dec 19, 2012 at 8:40 AM, Murtaza Husain 
murtaza.hus...@sevenolives.com wrote:

 (defroutes app-routes
   (GET / [] (resp/redirect /landing))
   (GET /landing [] (resp/file-response landing.html {:root public}))
   (GET /index [] (index index-data))
   (route/files / {:root public})
   (route/not-found Not Found))

 (def mock-app
   (- app-routes
   (friend/authenticate
{:allow-anon? false
 :login-uri? /landing
 :workflows [(openid/workflow :openid-uri /openid :realm 
 http://invoize.com;)]})))



I'm not fully conversant with all the libraries, but don't you actually
need to use mock-app somewhere?


 (def app
   (handler/site app-routes))



-- 
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: Closure Accordion Widget

2012-11-26 Thread Aaron Cohen
I've only used it at a very shallow level, but
https://developers.google.com/closure/library/docs/overview has seemed
quite nice to me?


On Sat, Nov 24, 2012 at 7:14 PM, Jonathan Fischer Friberg 
odysso...@gmail.com wrote:

 I don't think there's a consensus.
 You will have to weigh the pros/cons and choose what fits you best.

 For example:
 closure integrates perfectly with the closure compiler while jquery does
 not.
 jquery has great documentation while closure does not.
 And so on. :)

 Jonathan



 On Sat, Nov 24, 2012 at 7:20 PM, J Elaych microsc...@gmail.com wrote:

 So I guess that means using jayq.  Is that the new consensus on using
 clojurescript for guis?  I see lots of discussion on closure vs jquery in
 clojurescript but it is hard to tell what is going to be the standard.

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


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


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

Re: ease of use

2012-11-22 Thread Aaron Cohen
Reports like this are only as valuable as the information they provide.
While we're sympathetic with your frustration, you haven't even begun to
give us anything to go on in terms of 1) helping you with your problem or
even 2) improving Clojure.

Happy Thanksgiving!


On Thu, Nov 22, 2012 at 5:47 PM, atucker agjf.tuc...@gmail.com wrote:

 Sorry, I'm in a bad mood.  For context, after hours of struggling with
 Aquamacs and the new nrepl, I find it's overwritten my last two days' work.
 I guess it's likely my fault, I probably clicked the wrong key in my
 frustrated eightieth attempt to restart the repl.

 On Thursday, November 22, 2012 10:37:22 PM UTC, atucker wrote:

 K guys,
   I honestly don't want to piss on Clojure, I know how hard a lot of
 people have worked for a long time in order to make this a viable language.
  I respect and am grateful for your dedication.
   But you should know this: every time I come back to use Clojure I find
 that it's become harder.  Maybe it's my mind that's going (quite possible).
  Or maybe it's something you should worry about.
   A

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


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

Re: Can anyone explain this behavior of clojure.java.shell/sh ?

2012-11-10 Thread Aaron Cohen
I'm pretty sure xdg-open ends up being a thin wrapper that delegates
to your desktop environment's open program (gnome-open, kde-open,
xce-open, etc)
so probably that is where the difference lies.

--Aaron

On Nov 10, 2012, at 12:52 AM, Michael Gardner gardne...@gmail.com wrote:

 I can't duplicate your results on my Debian wheezy box (Clojure 1.4, openjdk 
 1.6.0_24, xdg-open 1.1.0 rc1); the call to (sh xdg-open …) returns 
 immediately. The only possibilities I can think of are that your version of 
 xdg-open blocks when run from a non-interactive shell, or that your version 
 of Java somehow handles subprocesses differently.

 The first possibility should be easy to test. And you should be able to test 
 the second by writing your own shell script that forks and then exits (at 
 least, I assume that's what xdg-open is doing).

 On Nov 9, 2012, at 19:26 , Andy Fingerhut andy.finger...@gmail.com wrote:

 This issue may be specific to Linux, or even to a particular version of 
 Linux that I am using (Ubuntu 11.10 32-bit desktop), although I doubt it is. 
  If others try this out, I'd be curious to know what your results are, 
 especially if you know why it is happening, and how it can be fixed.

 First, some behavior from a bash window on Ubuntu 11.10:

 % echo hi
 hi
 % xdg-open http://www.google.com
 %

 After pressing return for the xdg-open command above, my browser opens a tab 
 to Google's home page.  Back in the shell window, the next prompt appears 
 immediately, even though the browser is still running and open to that page. 
  That is what I expect to happen.

 However, if I do the following commands inside of a Clojure REPL (tested 
 Clojure 1.4 and 1.5-beta1 so far):

 % rlwrap java -cp ~/lein/clojure-1.4.0/lib/clojure-1.4.0.jar clojure.main
 Clojure 1.4.0
 user= (require '[clojure.java.shell :as sh])
 nil
 user= (sh/sh echo hi)
 {:exit 0, :out hi\n, :err }
 user= (sh/sh xdg-open http://www.google.com;)

 The invocation of echo returns immediately, printing the result and the next 
 REPL prompt.  But when I invoke xdg-open, while the browser window appears 
 and goes to the Google home page, back in the bash window I see no return 
 value and no new REPL prompt.

 If I quit the browser, then back in the bash window I finally see the return 
 value and a REPL prompt, as shown below:

 {:exit 0, :out , :err }
 user=


 What I'm wishing would happen is for the return value and REPL prompt to 
 appear very soon after pressing return when invoking xdg-open with 
 clojure.java.shell/sh.

 I added some debug print messages to a local copy of clojure.java.shell/sh, 
 and it is stopping when waiting for the evaluation of either @out or @err in 
 the final line of the function.

 If I do the same commands above on Mac OS X, with open instead of 
 xdg-open, it all works as I expect.

 Any clues?

 Thanks,
 Andy

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

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

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


Re: Can anyone explain this behavior of clojure.java.shell/sh ?

2012-11-10 Thread Aaron Cohen
I would check what open program it is that eventually gets used on
your system. I imagine whichever one it is is trying to make your life
easier by changing its behavior when invoke interactively vs in a
script.

once you find which one it is, you may be able to suppress that helpfulness.

--Aaron

On Nov 10, 2012, at 5:27 PM, Andy Fingerhut andy.finger...@gmail.com wrote:

 There must be a difference between these other folks's environments and mine, 
 given the different behavior.

 What I find so odd is that it hangs when invoked via clojure.java.shell/sh 
 from within the REPL, but returns immediately with another prompt when run 
 from bash.  I've even copied the xdg-open on the system exhibiting this 
 problem, because it is a shell script, and added debug statements to it to 
 print out environment variables.  They are nearly identical when invoked from 
 bash vs. when invoked from in the REPL, except for the value of 
 LD_LIBRARY_PATH.  I thought that might cause the different behavior, but 
 after tweaking things to make them the same I still saw the hang from the 
 REPL.

 I'll try creating another user on that system to see if it happens there, but 
 if most people don't see this behavior, that is a good thing for when/if the 
 patch for CLJ-896 is committed, which is the reason I was testing this and 
 finding the odd behavior.

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

 Thanks,
 Andy

 On Nov 10, 2012, at 12:26 PM, Aaron Cohen wrote:

 I'm pretty sure xdg-open ends up being a thin wrapper that delegates
 to your desktop environment's open program (gnome-open, kde-open,
 xce-open, etc)
 so probably that is where the difference lies.

 --Aaron

 On Nov 10, 2012, at 12:52 AM, Michael Gardner gardne...@gmail.com wrote:

 I can't duplicate your results on my Debian wheezy box (Clojure 1.4, 
 openjdk 1.6.0_24, xdg-open 1.1.0 rc1); the call to (sh xdg-open …) 
 returns immediately. The only possibilities I can think of are that your 
 version of xdg-open blocks when run from a non-interactive shell, or that 
 your version of Java somehow handles subprocesses differently.

 The first possibility should be easy to test. And you should be able to 
 test the second by writing your own shell script that forks and then exits 
 (at least, I assume that's what xdg-open is doing).

 On Nov 9, 2012, at 19:26 , Andy Fingerhut andy.finger...@gmail.com wrote:

 This issue may be specific to Linux, or even to a particular version of 
 Linux that I am using (Ubuntu 11.10 32-bit desktop), although I doubt it 
 is.  If others try this out, I'd be curious to know what your results are, 
 especially if you know why it is happening, and how it can be fixed.

 First, some behavior from a bash window on Ubuntu 11.10:

 % echo hi
 hi
 % xdg-open http://www.google.com
 %

 After pressing return for the xdg-open command above, my browser opens a 
 tab to Google's home page.  Back in the shell window, the next prompt 
 appears immediately, even though the browser is still running and open to 
 that page.  That is what I expect to happen.

 However, if I do the following commands inside of a Clojure REPL (tested 
 Clojure 1.4 and 1.5-beta1 so far):

 % rlwrap java -cp ~/lein/clojure-1.4.0/lib/clojure-1.4.0.jar clojure.main
 Clojure 1.4.0
 user= (require '[clojure.java.shell :as sh])
 nil
 user= (sh/sh echo hi)
 {:exit 0, :out hi\n, :err }
 user= (sh/sh xdg-open http://www.google.com;)

 The invocation of echo returns immediately, printing the result and the 
 next REPL prompt.  But when I invoke xdg-open, while the browser window 
 appears and goes to the Google home page, back in the bash window I see no 
 return value and no new REPL prompt.

 If I quit the browser, then back in the bash window I finally see the 
 return value and a REPL prompt, as shown below:

 {:exit 0, :out , :err }
 user=


 What I'm wishing would happen is for the return value and REPL prompt to 
 appear very soon after pressing return when invoking xdg-open with 
 clojure.java.shell/sh.

 I added some debug print messages to a local copy of 
 clojure.java.shell/sh, and it is stopping when waiting for the evaluation 
 of either @out or @err in the final line of the function.

 If I do the same commands above on Mac OS X, with open instead of 
 xdg-open, it all works as I expect.

 Any clues?

 Thanks,
 Andy

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

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient

Re: after a few days, my app dies -- how should I diagnose?

2012-10-22 Thread Aaron Cohen
On Mon, Oct 22, 2012 at 2:30 PM, larry google groups
lawrencecloj...@gmail.com wrote:


 And the core.clj looks like this:

 (ns who-is-logged-in.core
   (:gen-class)
   (:import (java.util Date))
   (:require clojure.string clojure.java.io who-is-logged-in.memory_display
 [clojure.data.json :as json])
   (:use   [net.cgrand.moustache :only [app delegate]]
   [ring.util.response]
   [ring.middleware.params]
   [ring.adapter.jetty :only [run-jetty]]))

 (def registry (atom {}))

 (defn add-to-logged-in-registry [this-users-params]
   We assume some user is looking at a site such as wpquestions.com and the
 Javascript on that site is sending an Ajax request to this app, every 10
 seconds, with a map of information about the user, which we need to store in
 the registry.
   (let [right-now (. (Date.) getTime)

Please do (System/currentTimeMillis) instead of allocating new Date
objects over and over.


 new-user-entry (conj this-users-params { updated right-now })]
 (if-not (nil? (get new-user-entry username))
   (swap! registry assoc (get new-user-entry username)
 new-user-entry

 (defn is-current? [this-users-map]
   If we have not received an Ajax request from a user during the last 15
 seconds then we can assume they have left the site. We need to remove them
 from registry.
 (let [most-recent-ping (get this-users-map updated)
   allowed-cutoff (- (. (Date.) getTime) 15000)]
   (if ( most-recent-ping allowed-cutoff)
 true
 false)))

 (defn remove-old-registrants []
   The registry should only show people who have pinged this app during the
 last 15 seconds. We rebuild the registry with only those users whose maps
 return true from is-current?
   (def updated-registry {})

This def is too ugly to live, and possibly a memory leak. Is it also
always empty?

   (swap! registry (fn [map-of-all-user-maps]
 (into {}
   (doall

(Not likely to be a problem, but into  and doall are redundant here.)

(for [[username-as-key each-user-map]
 map-of-all-user-maps :when (is-current? each-user-map)]
  (conj updated-registry {(get each-user-map
 username) each-user-map})))

I think that what you are doing here is something like the following?:

(into {} (keep #(is-current? %2) map-of-all-user-maps)


 (defn current-users [request]
   The default action of this app. Add new users to the registry, and delete
 the ones that are more than 15 seconds old
   (let [this-users-params (:params request)]
 (add-to-logged-in-registry this-users-params)
 (remove-old-registrants)
 (response (apply str (json/write-str @registry)

-- 
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: after a few days, my app dies -- how should I diagnose?

2012-10-22 Thread Aaron Cohen
On Mon, Oct 22, 2012 at 2:51 PM, Aaron Cohen aa...@assonance.org wrote:
 I think that what you are doing here is something like the following?:

 (into {} (keep #(is-current? %2) map-of-all-user-maps)

Bah, used the wrong function, since keep works on nil/not-nil this should be:
(into {} (filter #(is-current? %2) map-of-all-user-maps)

Sorry

--Aaron

-- 
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: after a few days, my app dies -- how should I diagnose?

2012-10-22 Thread Aaron Cohen
On Mon, Oct 22, 2012 at 2:54 PM, Aaron Cohen aa...@assonance.org wrote:
 On Mon, Oct 22, 2012 at 2:51 PM, Aaron Cohen aa...@assonance.org wrote:
 I think that what you are doing here is something like the following?:

 (into {} (keep #(is-current? %2) map-of-all-user-maps)

 Bah, used the wrong function, since keep works on nil/not-nil this should be:
 (into {} (filter #(is-current? %2) map-of-all-user-maps)

Or maybe my mental compiler is a little broken and that should be:
(into {} (filter #(- % val is-current?) map-of-all-user-maps)

As to why your app dies after a couple of days. It may because of
continually re-def'ing updated-registry, but it may not be. What do
your ring routes look like, and what are you using to serve your web
app?

-- 
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: unexpected NaN behavior

2012-10-09 Thread Aaron Cohen
On Tue, Oct 9, 2012 at 5:20 PM, David Nolen dnolen.li...@gmail.com wrote:
 On Tue, Oct 9, 2012 at 4:38 PM, Brian Craft craft.br...@gmail.com wrote:
 Can someone explain the last result here?

 [1 2 3 Float/NaN]
 [1 2 3 NaN]
 (= Float/NaN Float/NaN)
 false

This is a primitive comparison and follows IEEE floating point
semantics. NaN must not equal NaN.

 ; all is good so far, but...
 (filter #(= % %) [1 2 3 Float/NaN 4])
 (1 2 3 NaN 4)

This is an Object comparison, and in Java this follows the contract
for equals and hashCode. Thus, an object must be equal to itself (for
HashMap to work).

See: 
http://stackoverflow.com/questions/1408569/why-does-double-nan-equal-itself-when-wrapped-in-a-double-instance

and in particular:
http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html#equals(java.lang.Object)





 Now I'm lost. What just happened?

 The behavior is strange, I've simplified it a bit to the following:

 ((fn [x] (= x x)) Float/NaN)
 true
 ((fn [x y] (= x y)) Float/NaN Float/NaN)
 false

 This is using Clojure 1.4.0

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

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


Re: how do we go about promoting new clojure libraries?

2012-09-26 Thread Aaron Cohen
On Wed, Sep 26, 2012 at 3:40 PM, Michael Klishin
michael.s.klis...@gmail.com wrote:
 2012/9/26 Stuart Sierra the.stuart.sie...@gmail.com

 http://dev.clojure.org/display/community/Libraries is unorganized and out
 of date - volunteers welcome.


 Stuart,

 No, that's not how it works. You *first* make contribution process easy,
 *then* ask people to volunteer.

 Not the other way around, no.
 --

No, only if you want an unfiltered stream of absolutely anyone to
contribute is that true. If you're ok with restricting volunteers to
the subset who are actually willing show a little effort, making the
process slightly cumbersome might even be a net benefit.

--Aaron

-- 
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: Behavior of (eval) in different namespaces

2012-09-25 Thread Aaron Cohen
On Tue, Sep 25, 2012 at 4:58 PM, Alex Dowad alexinbeij...@gmail.com wrote:
 Does anyone know what's going on here?

 user= (let [a 1] (eval 'a))
 1

I have to assume you have a def of a lying around from previous
experimentation. This isn't valid otherwise.

--Aaron

-- 
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: mixing clojure source with java class files problem!

2012-09-18 Thread Aaron Cohen
On Tue, Sep 18, 2012 at 10:52 AM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 Hi all,

 I'm having a really ridiculous problem...let's say there is jar on clojars
 with the following structure:

 --- top-level (.jar)
   --foo (clojure namespaces)
 -a.clj
 -b.clj
 -c.clj
   --
   --bar (java .class files - no package declaration when compiled)

The package is baked into the .class file format. You can't change it
after the fack by just moving files in the directory structure.

You'll have to use a bytecode editor (such as Jar Jar Links:
http://code.google.com/p/jarjar/) to change the package
after-the-fact.

What are you trying to accomplish by doing this?

--Aaron

-- 
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: mixing clojure source with java class files problem!

2012-09-18 Thread Aaron Cohen
What did you use to compile this? I don't believe hyphens are legal in
Java package names.

It will be hard to use this in clojure, clojure converts hyphens to
underscores automatically behind the scenes in package names. But your
package actually has a (possibly invalid) hyphen in it's name, so the
mangling prevents your class from being found.

--Aaron

On Tue, Sep 18, 2012 at 11:58 AM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 decompiling a simple interface gives:

 package encog_java.customGA;

 import org.encog.ml.MLRegression;
 import org.encog.ml.genetic.population.Population;

 public abstract interface CalculateScore
 {
 public abstract double calculateScore(MLRegression paramMLRegression);

 public abstract boolean shouldMinimize();

 public abstract void setPopulation(Population paramPopulation);
 }

 the package declaration seems perfectly fine in the class files (as
 expected)...what on earth is happening? Tried both hyphen/underscore when
 :import-ing but i get the same error!

 Jim


 On 18/09/12 16:51, Jim - FooBar(); wrote:

 It still not finding the compiled classes! I compiled them all using the
 exact same package declaration as the one found in the jar that I'm
 producing!
 I was also careful to convert the hyphen (directory name) to an underscore
 (in the .java file)...

 I am still getting a :

 ClassNotFoundException encog_java.customGA.CustomNeuralGeneticAlgorithm
 java.net.URLClassLoader$1.run (URLClassLoader.java:366)

 the jar i'm referring to is on clojars [enclog 0.5.6-SNAPSHOT] in case you
 have any doubts that the classes are in there...

 any pointers are greatly appreciated...

 Jim





 On 18/09/12 16:16, Jim - FooBar(); wrote:

 On 18/09/12 16:00, Aaron Cohen wrote:

 The package is baked into the .class file format. You can't change it
 after the fack by just moving files in the directory structure.


 regardless of whether there is an actual package declaration?

 So, you're saying that if I compile the java source inside a replicated
 directory structure as the one it will be consumed from, everything will be
 fine?
 I honestly thought i could skip all that, by not having any packages at all!
 I also tried putting the class files right next to the clj files but again
 it wouldn't find them!

 What are you trying to accomplish by doing this?


 well, the short story is that I'm wrapping a library but I'm not completely
 satisfied with the way it does a couple of things...too many assumptions in
 some places - so I'm trying to sort of re-implement a couple of
 classes/interfaces and include them already compiled in a separate folder in
 the jar in case someone else faces similar issues. It took a while to write
 the java code and of course compile it successfully against all the
 prerequisites...now, apparently i need to recompile in a replicated dir
 structure...

 I did not use proxy and the gang cos it just seemed easier (mutable
 variables/inheritance etc etc)

 Jim



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

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


Re: mixing clojure source with java class files problem!

2012-09-18 Thread Aaron Cohen
On Tue, Sep 18, 2012 at 12:39 PM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 On 18/09/12 17:28, Aaron Cohen wrote:

 What did you use to compile this? I don't believe hyphens are legal in
 Java package names.


 I used regular

  javac -cp blah:blah:blah  encog-java/customGA/*.java

 the compiler did not complain because the actual package declaration uses
 underscore instead of hyphen.
 yes hyphens are indeed illegal... that is, you cannot write package
 foo-bar; but you can write package foo_bar;  when in fact being in the
 foo-bar folder.

 It will be hard to use this in clojure, clojure converts hyphens to
 underscores automatically behind the scenes in package names. But your
 package actually has a (possibly invalid) hyphen in it's name, so the
 mangling prevents your class from being found.

I was actually wrong here, I think. I should probably check closer,
but I now think that clojure only mangles its own package names when
necessary. I don't think it ever mangles doing pure interop.


 exactly!!! when I ask from clojure  (:import [encog-java.customGA aClass])
 clojure should convert the hyphen to match the actual package found in the
 declaration of class files. UNderscores are certainly legal characters...the
 thing is, it doesn't matter whether i use an underscore or not when
 importing - I always get the same error which makes me slightly
 suspicious...

 In my desperation, I went into my ~/.m2 directory and actually modified the
 jar by hand so the folder encog-java was renamed to encog_java but again
 the same story! I don't get it!!!

I actually just tried this (I don't recommend this approach though),
and it worked for me, maybe you missed a step.

 I think you'll have best luck if you make your directory structure
match the package name.

--Aaron

-- 
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: mixing clojure source with java class files problem!

2012-09-18 Thread Aaron Cohen
On Tue, Sep 18, 2012 at 12:54 PM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 On 18/09/12 17:50, Aaron Cohen wrote:

 I actually just tried this (I don't recommend this approach though),
 and it worked for me, maybe you missed a step.



 what jar is lein2 using? the one with the nice name or the one with the
 numbers at the end? which one of the 2 did you modify?

 Jim

 ps: btw thanks a million for your time

The one with the full timestamp. I extracted the whole thing, renamed
the directory and recompressed it.

user= (import encog_java.customGA.CustomNeuralGeneticAlgorithm)
encog_java.customGA.CustomNeuralGeneticAlgorithm

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


Re: using take-while with pred function that has state

2012-09-03 Thread Aaron Cohen
On Tue, Sep 4, 2012 at 1:24 AM, Ben Wolfson wolf...@gmail.com wrote:
 On Mon, Sep 3, 2012 at 1:58 PM, Stephen Compall
 stephen.comp...@gmail.com wrote:
 Of course take-while might cause more of a lazy seq to be realized
 than is present in its output because of seq chunking. But I'd *hope*
 that it wouldn't exacerbate that by reserving the right to work like,
 say, this, where n is the largest number of elements of a seq calling
 first might compute:

 1. Realize the first 1000n elements of a seq, retaining them in memory.
 2. Call pred on those elements in reverse order.
 3. If pred was true for all of them, realize the next 1000n elements,
 etc., otherwise return a lazy seq of the first stretch of elements for
 which pred returned true.

 That admittedly would be insane, but if pred is free of side-effects
 (and computing the elements of the collection is also free of
 side-effects) it would be correct.

It wouldn't even be all that insane if you had 1000 otherwise idle
cores sitting around and an expensive enough predicate.

-- 
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: function parameters were working, and now I suddenly get a cast error

2012-08-28 Thread Aaron Cohen
Larry,

   You are missing a bit of important code from the example in the blog post.

  In his original example, echo is a function (note the code block
that begins, (defn echo ...).

   His listen-and-respond function is what handles reading from the
ServerSocket, and responding back on the socket with the output (the
result of callin the service function).

   The ServerSocket constructor he invokes takes a single argument,
the port number. There is no constructor that takes a hostname as a
string, which is where all your attempts are failing (as you can see
from the javadoc for ServerSocket here:
http://docs.oracle.com/javase/1.4.2/docs/api/java/net/ServerSocket.html).

   Also, trying to take the what-to-do command line parameter and
treat it as a symbol is a total red herring. You should not normally
need to use the symbol function in typical clojure code, it is more
usually needed for macro manipulation.

So:

1) Remove localhost from your constructor invocation.
2) Your command line argument what-to-do is kind of nonsense.
listen-and-respond is expecting a fn as its 2nd argument


For instance:

(defn run-server [port what-to-do]
   (let [server-socket (ServerSocket. port)]
 (while (not (. server-socket isClosed))
   (listen-and-respond server-socket what-to-do

# I don't know if the following works, but something close to it probably will
(defn dumb-service [word]
  (fn [input output]
 (loop [line (.readLine input)]
 (if-not (= line ))
(recur (.readLine input))
(- output
(.println word)
.flush
.close)

(defn -main [ args]
   (let [port (Integer/parseInt (first args))
 word (second args))]
 (println Server is starting)
 (println port:  port)
 (println  (second args))
 (run-server port (dumb-service word


On Tue, Aug 28, 2012 at 8:25 PM, larry google groups
lawrencecloj...@gmail.com wrote:
 I apologize about the beginner questions. I am new to Clojure.

 If I do this:

 (defn run-server [port what-to-do]
   (let [server-socket (ServerSocket. port localhost)]
 (while (not (. server-socket isClosed))
   (listen-and-respond server-socket what-to-do

 (defn -main [ args]
   (let [port (Integer/parseInt (first args))
 service (symbol (second args))]
 (println Server is starting)
 (println port:  port)
 (println  (second args))
 (println  (symbol (second args)))
 (println service:  service)
 (run-server port service)))

 And on the command line I call it like:

  java -jar who-is-logged-in-1.0-standalone.jar 3456 who-is-here-now

 This prints out:

 Server is starting
 port:  3456
 who-is-here-now
 who-is-here-now
 service:  who-is-here-now

 but then I get this error:

 Exception in thread main java.lang.ClassCastException: java.lang.String
 cannot be cast to java.lang.Number
 at who_is_logged_in.core$run_server.invoke(core.clj:27)

 Line 27 is:

 (defn run-server [port what-to-do]

 The only way I can read the error message is to think that the code is
 trying to assign the value of what-to-do to the (integer) port.

 What have I done wrong?




 On Tuesday, August 28, 2012 12:47:44 PM UTC-4, larry google groups wrote:

 Command line arguments that are not strings need to be converted
  prior to use by your main function.

 That makes sense, I need to cast it to a symbol, yes? I have a problem
 with that though. At the REPL I tried something like this:

 (def hey (resolve (symbol what-to-do)))

 which worked great at the REPL, but in my code I get nil returned from
 resolve. If I do this:

 (defn -main [ args]
   (let [port (Integer/parseInt (first args))
 service (resolve (symbol (second args)))]
 (println Server is starting)
 (println port:  port)
 (println  (second args))
 (println  (symbol (second args)))
 (println service:  service)
 (run-server port service)))

 And call it like this:

 java -jar who-is-logged-in-1.0.0-SNAPSHOT-standalone.jar 3456
 who-is-here-now

 Everything looks correct till the final line when I get nil:

 Server is starting
 port:  3456
 who-is-here-now
 who-is-here-now
 service:  nil








 On Tuesday, August 28, 2012 6:53:24 AM UTC-4, Jon_Boone wrote:

 Command line arguments that are not strings need to be converted prior to
 use by your main function.

 Look at the code for the port number and do the same for the service.

 --jon


 On Aug 28, 2012, at 2:42, larry google groups lawrenc...@gmail.com
 wrote:


 So, this started when I read Keith Swallow's article on a simple web
 server:

 http://keithcelt.com/a-simple-web-server-in-clojure

 I took his code and ran lein new to create a new project and I copy and
 pasted his code to core.clj and made some minor adjustments, adding
 gen-class and main so I could run this from the command line. My main
 function looked like this:

 (defn -main [ args]
   (let [port (Integer/parseInt (first args))]
 (println Server is 

Re: Alternative to (or (:k1 m) (:k2 m))

2012-07-30 Thread Aaron Cohen
On Mon, Jul 30, 2012 at 6:55 PM, Moritz Ulrich ulrich.mor...@gmail.com wrote:
 (some identity ((juxt :k1 :k2) m)) is the first thing I can think of.

For even more fun, try (some m [:k1 :k2]) :)

--Aaron

-- 
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: Why :inline have to define the function twice?

2012-07-16 Thread Aaron Cohen
My guess: to allow functions with :inline metadata to still be used as
higher order (first class) functions.

Note, the fn specified by :inline is more of a macro than a function, it's
called at compile time.

How would the following work without a function body?

(map pos? [-1 0 1])

definline gives you what you're asking for, a way to define an :inline
function without repetition.

--Aaron

On Sun, Jul 15, 2012 at 10:43 PM, dennis zhuang killme2...@gmail.comwrote:

 Inline a function in clojure is easy,just define a :inline form to meta
 map and it will be inlined into the form which calls it.For example,the
 pos? function in clojure.core:

 (defn pos?

   Returns true if num is greater than zero, else false

   {

:inline (fn [x] *`(. clojure.lang.Numbers (isPos ~x))*)

:added 1.0}

   [x] *(. clojure.lang.Numbers (isPos x))*)


 But i have a question about the usage,why we have to write the body
 form(Here is *(. clojure.lang.Numbers (isPos ~x))*) twice both in
 function's body and :inline value? Why :inline form could not just use the
 form in function's body instead of duplicate definition?


 --
 庄晓丹
 Email:killme2...@gmail.com xzhu...@avos.com
 Site:   http://fnil.net
 Twitter:  @killme2008



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

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

Re: Why :inline have to define the function twice?

2012-07-16 Thread Aaron Cohen
On Mon, Jul 16, 2012 at 11:26 AM, dennis zhuang killme2...@gmail.com wrote:

 Yes, thank you for your reply,i total agree with you about why we need 
 :inline form in meta map.
 But my problem is that why clojure compiler could not use the body form as 
 the :inline value automatically for us instead of writing a duplicate form? I 
 think below codes is more suitable:

 (defn pos?
   Returns true if num is greater than zero, else false
   {
:inline true
:added 1.0}
   [x] (. clojure.lang.Numbers (isPos x)))


 Then clojure compiler finds out that we set :inline to be true and captures 
 the body form as the :inline value automatically,is it not better?

 If the function accepts different arguments arities, we can set 
 :inline-arities value to make compiler captures the body form  which 
 arguments count equals to :inline-arities value as :inline value.


As I said, that's precisely what definline does. As many things in
clojure, the simple pieces are given and easy things can be built on
top of them. I don't know precisely when in clojure.clj that pos? is
defined, but if it is late enough that definline has been defined,
it could be rewritten as:

(definline pos?
Returns true if num is greater than zero, else false
{:added 1.0}
   [x] `(. clojure.lang.Numbers (isPos x)))

Which is pretty much what you asked for, isn't it?

The fact that it isn't written that way is either historical or
because it needs to exist before definline does.

--Aaron

-- 
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: meta-questions - [clojure] in front of Subject line

2012-06-19 Thread Aaron Cohen
In gmail:
 1) click the down arrow next to clojure in the subject line (it has
a Show details tooltip).
 2) click the filter messages from this mailing list link next to
the mailing list
 3) This will automatically create a filter on words:
list:clojure.googlegroups.com
 4) Proceed to the next option Create a filter matching this search
 5) Apply a label, Clojure for instance
 6) Optionally, skip the inbox

The label in your inbox provides the exact visual indication you are
asking, without altering the subject line. In IMAP, it creates a
folder containing only those messages.

--Aaron

On Mon, Jun 18, 2012 at 11:46 PM, Andy Coolware andy.coolw...@gmail.com wrote:
 Hi,

 thx a lot for all  viewpoints. I am personally a bit torn. On one
 hand, when I open my gmail I have hard time to distinguish between all
 groups I am subscribed too. When you get tens of threads updated
 daily, this is really handy. However, I hate to have a redundant
 information in Subject and headers as it was pointed out. And even if
 that prefix is added,  the solution is not perfect since all my
 original posts are missing prefix too.

 Managing subfolders is out a question for me since I use multiple
 clients over IMAP. That would be a mess. I wish Thunderbird and gmail
 have an option to split the traffic by group in some automated fashion
 ...

 Cheers,
 Andy

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

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


Re: Calling Clojure from Java and classloader

2012-06-15 Thread Aaron Cohen
On Wed, Jun 13, 2012 at 11:48 PM, Warren Lynn wrn.l...@gmail.com wrote:
 Ok, I hit a wall and really did not see this coming.

 Based on what I have read, its really easy for Clojure and Java to
 work together. So I wrote some test Clojure code with a very simple
 defrecord (say named as testrec) and AOT compile it, create a jar
 file, and add it to a HelloWorld java project in Eclipse. I can
 create object of class testrec and run its member functions. Cool,
 no problem.

 But then I put the same thing into my target Java system (for which I
 am consider Clojure for production use), I got
 java.lang.ExceptionInInitializerError exception when trying to
 create my testrec object. A little bit more digging suggests this is
 related to class loader, which I don't know much about. According to a
 web page, I need to do this:

 Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());

 before calling the constructor of my testrec class. Tried that, but
 I got

 java.security.AccessControlException: access denied
 (java.lang.RuntimePermission setContextClassLoader)

 Seems I cannot change the context class loader.

 What is the solution here?

 Sorry for the long post. But I hope this is not a dead end. Thanks a
 lot.

It's not really a good idea to AOT your code and then directly try to
use it from java. The generated java bytecode isn't guaranteed to be
stable across versions of clojure, and you're depending on
implementation details.

One way to use your clojure code from java is through RT. An example
would be the accepted answer here:
http://stackoverflow.com/questions/2181774/calling-clojure-from-java

Another tack you can take is to use gen-class to create a real java
class from clojure and use that as an entry point to your clojure
code.

--Aaron

-- 
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: 'dotimes' will not work inside a 'doto'...

2012-06-14 Thread Aaron Cohen
On Thu, Jun 14, 2012 at 8:09 AM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 (doto foo
  (.bar x)
  (.baz y)
  (dotimes [i 10] (.zab g)))

 won't work because foo is substituted as the second argument of 'dotimes'!
 It has to be 'do' instead of 'doto'...

 very subtle trap...

 Jim

I think the trap here (if there is one) is that coming from another
language, you might believe that doto is setting some magical
context value. For instance, the with statement in javascript does
some sort of magic to alter the current scope.

If you understand that doto is simply a macro that alters the source
code that it is invoked upon, it's pretty clear what is wrong with
your code. This same understanding then applies to all the other
similar macros (.., -, -). None of them are doing anything other
than rearranging source code.

--Aaron

-- 
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: Type hint for vector element?

2012-06-14 Thread Aaron Cohen
On Wed, Jun 13, 2012 at 8:22 PM, Warren Lynn wrn.l...@gmail.com wrote:
 It is very common for all elements in a vector to be always of the same
 type. Is there any way to hint the type to Clojure? Does such hint can even
 improve performance? Thank you.


In general, not through type hints. However, there are implementations
of vector for primitive types, accessed using the vector-of
constructor function.
(http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/vector-of)

These are at least more space efficient, I'm not sure how they compare
performance-wise.

--Aaron

-- 
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: Clojure Sticker

2012-06-14 Thread Aaron Cohen
On Thu, Jun 14, 2012 at 2:52 PM, Rich Hickey richhic...@gmail.com wrote:
 No, you are not allowed to reproduce the Clojure logo and put it up for sale.

 I'd be happy to set up an official way to get stickers/shirts etc.

 Rich

I just wanted to mention that the American Apparel t-shirt that was
given out at Clojure/conj last year is still one of my favorite
t-shirts.

--Aaron

-- 
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: defrecord with inheritance

2012-05-21 Thread Aaron Cohen
On Mon, May 21, 2012 at 4:53 AM, nicolas.o...@gmail.com 
nicolas.o...@gmail.com wrote:

 
  Have you actually looked at the data structure implementations in
  ClojureScript? The work is done. It's all protocols.
 
 Hi David,

 I just have. This is a nice work. There is a lot of repetitions though.


I actually like this repetition. When it's simple one-liners like this, I
feel the explicitness is worth way more than any gains from re-use,
particularly because re-use often becomes a game of trying to find which
file defines the behavior you're interested in.

If the repetition were more substantial, the explicitness vs reuse tradeoff
would eventually crossover though.

--Aaron

-- 
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: docstrings of if-let and when-let incorrect

2012-05-21 Thread Aaron Cohen
On Wed, May 16, 2012 at 9:53 AM, Walter Tetzner 
robot.ninja.saus...@gmail.com wrote:

 On Wednesday, May 16, 2012 9:16:29 AM UTC-4, Aaron Cohen wrote:

 Saying something is obvious and then using the word monad a paragraph
 later is contradictory. ;)

 What should happen on the else branch of the if-let; which bindings are
 in scope and what would be their values?


 None of the bindings should be available in the else branch, since there
 would be no way to know which will succeed before run-time.


I actually think that having all the bindings available and just nil for
everything past the first failure would be more useful, and also matches
the intuition that it expands out to nested if-lets

(if-let [a 1 b 2 c nil] [a b c])


(if-let [a 1]
   (if-let [b 2]
  (if-let [c nil]
  [a b c]
  [a b c])
  [a b c])
   [a b c])

= [1 2 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: docstrings of if-let and when-let incorrect

2012-05-21 Thread Aaron Cohen
On Mon, May 21, 2012 at 1:43 PM, Jay Fields j...@jayfields.com wrote:

 There's a few issues there, first of which is that the code doesn't
 evaluate to what's shown:
 REPL started; server listening on localhost port 21867
 user=
 (if-let [a 1]
(if-let [b 2]
   (if-let [c nil]
   [a b c]
   [a b c])
   [a b c])
[a b c])
 java.lang.Exception: Unable to resolve symbol: c in this context
 (NO_SOURCE_FILE:3)

 The c isn't nil in the else form, it's unbound. The same would be true if
 it failed at any of the other levels, if the original if fails, a, b,  c
 are all unbound. So, setting them to nil isn't consistent. It might be a
 good option, but it's not consistent with the code above. I can't imagine
 that you'd want the else statement to have a bunch of possibly nil vars for
 any reason other than printing - otherwise you'd end up putting a bunch of
 conditional logic in the else to know which vars are nil, in which case
 you're better off using nested if-lets anyway. But, maybe the printing
 (i.e. logging) scenario is reason enough to bind these variables. I'd
 probably lean towards keeping them all unbound, as it's clear that each var
 would be bound (if form) or unbound (else form), versus each var being
 possibly truthy or nil in the else form.


Yeah, I was typing theory code. However, none defined in the else doesn't
fully match the nested if-lets behavior either. In the second if-let
stanza, a would be bound in the else case.

In any event, this is all just bike-shedding and illustrating that what
appears obvious isn't necessarily.

-- 
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: docstrings of if-let and when-let incorrect

2012-05-16 Thread Aaron Cohen
On Wed, May 16, 2012 at 9:10 AM, Walter Tetzner 
robot.ninja.saus...@gmail.com wrote:

 On Wednesday, May 16, 2012 9:01:49 AM UTC-4, Stuart Sierra wrote:How would
 multiple bindings for if-let or when-let work? Should every binding be
 testedd? Should they be and-ed together? Should it short-circuit if the
 first is false?


 I don't think there are obvious answers to those questions.


 Well, considering everyone on here that's answered that question said
 'AND', it seems to be obvious.

 To make the bindings work like let, where later bindings can see previous
 bindings, I think the most natural way to do it is to have the bindings
 behave like the maybe monad. The first time you encounter a false value, it
 fails. This way, you are using 'AND', but you don't run the risk of a
 NullPointerException in later bindings if a previous one fails.


Saying something is obvious and then using the word monad a paragraph later
is contradictory. ;)

What should happen on the else branch of the if-let; which bindings are in
scope and what would be their values?

--Aaron

-- 
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: what is the deal with ArraySeq?

2012-05-16 Thread Aaron Cohen
On Wed, May 16, 2012 at 1:04 PM, Jim - FooBar(); jimpil1...@gmail.comwrote:

  This is the only error I'm getting - there is no stack trace or at least
 i can not see it...I'm inside leiningen 2 preview 4... I can however
 provide 2 screenshots confirming what is happening.


Your most recent exception should be stored in *e.

To hopefully print a nice stack trace:

(use 'clojure.repl)
(pst)

-- 
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: what is the deal with ArraySeq?

2012-05-16 Thread Aaron Cohen
I believe that your problem is in make-data. If I understand correctly,
data has been closed over and is fixed at whatever value it happened to
be when you first defined make-data.

You need it to change make-data so that it returns a new function every
time, not one that has closed over data.

--Aaron

On Wed, May 16, 2012 at 1:04 PM, Jim - FooBar(); jimpil1...@gmail.comwrote:

  This is the only error I'm getting - there is no stack trace or at least
 i can not see it...I'm inside leiningen 2 preview 4... I can however
 provide 2 screenshots confirming what is happening.

 Thanks a lot for your time btw...

 Jim

 ps: function.png shows the function thatis being returned by make-data
 when passed the key :temporal-window.



 On 16/05/12 17:58, Walter Tetzner wrote:

 On Wednesday, May 16, 2012 12:51:15 PM UTC-4, Jim foo.bar wrote:

  I guess what I'm asking is at which point does the array become an
 ArraySeq and why casting it back to a double array with 'doubles' doesn't
 work?


 Can you post the whole stack trace?

 -Walter

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


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


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

  1   2   3   >