Re: Plain clojure 1.9 fails with Could not locate ... clojure/spec/alpha.clj on classpath. in Kubuntu 18.04

2018-05-21 Thread John Mastro
Jesús Gómez  wrote:
> Simply: 1.7 works but 1.9 not.

> Test:

> $ # Download Clojure 1.7, 1.8 and 1.9 jars
> $ seq 7 9 | xargs -L1 -I% wget
http://repo1.maven.org/maven2/org/clojure/clojure/1.%.0/clojure-1.%.0.jar
> $ seq 7 9 | xargs -L1 -I% java -jar clojure-1.%.0.jar -e '"1.%.0 is
Working"'
> "1.7.0 is Working"
> "1.8.0 is Working"
> Exception in thread "main" java.lang.ExceptionInInitializerError
> ...
> Caused by: java.io.FileNotFoundException: Could not locate
clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath.

Use the Linux installation script as described on the "geting started"
page[1]. This will also install Clojure's dependencies for you. The
installation script accepts a `--prefix` argument if you don't want to
install it globally.

[1]: https://clojure.org/guides/getting_started

Hope that helps

 John

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: class and case

2017-05-12 Thread John Mastro
Kevin Kleinfelter  wrote:
> Can someone help me get un-stuck with a problem of using class in a case?
>
> This returns true, as I expect:
> (= (type "x") java.lang.String)
>
> This returns an error, and I'd hoped it would print STRING:
> (case (type "x")
>  class java.lang.String (println "STRING")
>  class java.lang.Long (println "NUM"))
>
> Because the error said "No matching clause: class java.lang.String", I
> thought maybe this would be better, but if gave the same error:
> (case (type "x")
>  class java.lang.String (println "STRING")
>  class java.lang.Long (println "NUM"))
>
> Is in not possible to match on class in a case?

Correct, because the test expressions have to be compile-time constants.
Also, "class java.lang.String" isn't valid Clojure syntax for an
expression. Just "java.lang.String" evaluates to the class with that
name, but the test expressions aren't evaluated.

I think the most common approach for this scenario is to use condp:

(condp instance? "x"
 java.lang.String "STRING"
 java.lang.Long "LONG")

Hope that helps

John

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Keywords with colon on the backside?

2016-09-23 Thread John Mastro
Timothy Baldridge  wrote:
> The syntax (I think) comes from Ruby although they call keywords "symbols".

The reader syntax for Common Lisp's keywords has the leading colon too.

John

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Quil and Core.async - Problems blocking thread with

2016-08-02 Thread John Mastro
JvJ  wrote:
>   (try (do
>  (q/text "Putting beacon..."0 40)
>  (put! beacon true)
>  (let [ns ((q/fill 255)
>(q/text (str "State: " ns) 0 60)))
>(catch Exception e
>  (q/fill 255 0 0)
>  (q/text (str "Error: " e 0 60
>
>   state)

I don't know if this is related, but I noticed that where you have:

(q/text (str "Error: " e 0 60))

You probably mean this (based on the other calls to q/text):

(q/text (str "Error: " e) 0 60)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Land of lisp to Clojure

2014-07-09 Thread John Mastro
Cecil Westerhof  wrote:
> I read a little about it. And no, I do not use dynamic binding. So I
> probably should use atoms. Is there a convention how to name atoms?

Nope, none that I've come across anyway. Dynamic variables can have very
surprising effects if you're not aware you're dealing with them. This is
more of an issue in Common Lisp than in Clojure because in CL you can
rebind both dynamic and lexical variables with `let`, whereas in Clojure
`let` always produces a lexical binding (`binding` creates dynamic
bindings). With Atoms, the worst that happens is you forget to deref one
and you get an NPE or whatever.

Land of Lisp sounds like a fun book. My "books to read" stack is pretty
massive but I'll get to it eventually.

All the best,

John

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Land of lisp to Clojure

2014-07-08 Thread John Mastro
Hi Cecil,

Cecil Westerhof  wrote:
> - The book displays all the lines of a look on separate lines. In my
> case it is just one long line. Am I doing something wrong?

No, you're not doing anything wrong. There's nothing in that data
structure which would inherently cause it to print on multiple lines.

If you're using Cider, you can enable automatic pretty-printing in the
REPL, which would likely cause it to print on multiple lines. I think
it's M-x cider-repl-toggle-pretty-printing.

Or you could use a definition of look more like this, which uses println
to print each item on its own line (not sure if you wanted to retain the
parens or not, but both are easily doable).

(defn look []
  (doseq [d [(describe-location *location* nodes)
 (describe-paths *location* edges)
 (describe-objects *location* objects *object-locations*)]]
(println d)))

> - In Emacs Lisp you can use a function A in the definition of another
> function B before you declared function A. Is it correct that this is
> not possible in Clojure?

Correct, though you can declare it without defining it, e.g.
(declare function-a).

> - Al variables in land of lisp begin and end with an asterisk. As I
> understood it, you only do this for variables that can be changed. So
> I renamed some variables. Did I understand this correctly, or is the
> usage of asterisks for something else?

The "earmuffs" convention is related to dynamic variables. All global
variables are dynamic in Common Lisp, but that's not the case in
Clojure. You're creating dynamic variables (by using :dynamic metadata
in your defs) but I didn't notice anywhere where you're using this
feature (i.e. no binding or set! forms). Long story short, I would use
earmuffs if the variables are dynamic but not otherwise.

Speaking of global variables, I'd recommend only using def at top level
(it creates global vars regardless of where you use it). Perhaps it
would work to initialize them at top level with a "null value", like
(def something (atom nil)), and then set it later if/when appropriate,
like (reset! something (first whatever)). As a plus, if you use
atoms like this you most likely won't need dynamic variables, even if
you need to start changing global variable values later on.

Hope that helps,

John

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Instaparse - thank you!

2014-06-14 Thread John Mastro
Agreed - thanks Mark!

If anyone is able to share the query languages you're using (the language's
grammar more than the implementation), I'd be very interested (and
grateful).

I'm always struggling to create reports for our non-technical staff which
are flexible enough to be useful but don't rely on complicated UIs. I've
tried the natural language approach a couple times but haven't come up with
anything I'm happy with.

- John

On Tue, Jun 10, 2014 at 8:04 PM, Sean Corfield  wrote:

> I just wanted to post a public "Thank You!" to Mark Engelberg for his
> Instaparse library.
>
> https://github.com/Engelberg/instaparse
>
> We are just starting to use this at World Singles so that we can provide a
> "natural language" interface to our search engine, allowing our internal
> support folks to create custom queries without needing some complex
> cascading drop-down-filled UI to define complex queries. The ability to
> provide an English-like DSL for an otherwise very complex part of our
> business is a huge benefit!
>
> I started playing with Instaparse just yesterday morning and we have a
> working proof of concept up on QA today - Instaparse is an amazing tool!
>
> Sean Corfield -- http://clojurebridge.org
>
> "ClojureBridge aims to increase diversity within the Clojure community by
>  offering free, beginner-friendly Clojure programming workshops for women."
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Reduce vs. Comp

2014-05-07 Thread John Mastro
Hi,

Mike Fikes  wrote:
> In fact, section 5 of that document defines comp as a reduce
> involving the identify function in some way. (Now, I want to re-read
> this paper, but translated into Clojure.)

Here's one definition of comp in terms of reduce:

(defn comp [& fs]
  (reduce (fn [result f]
(fn [& args]
  (result (apply f args
  identity
  fs))

It's probably a bit clearer with one of the anonymous functions pulled
out and named:

(defn comp [& fs]
  (letfn [(chain [result f]
(fn [& args]
  (f (apply result args]
(reduce chain identity fs)))

They're less efficient than clojure.core/comp's implementation, but I
love the versatility of {reduce,fold,whatever}.

Best regards,

John

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: The Cons in iterate's return value

2014-04-16 Thread John Mastro
> I assume that there's a good reason that iterate returns a Cons
> instead of a LazySeq.

IIUC, this particular case arises because iterate's body is implemented
as

(cons x (lazy-seq (iterate f (f x

rather than

(lazy-seq (cons x (iterate f (f x

Can anyone comment on whether there's a reason to prefer one over the
other?

--
John Mastro

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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 work with variables that need to change

2014-04-12 Thread John Mastro
On Sat, Apr 12, 2014 at 5:13 AM, Cecil Westerhof 
wrote:
> But it looks a ‘little’ cumbersome. Is there a better way to do this?

Here's another way. Not the best way, but I offer it to introduce you
to atoms [1] if you're not familiar yet.

[1] http://clojure.org/atoms

(def numbers '(4 6 8 10))

(def needed-times (atom []))

(doseq [number numbers]
  (let [start   (now)
elapsed (fn elapsed []
  (- (.getTimeInMillis (now)) (.getTimeInMillis start)))]
(foo number)
(swap! needed-times conj (elapsed

--
John



>
> At the moment I have the following:
> (def numbers '(4 6 8 10))
>
> (doseq [number numbers]
>(foo number))
>
> The call foo generates some output, but I also want to save the time it
> took for the call to complete. At the moment I am thinking about
> something like:
> (def numbers '(4 6 8 10))
>
> (def ^:dynamic needed-times ())
> (doseq [number numbers]
>(let [start (now)]
> (foo number)
> (def ^:dynamic needed-times
>(cons (- (.getTimeInMillis (now))
(.getTimeInMillis start))
>  needed-times
>
>
>
> Also if I need to use several points in time, do I keep nesting ‘let’,
> or is there a better way?
>
> --
> 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.


Re: apply to quoted form

2014-03-21 Thread John Mastro
On Fri, Mar 21, 2014 at 4:44 PM, John Mastro wrote:
>
> That's interesting. It seems it's the last form in the list that's being
> returned, and it doesn't matter what function you apply
>

Sigh, clearly sometimes I type faster than I think. That should be "it
doesn't matter what symbol you apply", since as you already noted it's not
a function object at all.

--
John Mastro

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: apply to quoted form

2014-03-21 Thread John Mastro
On Fri, Mar 21, 2014 at 4:44 PM, John Mastro wrote:
>
> (let [f '(+ 1 1)]
>   (apply (resolve (first f) (rest f
> ;=> 2
>

Sorry, I have a typo in there. It should be:

(let [f '(+ 1 1)]
  (apply (resolve (first f)) (rest f)))

--
John Mastro

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: apply to quoted form

2014-03-21 Thread John Mastro
On Fri, Mar 21, 2014 at 3:55 PM, Andy Smith wrote:
> I came across the following issue when doing problem
>
> user=> (let [f '(+ 1 1)] (apply (first f) (rest f)))
> 1

That's interesting. It seems it's the last form in the list that's being
returned, and it doesn't matter what function you apply

(apply '+ '(2 1))   ;=> 1
(apply '+ '(1 2))   ;=> 2
(apply 'map '(2 1)) ;=> 1

I don't have any immediate thoughts on why it behaves like that, though
I'm sure there's a reason (?).

> I could use eval but eval is bad (apparently)...

You could use clojure.core/resolve instead, I think that should be safe.

(let [f '(+ 1 1)]
  (apply (resolve (first f) (rest f
;=> 2

--
John Mastro

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: STM and persistent data structures performance on mutli-core archs

2014-03-19 Thread John Mastro
> Due to the path-copy semantics, the contention gets driven to the root of the 
> tree. 

Out of curiosity, would reference counting (rather than or in addition to 
"normal" GC) help with this? Or is reference counting problematic in a highly 
concurrent environment? It seems like reference cycles will be less of an issue 
with immutable data. 

- John

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: shenandoah

2014-03-14 Thread John Mastro
Jacob Goodson wrote:
> I was wondering, would a GC like this one(or Azul's) make a
> significant impact so that I, or others, could make games in a more
> pure fashion? I WANT MY EFFIN PURITY!

I'm not particularly knowledgeable about either game development or
advanced garbage collection technologies, so forgive me if this is a
stupid idea.

That said, would reference counting (or rather, a combination of
reference counting plus some sort of GC or cycle detection algorithm) be
a possible way forward here? It seems like the reference counting would
be able to release many objects immediately after they become
unreachable. The "normal" GC would then have a lot less to do, helping
achieve shorter pauses.

(AFAIK no such thing actually exists for the JVM, this is just an idle
thought.)

--
John Mastro

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: query on clojure maps / vectors

2014-02-14 Thread John Mastro
t x  wrote:
> @David:
>   * set operations is not what I'm looking for

Just in case you didn't notice it (it's not called out very prominently), when
the `clojure.set` documentation [1] mentions a "rel" it's referring to a set of
maps - a "table" similar to what you mentioned.

[1] http://clojure.github.io/clojure/clojure.set-api.html

- John

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: map semantics

2014-02-08 Thread John Mastro
To add just one more thing to this: Referential transparency is clearly
valuable, but it's not the *only* valuable property a function or system might
have. There are always tradeoffs to be made. Clojure has made different
tradeoffs than you expected, or would yourself have made, but that doesn't
/a priori/ mean they're wrong.

- John

John Mastro  wrote:
> Hi Andy,
>
> Andy C  wrote:
>>
>>
>>> user> (= s1 s2)
>>> true
>>> user> (= (seq s1) (seq s2))
>>> false
>>
>>
>> Thx. If a=b  then f(a) must = f(b). Something is broken here.
>
> If a seq is a sequential view of a thing, and a set is an unordered thing, 
> then
> it does not seem shocking to me that multiple sequential views of a given set,
> with different orderings, are possible.
>
> This may not be the only way to do things; and it may not be the way other
> languages do it; and it may not match your preference. But I think it's 
> clearly
> wrong to say that it's internally inconsistent or "broken".
>
> It's perhaps hard to say this without sounding condescending, but rather than
> seeking to identify all the ways in which Clojure isn't Haskell, it might be
> more useful to pursue an understanding of Clojure (including its
> definitely-not-nonexistent flaws!) on its own terms.
>
> - John

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: map semantics

2014-02-08 Thread John Mastro
Hi Andy,

Andy C  wrote:
>
>
>> user> (= s1 s2)
>> true
>> user> (= (seq s1) (seq s2))
>> false
>
>
> Thx. If a=b  then f(a) must = f(b). Something is broken here.

If a seq is a sequential view of a thing, and a set is an unordered thing, then
it does not seem shocking to me that multiple sequential views of a given set,
with different orderings, are possible.

This may not be the only way to do things; and it may not be the way other
languages do it; and it may not match your preference. But I think it's clearly
wrong to say that it's internally inconsistent or "broken".

It's perhaps hard to say this without sounding condescending, but rather than
seeking to identify all the ways in which Clojure isn't Haskell, it might be
more useful to pursue an understanding of Clojure (including its
definitely-not-nonexistent flaws!) on its own terms.

- John

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Help about using clojure in org mode in Emacs with CIDER

2014-01-28 Thread John Mastro
Stuart Sierra  wrote:
> Don't know if it's relevant or helpful here, but here's my Emacs org / babel 
> / Clojure setup:

Thanks Stuart, very useful indeed (for me anyway).

- John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: let bindings

2014-01-20 Thread John Mastro
> If there's another reason then I'm hoping someone will correct me, but I
> can't think of any other reasons at the moment.

Since Clojure doesn't do tail call elimination implementing let atop fn would 
also use up stack. 

I believe many or all Schemes (which are required by the spec to eliminate all 
tail calls) do implement let in that way, but Common Lisps (where it's not 
promised by the spec, though some implementations with some settings will) does 
not, likely at least in part for the same reason. 

- John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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 clojure.zip when calling next on empty list node?

2013-12-31 Thread John Mastro
Hi Lee,

> Can anyone tell if I'm right that this is a bug in clojure.zip? If so, then 
> is the right thing to do to post an issue on JIRA?

I don't have any insight regarding whether this is a bug (haven't yet had an 
opportunity to dig into clojure.zip or zippers in general). However, I think 
you're right that opening a ticket on JIRA is the next step.

- John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: is there a tutorial about working at the REPL?

2013-12-30 Thread John Mastro
On Sun, Dec 29, 2013 at 1:30 PM, larry google groups
 wrote:
> Thanks for that. But the app has no problem reading the schema.edn file when
> I start the app with:
>
> java -jar admin-1-standalone.jar
>
> So why would it have trouble reading the file when I'm in the repl?

Can you post the project (or just the EDN file)? It's hard to get specific
without seeing more.

My general REPL-driven debugging strategy is to run the code in question in
smaller and smaller increments until I find the minimum piece of code that
fails. That will help you pinpoint where the issue is.

So, for instance, you know that (initiate-forms) fails, and you noted that it
contains (read-string (slurp (clojure.java.io/resource "config/schema.edn"))).
Given that, I would try each of the following in sequence:

1. (clojure.java.io/resource "config/schema.edn")
2. (slurp (clojure.java.io/resource "config/schema.edn"))
3. (read-string (slurp (clojure.java.io/resource "config/schema.edn")))

Of course, also include anything else in `initiate-forms`. Going through that
may lead you to the problem, but if not please reply with the result of each of
those expressions, including the details of any exception(s) thrown. Based on
the error in your REPL session

- John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: is there a tutorial about working at the REPL?

2013-12-28 Thread John Mastro
Hi Larry,

> 4.) load whatever file holds the (main-) function that starts the app. So for
> me, for instance, it might be: (load-file "src/admin/core.clj")

I don't think the `load-file` should be necessary. Do things not work if you
omit it?

The code on disk when you jacked in will already have been loaded, so you
should only need to re-evaluate it (whether through cider/nrepl.el,
`load-file`, or what have you) if you've made subsequent changes. I tend to use
`cider-eval-defun-at-point`, `cider-eval-last-sexp`, or `cider-eval-region` to
evaluate just the code I've changed rather than reloading the whole file.
(Actually, lately I've been using the `tools.namespace`[1] approach a lot, but
that's probably a separate topic).

(Cider[2], by the way, is just nrepl.el's new name).

> But when I want to work on this app at the REPL, the app seems unable to find
> the schema.edn file. You can see my REPL session below. The function
> (initiate-forms) has this line: (read-string (slurp (clojure.java.io/resource
> "config/schema.edn")))

I'm not positive, but I don't think the issue is that it can't find
"config/schema.edn". What's the result of (clojure.java.io/resource
"config/schema.edn")?

If it can't find the file, `clojure.java.io/resource` returns nil; and (slurp
nil) throws an IllegalArgumentException, which doesn't seem to be the error
you're getting.

[1] https://github.com/clojure/tools.namespace
[2] https://github.com/clojure-emacs/cider

- John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Is The Joy if Clojure up to date?

2013-11-30 Thread John Mastro
Manning (the publisher) has an interesting early-access program called MEAP. I 
used it to buy [1] electronic access to both the first edition and the second 
edition (the in-progress version immediately, plus the final version when it's 
released). I've been very happy with the arrangement. 

[1] http://www.manning.com/fogus2/

- John

> On Nov 30, 2013, at 10:34 AM, Mars0i  wrote:
> 
> Amazon claims that the publication date of the second edition is Feb. 28, 
> 2014.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: parse a text file that has some binary characters

2013-11-19 Thread John Mastro
On Tue, Nov 19, 2013 at 6:24 AM, smk  wrote:

> Hi
> I am trying to parse a text file that has some binary characters(such as
> 0x001 or 0x002) and replace them with text characters.
> How to do it in clojure?
>

Would something like this work?

(require '[clojure.java.io :as io])

(def replace-chars
  "A map of characters to their replacements."
  (let [m {0x01 \X, 0x02 \Y, 0x03 \Z}]
(into {} (map (fn [[k v]] [(char k) v])
  m

(defn read-lines [filename]
  (with-open [rdr (io/reader filename)]
(doall (line-seq rdr

(defn read-and-replace [filename]
  (for [line (read-lines filename)]
(apply str (map #(get replace-chars % %) line

I tried it like this:

(def test-file "/home/jbm/text-and-binary.txt")

(defn create-test-file [filename]
  (with-open [wtr (io/writer filename)]
(.write wtr "foo")
(.write wtr 0x01)
(.write wtr "bar")
(.write wtr 0x02)
(.write wtr "baz")))

(create-test-file test-file)

(read-lines test-file)   ;=> ("foo^Abar^Bbaz")
(read-and-replace test-file) ;=> ("fooXbarYbaz")

- John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Padding missing elements in a sequence of identical K/V maps

2013-11-19 Thread John Mastro
This was my first thought (quite close to Jim's):

(def the-maps [{:key 3 :value 30} {:key 4 :value 40}])

(def mandatory-keys [1 2 3 4 5])

(defn find-missing-keys [maps keys]
  (let [found (into #{} (map :key maps))]
(remove #(contains? found %) keys)))

(defn ensure-mandatory-keys [maps]
  (let [missing (find-missing-keys maps mandatory-keys)]
(sort-by :key (reduce (fn [result key]
(conj result {:key key :value nil}))
  maps
  missing

(ensure-mandatory-keys the-maps)
;; ({:key 1, :value nil}
;;  {:key 2, :value nil}
;;  {:key 3, :value 30}
;;  {:key 4, :value 40}
;;  {:key 5, :value nil})

- John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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.


What's the -dup in print-dup?

2013-11-02 Thread John Mastro
This isn't a very deep question, but I wonder every time I come across it:
to what does "-dup" in `print-dup` and `*print-dup*` refer?

Thanks

- John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-19 Thread John Mastro
> John, thanks. Not a stupid question at all. When learning a new language, a 
> new environment, and using an unfamiliar OS, there are so many moving parts 
> that it is sometimes hard to know where to begin when tracking stuff down. My 
> old and favorite line here is that "signposts are generally made by people 
> who know the lay of the land"..
> So please keep the advice coming.


Were you able to get it working after setting :dependencies?

To expand a bit on what's going on: Part of what Leiningen does for you is 
manage your dependencies (including Clojure itself, which is very cool). It 
will both install them and arrange for the correct classpath to be in effect 
when you run e.g. 'lein repl' or 'lein run' from your project directory. You 
only need to tell Leiningen about your direct dependencies - it will 
automatically handle their dependencies as well. 

I'd recommend taking a look at Leiningen's official tutorial if you haven't 
already:
https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md

I've never used Eclipse so I can't be any help there. 

- John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread John Mastro
> So, clearly I need to get  the libs onto the classpath. The questions are 
> what libs, where and how?

Forgive me if this is a stupid question, but have you already listed the 
dependency coordinates under the :dependencies key of your project.clj?

Leiningen has a sample project.clj here: 
https://github.com/technomancy/leiningen/blob/master/sample.project.clj

You're unlikely to need most of the options - just take a look at 
:dependencies. Each project will list the appropriate coordinate vector (e.g. 
[some/project "1.0.0"]) on their project page and/or GitHub repo.

- John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Question on mapcat and its variable arity

2013-08-25 Thread John Mastro
On Aug 25, 2013, at 2:43 PM, ngieschen  wrote:

> I'm somewhat new to clojure and trying to understand mapcat, so apologies in 
> advance if this is an embarrassingly elementary question.
>
> mapcat's signature is (f & colls) which indicates to me I should be able to 
> so something like (mapcat #(list (inc %)) [1 2 3] [4 5 6]). That is, doesn't 
> the & indicate that I can pass in a variable number of colls? However, if I 
> do, it crashes and burns, since internally it's calling (apply map #(list 
> (inc %)) '([1 2 3] '[4 5 6])), which, as expected, throws an ArityException.

Try this:

(mapcat #(list (+ %1 %2)) [1 2 3] [4 5 6])

The function f needs to accept a number of arguments equal to the
number of colls.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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.