Re: Lots of newbie clojure questions

2010-12-07 Thread Alyssa Kwan
Incidental mutability is the key.  Functional programming doesn't
eliminate mutability, it manages it:  only the parts of the system
that truly need to change state do so.  Everything else is pure and
easy to write and test.  Contrast that with imperative programming
where it's hard to tell which state changes are incidental and which
are truly required.  That's why Clojure provides identity objects:
immutability is the default, and you have to ask for state change.
That makes it a red flag that other programmers maintaining your code
can observe.

Idioms should be functions or macros.  That's the beauty of symbolic
programming:  no boilerplate.

Thanks,
Alyssa

On Dec 6, 9:19 pm, Robert McIntyre  wrote:
> 1. What is the justification for using a map as a function? I find
> this to be very confusing.
>
> In math, a function is a mapping from one set to another, so from that
> perspective it makes good sense for a clojure-map to be a function
> from its set of keys to its set of values. The justification here is
> mathematical convention.  Same thing with vectors being functions.
>
> 2. In practice, I find myself wincing when needing to decide whether
> or not to type an open-paren. Is that a common thing?
>
> Normally this isn't a problem for me because I always look at the
> bottom of my emacs window and am able to see the arguments whatever
> function I'm working with requires.
>
> 3. Is there a compendium of recursive idioms, ideally expressed in
> clojure? Including indentation conventions! (Is there an opportunity
> for a python inspired pre-processor that interprets indentation as
> parens?)
>
> You might try SICP (http://mitpress.mit.edu/sicp/) because Professor
> Sussman is awesome.
> Also try the clojure cookbook
> (http://en.wikibooks.org/wiki/Clojure_Programming/Examples/Cookbook)
>
> 4. Why don't long-running clojure programs monotonically increase in
> heap usage if all data-structures are immutable?
>
> If every reference to an immutable structure disappears than that
> structure can be garbage collected. Therefore, loops that create
> intermittent structures aren't that much of a memory hog since java
> garbage collects the structures every turn of the loop.
> ;;Memory : 0
> (let [a (range 5)]) ;; Memory: "big" while the let is "executing"
> ;;Memory : 0 -- no reference to a anymore !
>
>  5. In the REPL, isn't it redundant to always have to type the top-
> level parens?
>
> not for (let    :)
>
> 6. Is there a place to get guidlines on macro idioms? The feature is
> so powerful that it seems like it would be easy to misuse it and crack
> a programmers head like a nut with a badly structured macro.
>
> Try Stuart Halloway's book, Programming Clojure.  I liked it, at least.
>
> 1. Isn't the world actually imperative? And mutable? Collaboration
> *is* a messy proposition in real life. It's hard to fix your car, and
> even harder to have lots of people fix your car. I find the "it models
> the real world better" justification for functional programming rather
> confusing. (Indeed, the CPU and physical memory also have an
> imperative relationship!)
>
> The amount of mutability depends on your level of granularity. Let's
> say you want to add two numbers  --- if you consider all the robotic
> actions the arm in your hard disk must do to load the memory into the
> CPU, the flow of electrons in the wires, etc, then there does seem to
> be mutable state everywhere. But, addition itself is a pure function,
> so the mutable state is incidental complexity that doesn't really
> matter in the long run. You can tell it doesn't matter because you can
> change all the mutable physical stuff and it won't affect the
> computation. You might use an abacus, a hydraulic computer, your
> brain, etc, but 2 + 2 is still 4 no matter how you get there. Just as
> Greens Theorem can transform a surface integral into a line integral
> and save a lot of work, it's important to circumscribe as much mutable
> state as possible with abstraction barriers to make our lives simpler.
>
> 2. 'Side-effects' are treated almost as a bad word by most functional
> programming advocates. And yet, aren't ALL programs executed for their
> side-effects? Does "side effect" perhaps then require a qualification
> or a tighter definition? Or perhaps side-effects "aren't that bad"?
>
> What is a side effect and what isn't depends again on your level of
> granularity.  Too many side effects is a warning of "badness" because
> it means that you might be working at the wrong abstraction level.
> Incidental mutability should be removed because it just clutters
> everything up, but truly necessary mutability is just fine.
>
> 3. What is the relationship between the "shape" of a clojure program
> and the runtime call stack? (I ask because a clojure program looks
> strikingly similar to the callstack of an ordinary program when you
> 'pause' a thread.)
> 4. Is it possible (and/or advisable) to introduce a typing system on
> top of clojure? E.g.

Re: Why I'm getting StackoverflowError?

2010-12-07 Thread Meikel Brandmeyer
Hi,

Am 06.12.2010 um 22:38 schrieb Ken Wesson:

> A reduce that discards one of its arguments (e.g. (reduce (fn [n _]
> (inc n)) coll)) also strikes me as slightly icky. :)

Indeed this would fit in the 5% left. Anyway: I can't remember writing a 
function with accumulator not using the other argument in production code.

Sincerely
Meikel

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


Re: Lots of newbie clojure questions

2010-12-07 Thread javajosh
On Dec 6, 11:58 pm, Ken Wesson  wrote:
> On Tue, Dec 7, 2010 at 2:15 AM, javajosh  wrote:
> > Mike and I have had a nice off-line conversation where we enumerated
> > the possible things that can come after open-parens. I listed 7, he
> > added 3:
>
> >> 1. A value (if the paren has a tick '(  )
> >> 2. A function.
> >> 3. A map - which is a psuedo function that takes a key as an arg.
> >> 4. A keyword - which is a psuedo function that takes a map as an arg.
> >> 5. A macro. This is the normal case, I think. Looking through the mailing
> >> list, it appears that most clojure programming questions revolve around
> >> which one of the hundreds of macros to invoke and in which order!
> >> 6. The Java form: (MyClass. )
> >> 7. The java method form (.doSomething)
> > 8. A function returning a function to invoke - ((find-my-function) )
> > 9. A loop - (recur )
> > 10. The anonymous function macro: #( )
>
> > So, at least I know why I feel uneasy about open paren! It's super
> > overloaded.
>
> Not really. (...) is a non-atomic s-expression. If it's evaluated
> unquoted, the first nested s-expression is evaluated and if it's not
> callable an exception is thrown. Macros, special forms (which are sort
> of like system-internal macros and are used to build all the other
> macros, and functions), Java constructors, Java methods, and functions
> are callable (and maps and keywords -- also vectors -- act as
> functions for this purpose).

So, to paraphrase: "all of those things act like functions, parens
just call functions, so parens aren't overloaded." ..Which is about
two steps away from a tautology.  :)

Anyway, I'm aware that open-parens is the signal to Invoke or Call
something in Clojure - and therefore anything after the parens is
Callable. It is the incredible diversity of 'Things I Can Invoke' that
makes the parens difficult to a newb. (Although, I have to say,
enumerating the possibilities is helping me immensely.)

As an aside, it would be nice if there was some code convention to
distinguish between macros and functions, just as there is a
convention for identifying globals. (doc something) gets to be rather
tedious to type.

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

2010-12-07 Thread Ken Wesson
On Tue, Dec 7, 2010 at 4:22 AM, javajosh  wrote:
> As an aside, it would be nice if there was some code convention to
> distinguish between macros and functions, just as there is a
> convention for identifying globals. (doc something) gets to be rather
> tedious to type.

+1, with two provisos: special forms should look like macros (since
they may evaluate their arguments selectively, or late, or etc.) and
it's kind of too late to do that now without ruining compatibility
with pretty much every bit of existing code out there.

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

2010-12-07 Thread Shantanu Kumar


On Dec 7, 12:00 pm, Baishampayan Ghose  wrote:
> Hello,
>
> http://www.theregister.co.uk/2010/12/07/apache_google_vote_no_oracle_...http://news.ycombinator.com/item?id=1977720
>
> Does this mean anything for Clojure (on the JVM)?

As an interesting aside, here is the details on JCP votes:
http://www.jroller.com/scolebourne/entry/java_se_7_8_passed

Regards,
Shantanu

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

2010-12-07 Thread James Reeves
On 7 December 2010 09:22, javajosh  wrote:
> Anyway, I'm aware that open-parens is the signal to Invoke or Call
> something in Clojure - and therefore anything after the parens is
> Callable. It is the incredible diversity of 'Things I Can Invoke' that
> makes the parens difficult to a newb. (Although, I have to say,
> enumerating the possibilities is helping me immensely.)

It's probably more accurate to say that parentheses denote a list. In
a Lisp, it's important to grasp that executable code is represented by
a data structure.

To get the list to actually do something, the compiler must evaluate
it. The way it evaluates it depends on the type of its first element.
Broadly speaking, there are functions - which resolve at runtime - and
macros - which resolve at compile time.

Everything else is best thought of as syntax sugar. e.g. '(foo) is the
same as (quote foo).

- James

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

2010-12-07 Thread lprefontaine
I would not be surprised if some regulatory agency (UE) puts it's nose in
this if it has real impacts. Especially if Oracle does not abide by previous 
agreements with the Open Source community.

If a regulator sanctions Oracle, others will follow most likely.

If Oracle wants to be the next Microsoft, I think regulatory agencies are
now well aware of the tactics, after all they went through the Microsoft
"experiment" a few years ago. We can only hope they act swiftly.

Anyway, we can get OpenJdk a lift in the short term at least to run the current
stuff properly.

Luc P.

Shantanu Kumar  wrote ..
> 
> 
> On Dec 7, 12:00 pm, Baishampayan Ghose  wrote:
> > Hello,
> >
> >
http://www.theregister.co.uk/2010/12/07/apache_google_vote_no_oracle_...http://news.ycombinator.com/item?id=1977720
> >
> > Does this mean anything for Clojure (on the JVM)?
> 
> As an interesting aside, here is the details on JCP votes:
> http://www.jroller.com/scolebourne/entry/java_se_7_8_passed
> 
> Regards,
> Shantanu
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first
> post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
Luc P.


The rabid Muppet

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

2010-12-07 Thread Mikhail Kryshen
I don't think it will affect Clojure and OpenJDK communities much.

Apache always wanted to have a certified Java implementation under
permissive license. They probably get sponsor money for not using
copyleft licenses like GPL [1].

Also, I recommend the recent talk by James Gosling on Apple, Apache,
Google, Oracle and the Future of Java:
http://www.youtube.com/watch?v=9ei-rbULWoA

[1] 
http://itmanagement.earthweb.com/osrc/article.php/3762786/Bruce-Perens-Microsoft-and-Apache---Whats-the-Angle.htm

--
Mikhail

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

2010-12-07 Thread Daniel Janus
While on the topic, I'd like to raise a naming issue.

The 'mapmap' function seems to be a recurring theme (see, e.g.,
http://tech.puredanger.com/2010/09/24/meet-my-little-friend-mapmap/)
and many Clojure projects include one -- Incanter comes to mind. My
project used to, too. But we found out that the name "mapmap" has its
deficiencies.

First, it conflates the two senses of the word "map" (1. noun -- an
object implementing IPersistentMap; 2. verb -- to apply a function to
each element of a collection, producing a new one) by putting them
right next to each other. This impairs code readability: I once found
myself typing (mapmap #(map ... ) ...) -- it's unobvious at first
sight which "map" is used in which sense.

Second, all these implementations of mapmap floating around are
mutually incompatible, which partly stems from the fact that it is
unclear from the name what the argument of mapmap should be. Should it
be a value->value function? Or should it take two arguments, a key and
a value? Or should it take a [key value] pair?

Actually, each one of these flavors is useful on different occasions.
So to differentiate between them, we've now dropped mapmap and use
transform-v and transform-kv instead. Here they are, with docstrings:

(defn transform-kv
  "Transforms each entry in a map with f and returns the resulting
map.
f should take and return a key/value pair.  Similar to
clojure.contrib.generic.functor/fmap, but can take keys into account.
Works on any seq of pairs (not necessarily maps), always returning
maps."
  [f x]
  (into {} (map (fn [[k v]] (f k v)) x)))

(defn transform-v
  "Like transform-kv, but takes a value->value function, leaving keys
intact."
  [f x]
  (into {} (map (fn [[k v]] [k (f v)]) x)))

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

2010-12-07 Thread Tobias Raeder
Just checking performance versus the version i have been using i
noticed quite a difference

For 10 runs over a small 10 key/value map
(defn fmap [keyf valf m]
  (into {}
(for [[k v] m]
  [(keyf k) (valf v)])))
550ms

(defn fmap2 [keyf valf m]
  (-> (fn [inputmap [k v]]
  (assoc inputmap (name k) (inc v)))
(reduce {} inputmap)))
250ms

On Dec 7, 7:50 am, Alex Baranosky 
wrote:
> Ahh apply does it again!  I saw how the code be simplified, but just tonight
> learned how apply can be used in situations like this.

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

2010-12-07 Thread Anclj
Thanks a lot for all the answers :)

I've been busy trying to understand all the scripts that you posted.
The code works but I also wanted to know why.
I'm new to Clojure and it's hard for me to understand "advanced code",
but looking through the docs and the api I'm learning a lot.

Cheers!

On 4 Des, 23:16, Tyler Perkins  wrote:
> Or, better yet,
>
>        (into {}
>              (->> (str "{" (slurp "data") "}")
>                   read-string
>                   (map (fn [[k v]] [(keyword (str k)) 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


Re: mapmap?

2010-12-07 Thread Ken Wesson
On Tue, Dec 7, 2010 at 3:31 AM, Tobias Raeder
 wrote:
> Just checking performance versus the version i have been using i
> noticed quite a difference
>
> For 10 runs over a small 10 key/value map
> (defn fmap [keyf valf m]
>  (into {}
>    (for [[k v] m]
>      [(keyf k) (valf v)])))
> 550ms
>
> (defn fmap2 [keyf valf m]
>  (-> (fn [inputmap [k v]]
>      (assoc inputmap (name k) (inc v)))
>    (reduce {} inputmap)))
> 250ms

Does the speed difference persist if you fix the bugs in the second version? :)

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

2010-12-07 Thread Sean Devlin
This is a solved problem.  The trick is to use a higher-higher order
function...

http://fulldisclojure.blogspot.com/2010/01/12-fn-proposal-same-multisame.html

On Dec 7, 7:38 am, Daniel Janus  wrote:
> While on the topic, I'd like to raise a naming issue.
>
> The 'mapmap' function seems to be a recurring theme (see, 
> e.g.,http://tech.puredanger.com/2010/09/24/meet-my-little-friend-mapmap/)
> and many Clojure projects include one -- Incanter comes to mind. My
> project used to, too. But we found out that the name "mapmap" has its
> deficiencies.
>
> First, it conflates the two senses of the word "map" (1. noun -- an
> object implementing IPersistentMap; 2. verb -- to apply a function to
> each element of a collection, producing a new one) by putting them
> right next to each other. This impairs code readability: I once found
> myself typing (mapmap #(map ... ) ...) -- it's unobvious at first
> sight which "map" is used in which sense.
>
> Second, all these implementations of mapmap floating around are
> mutually incompatible, which partly stems from the fact that it is
> unclear from the name what the argument of mapmap should be. Should it
> be a value->value function? Or should it take two arguments, a key and
> a value? Or should it take a [key value] pair?
>
> Actually, each one of these flavors is useful on different occasions.
> So to differentiate between them, we've now dropped mapmap and use
> transform-v and transform-kv instead. Here they are, with docstrings:
>
> (defn transform-kv
>   "Transforms each entry in a map with f and returns the resulting
> map.
> f should take and return a key/value pair.  Similar to
> clojure.contrib.generic.functor/fmap, but can take keys into account.
> Works on any seq of pairs (not necessarily maps), always returning
> maps."
>   [f x]
>   (into {} (map (fn [[k v]] (f k v)) x)))
>
> (defn transform-v
>   "Like transform-kv, but takes a value->value function, leaving keys
> intact."
>   [f x]
>   (into {} (map (fn [[k v]] [k (f v)]) x)))

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

2010-12-07 Thread pepijn (aka fliebel)
Thanks all.

How would I do this protocol extension thing? My guess is that I need
to define the IAtom protocol myself, and then do something like this?

(defprotocol IAtom
  (compare-and-set! [])
  ...)

(extend-type clojure.lang.Atom
  IAtom
  (compare-and-set! [])
  ...
  IDeref
  (deref []))

But will that pass a Atom type hint? I will play with it and see for
myself. Thanks.

On Dec 6, 7:08 pm, Alyssa Kwan  wrote:
> +1
>
> There is no STM integration with atoms.  That's not a concern.
>
> Just write your own Clojure core with your change.  I did for durable
> identities.  git://github.com/kwanalyssa/clojure.git shamelessPlug>
>
> Seriously though, just use protocols.
>
> Thanks,
> Alyssa
>
> On Dec 6, 5:24 am, Benjamin Teuber  wrote:
>
>
>
>
>
>
>
> > I guess it was Rich's intention to have swap! be used for real atoms
> > only so your code remains understandable - that's why it's called
> > swap! for atoms, alter for refs and alter-var-root for vars.
>
> > So why not define your own protocol for updating documents? If you
> > really want (usually bad idea, I guess) you could still extend atoms
> > or even refs to support this protocol, too.
>
> > Regards,
> > Benjamin
>
> > On 5 Dez., 23:29, Pepijn de Vos  wrote:
>
> > > tl;dr: Please add an interface to clojure.lang.Atom. kthxbye
>
> > > I had the brilliant idea of using CouchDB for something equally 
> > > brilliant, and if possible implement a Clojure view server. Turns out 
> > > Clutch fits the bill perfectly, except that I would like to use Aleph, 
> > > and Couch is using something called MVCC.
>
> > > I haven't looked into the libs to deep, but I know the REST API, and what 
> > > it does for updating is that you need to supply the current revision and 
> > > if it doesn't match (i.e. there has been another update), the update 
> > > fails. So then you need to get the new _rev and try again. Much the same 
> > > way compare-and-set! works.
>
> > > I thought it would be perfect to implement IAtom and IDeref to get the 
> > > latest value and to swap! documents in a spin loop with a 
> > > side-effect-free function, like atoms do.
>
> > > But it turns out there is no interface for Atom and it is marked final. 
> > > The same is true for Ref and Agent, but raek suggested this might be 
> > > because they are more complex and integrated with the STM.
>
> > > Is there a good reason why I'm not allowed to implement my own atom? If 
> > > not, can it be added? Thanks.
>
> > > Groeten,
> > > Pepijn de Vos
> > > --
> > > Sent from my iPod Shufflehttp://pepijndevos.nl-Hide quoted text -
>
> > - Show quoted text -

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

2010-12-07 Thread pepijn (aka fliebel)
If you use (empty m) rather than {} it will also work for other types.

On Dec 7, 5:45 am, Ken Wesson  wrote:
> This is also very easy to implement:
>
> (into {}
>   (for [[k v] the-map]
>     [k (f v)]))
>
> e.g.
>
> user=> (into {}
>   (for [[k v] {:a 3 :b 7}]
>     [k (inc v)]))
> {:a 4, :b 8}
> user=>
>
> and to encapsulate as a function:
>
> (defn fmap [f m]
>   (into {}
>     (for [[k v] m]
>       [k (f 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


Re: Lots of newbie clojure questions

2010-12-07 Thread Meikel Brandmeyer
Hi,

Am 07.12.2010 um 08:58 schrieb Ken Wesson:

> The ns macro is particularly
> guilty of this. I say guilty because I think it's bad design, which I
> guess may have been grandfathered in before the standard was settled
> on to use [] around non-executable lists of data such as binding
> lists. (In some cases the first element, e.g. when it's :use or
> :require, can be thought of as a pseudo-operator defined solely within
> the ns form. I don't have an objection in cases where the first
> element of the list can be thought of as a command or a call of some
> sort. But many of the nested inputs to e.g. :use have the stain.)

(ns some.name.space
  [:refer-clojure :exclude [filter]]
  [:use [clojure.set :only [difference]]]
  [:require [clojure.repl :as r]]
  [:import java.io.StringReader])

This works if it makes you feel better... One can the vectors of a embedded DSL 
where nowhere is written, that something has to be callable.

Sincerely
Meikel

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


Re: Lots of newbie clojure questions

2010-12-07 Thread Mike Meyer
On Tue, 7 Dec 2010 02:58:11 -0500
Ken Wesson  wrote:

> On Tue, Dec 7, 2010 at 2:15 AM, javajosh  wrote:
> > Mike and I have had a nice off-line conversation where we enumerated
> > the possible things that can come after open-parens. I listed 7, he
> > added 3:

That wasn't meant to be offline, but it's probably not worth
resending. However...

> >> 1. A value (if the paren has a tick '(  )
> >> 2. A function.
> >> 3. A map - which is a psuedo function that takes a key as an arg.
> >> 4. A keyword - which is a psuedo function that takes a map as an arg.
> >> 5. A macro. This is the normal case, I think. Looking through the mailing
> >> list, it appears that most clojure programming questions revolve around
> >> which one of the hundreds of macros to invoke and in which order!
> >> 6. The Java form: (MyClass. )
> >> 7. The java method form (.doSomething)
> > 8. A function returning a function to invoke - ((find-my-function) )
> > 9. A loop - (recur )
> > 10. The anonymous function macro: #( )
> >
> > So, at least I know why I feel uneasy about open paren! It's super
> > overloaded.
> 
> Not really. (...) is a non-atomic s-expression. If it's evaluated
> unquoted, the first nested s-expression is evaluated and if it's not
> callable an exception is thrown. Macros, special forms (which are sort
> of like system-internal macros and are used to build all the other
> macros, and functions), Java constructors, Java methods, and functions
> are callable (and maps and keywords -- also vectors -- act as
> functions for this purpose).
> 
> The only real overloading always involves macros:
> 
> #() evaluates to a function and doesn't run its insides right away.
> Then again so does (defn foo [x] (inc x)) -- the (inc x) is run when
> foo is called, calling inc, but not when the (defn ...) is called.
> Macros can delay evaluation of their contents, and #() is a reader
> macro.
> 
> '(x y z) is another reader macro and expands to (quote (x y z)).

This was pretty much what I tried to explain as well, even including
the comment that I almost never used '( ) in clojure because vectors
worked as well.

> > Mike also points out that things that aren't functions (not used in
> > that context) can't be aliased with def or use.
> 
> Really?
> 
> user=> (def a 3)
> #'user/a
> user=> (def b a)
> #'user/b
> user=> b
> 3

This one I flubbed, because my vocabulary failed me. There are three
classes of values that can work when they show up in the first
position in an executable expression:

1) Functions, which can also be passed to higher order functions.
2) Macros, which can't, but can be aliased by def or use.
3) Java interop things (#6 6 & 7 on his list), which can't be aliased
   by def or use.

http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

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

2010-12-07 Thread Alan
I see you have defined a print-and-return macro; you might prefer my
and-print:

(defmacro and-print
  "A useful debugging tool when you can't figure out what's going on:
  wrap a form with and-print, and the form will be printed alongside
  its result. The result will still be passed along."
  [val]
  `(let [x# ~val]
 (println '~val "is" x#)
 x#))

I'm not sure what you're using the flag argument for; if it's to keep
track of what prints belong to what statements then my automatic
printing of the input form might be useful for you.

I'd pull the (repeat blah blah blah) stuff in with-separator out into
an optional argument, so that (a) you only have to write it once, and
(b) you can use a different separator easily.

I find the map in local-bindings pretty hard to read - what on earth
is `'~x# for? Without trying to understand what you're doing, it seems
like you could gain readability by replacing (list 'println [`'~x#
x#]) with `(println ['~x# x#])

On Nov 28, 12:32 am, Sunil S Nandihalli 
wrote:
> Hi Robert,
>  What I had posted before was half-baked buggy code .. the following gist
> has a few more helper debug macroshttps://gist.github.com/718725
>
> This code was written when I was trying to
> learn writing macros .. so any criticism is very welcome.
> Thanks
> Sunil.
>
> On Sat, Nov 27, 2010 at 11:06 PM, Robert McIntyre  wrote:
> > cool!  Although I think with-seperator should be spelled "with-separator"
>
> > --Robert McIntyre
>
> > On Thu, Nov 25, 2010 at 9:13 AM, Sunil S Nandihalli
> >  wrote:
> > > I just tried to re-write with-seperator without using the symbol-macros
> > from
> > > macro-utils and it seems to work fine ..
>
> > > On Thu, Nov 25, 2010 at 1:27 PM, Sunil S Nandihalli
> > >  wrote:
>
> > >> Hello everybody,
> > >>  I was trying to learn to write clojure macros and the code is posted
> > here
> > >> in the following link
> > >>https://gist.github.com/715047
> > >> There are basically three macros
> > >> 1. with-seperator - a zero argument macro and is supposed to just draw a
> > >> line to indicate beginning and ending of the execution of the body.
> > >> 2. display-local-bindings - a function to print the local bindings in
> > the
> > >> lexical scope where the macro is called
> > >> 3. letd - a helper macro to print the values of all the bindings
> >  followed
> > >> by printing of the local bindings using display-local-bindings
> > >> The letd macro as posted works as expected but without the seperation
> > line
> > >> .  It is supposed to print the seperation line when I uncomment line 14
> > and
> > >> comment line 15 but some how this is causing the &env variable
> > automatically
> > >> passed with every macro to be nil display-local-binding .. but the I
> > feel it
> > >> is not the case .. can somebody help me understand this. This was an
> > >> exercise to learn macro writing than to writing a letd debugging helper
> > >> function..
> > >> Thanks,
> > >> Sunil.
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Clojure" group.
> > > To post to this group, send email to clojure@googlegroups.com
> > > Note that posts from new members are moderated - please be patient with
> > your
> > > first post.
> > > To unsubscribe from 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: Bug in clojure.contrib.core/-?> (improper quoting?)

2010-12-07 Thread Jason Wolfe


On Dec 6, 8:41 pm, Ken Wesson  wrote:
> On Mon, Dec 6, 2010 at 10:27 PM, Jason Wolfe  wrote:
> > This happens in both Clojure 1.2 and 1.3-latest:
>
> > user=> (require 'clojure.contrib.core)
> > nil
> > user=> (clojure.contrib.core/-?> 1 inc)
> > 2
> > user=> (clojure.contrib.core/-?> 1 inc inc)
> > CompilerException java.lang.Exception: Unable to resolve symbol: -?>
> > in this context, compiling:(NO_SOURCE_PATH:3)
>
> Sure looks like a quoting problem:
>
> user=> (require 'clojure.contrib.core)
> nil
> user=> (clojure.contrib.core/-?> 1 inc)
> 2
> user=> (clojure.contrib.core/-?> 1 inc inc)
> #
> in this context (NO_SOURCE_FILE:214)>
> user=> (use 'clojure.contrib.core)
> nil
> user=> (clojure.contrib.core/-?> 1 inc)
> 2
> user=> (clojure.contrib.core/-?> 1 inc inc)
> 3
> user=>
>
> It's obviously calling -?> recursively when there's additional args,
> and when it does, it's obviously looking for -?> in the current ns
> instead of for clojure.contrib.core/-?>. Which wouldn't happen with
> `(-?> ~foo ~bar). Someone used something like (list '-?> foo bar)
> instead, or something.
>
> Someone ought to open an Assembla ticket for this.

http://dev.clojure.org/jira/browse/CONTRIB-102

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

2010-12-07 Thread javajosh


On Dec 7, 5:50 am, Sean Devlin  wrote:
> This is a solved problem.  The trick is to use a higher-higher order
> function...
>
> http://fulldisclojure.blogspot.com/2010/01/12-fn-proposal-same-multis...

Why not call it "unseq"?

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

2010-12-07 Thread Laurent PETIT
Will provide a patch soon,

thanks for the bug report

2010/12/7 Jason Wolfe 

>
>
> On Dec 6, 8:41 pm, Ken Wesson  wrote:
> > On Mon, Dec 6, 2010 at 10:27 PM, Jason Wolfe 
> wrote:
> > > This happens in both Clojure 1.2 and 1.3-latest:
> >
> > > user=> (require 'clojure.contrib.core)
> > > nil
> > > user=> (clojure.contrib.core/-?> 1 inc)
> > > 2
> > > user=> (clojure.contrib.core/-?> 1 inc inc)
> > > CompilerException java.lang.Exception: Unable to resolve symbol: -?>
> > > in this context, compiling:(NO_SOURCE_PATH:3)
> >
> > Sure looks like a quoting problem:
> >
> > user=> (require 'clojure.contrib.core)
> > nil
> > user=> (clojure.contrib.core/-?> 1 inc)
> > 2
> > user=> (clojure.contrib.core/-?> 1 inc inc)
> > #
> > in this context (NO_SOURCE_FILE:214)>
> > user=> (use 'clojure.contrib.core)
> > nil
> > user=> (clojure.contrib.core/-?> 1 inc)
> > 2
> > user=> (clojure.contrib.core/-?> 1 inc inc)
> > 3
> > user=>
> >
> > It's obviously calling -?> recursively when there's additional args,
> > and when it does, it's obviously looking for -?> in the current ns
> > instead of for clojure.contrib.core/-?>. Which wouldn't happen with
> > `(-?> ~foo ~bar). Someone used something like (list '-?> foo bar)
> > instead, or something.
> >
> > Someone ought to open an Assembla ticket for this.
>
> http://dev.clojure.org/jira/browse/CONTRIB-102
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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

advantage of clojure over non lisp languages

2010-12-07 Thread SpiderPig
Hi,
I was wondering if there are any good examples that show what
advantages clojure/lisp has over most other programming languages.
I mean a piece of code that couldn't be easily translated into e.g.
scala or java. A program that would take much longer to develop in
other languages due to the unique properties of lisp. Is there such
code out there? Basically all the clojure code I have seen so far
could be translated to scala without any major problems and would take
about the same amount of time to write. I'm not talking about
differences in the API. That could easily be fixed.
In other words are there good examples that show that writing software
in a lisp language is a lot faster then writing the same program in a
language like scala.

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

2010-12-07 Thread Alex Baranosky
There are plenty of things that can be done with macros, that cannot be done
in Scala or Java.  I can't find an example off hand, but the books: The Joy
of Clojure, Clojure in Action, and Programming Clojure have good examples
throughout.

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

2010-12-07 Thread Alan
I remember I was very excited about Java 1.5 when it came out, because
of all the syntactic sugar it provided. I was tired of typing

for (int i = 0; i < foo.length; i++) {
Bar b = foo[i];
// do stuff with b
}

1.5 introduced the foreach loop syntax, so that I could instead write

for (Bar b : foo)
  // do stuff with b

At the time this was great, but on reflection it took a very long time
for such a simple source-level improvement to be added to java.
Wouldn't it be nice if I could write my own version of this instead of
waiting for Sun to do it? In a lisp, this is trivial. Let's imagine
that clojure had an ugly java-looking (for) syntax, instead of the
lovely list-comprehension style it has now. Maybe it looks like this:

(for i 0 (< i (.length foo)) (inc i)
  (let [bar (aget foo i)]
(comment do stuff with bar)))

And I've noticed I write the above code a lot and would like it to be
shorter. It's not hard to write a foreach macro myself:

(defmacro foreach [[name array] & body]
  `(for i# 0 (< i# (.length ~array)) (inc i#)
 (let [~name (aget ~array i#)]
   (do ~...@body

(foreach [bar foo]
  (comment do stuff with bar))

I don't know anything about Scala, but try doing this in java and
you'll see why lisps are so powerful.

On Dec 7, 3:10 pm, SpiderPig  wrote:
> Hi,
> I was wondering if there are any good examples that show what
> advantages clojure/lisp has over most other programming languages.
> I mean a piece of code that couldn't be easily translated into e.g.
> scala or java. A program that would take much longer to develop in
> other languages due to the unique properties of lisp. Is there such
> code out there? Basically all the clojure code I have seen so far
> could be translated to scala without any major problems and would take
> about the same amount of time to write. I'm not talking about
> differences in the API. That could easily be fixed.
> In other words are there good examples that show that writing software
> in a lisp language is a lot faster then writing the same program in a
> language like scala.

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

2010-12-07 Thread Jason Wolfe
Great, thanks!

-Jason

On Dec 7, 2:52 pm, Laurent PETIT  wrote:
> Will provide a patch soon,
>
> thanks for the bug report
>
> 2010/12/7 Jason Wolfe 
>
>
>
> > On Dec 6, 8:41 pm, Ken Wesson  wrote:
> > > On Mon, Dec 6, 2010 at 10:27 PM, Jason Wolfe 
> > wrote:
> > > > This happens in both Clojure 1.2 and 1.3-latest:
>
> > > > user=> (require 'clojure.contrib.core)
> > > > nil
> > > > user=> (clojure.contrib.core/-?> 1 inc)
> > > > 2
> > > > user=> (clojure.contrib.core/-?> 1 inc inc)
> > > > CompilerException java.lang.Exception: Unable to resolve symbol: -?>
> > > > in this context, compiling:(NO_SOURCE_PATH:3)
>
> > > Sure looks like a quoting problem:
>
> > > user=> (require 'clojure.contrib.core)
> > > nil
> > > user=> (clojure.contrib.core/-?> 1 inc)
> > > 2
> > > user=> (clojure.contrib.core/-?> 1 inc inc)
> > > #
> > > in this context (NO_SOURCE_FILE:214)>
> > > user=> (use 'clojure.contrib.core)
> > > nil
> > > user=> (clojure.contrib.core/-?> 1 inc)
> > > 2
> > > user=> (clojure.contrib.core/-?> 1 inc inc)
> > > 3
> > > user=>
>
> > > It's obviously calling -?> recursively when there's additional args,
> > > and when it does, it's obviously looking for -?> in the current ns
> > > instead of for clojure.contrib.core/-?>. Which wouldn't happen with
> > > `(-?> ~foo ~bar). Someone used something like (list '-?> foo bar)
> > > instead, or something.
>
> > > Someone ought to open an Assembla ticket for this.
>
> >http://dev.clojure.org/jira/browse/CONTRIB-102
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.> To post to this group, send email 
> > tocloj...@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from 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


Giving a 15 minute Clojure lightning talk. Any ideas?

2010-12-07 Thread Alex Baranosky
Hi guys,

I'm going to be doing a 15 minute Clojure lighting talk in a few weeks for
work.  I've been having trouble finding a nice topic for 15 minutes, mostly
because it is too short of a time to cover a wide array of... anything.

The audience does Java / Ruby so I am concerned about the syntax slowing
down the presentation, because they'll need some time to digest the slides,
I'm sure.

I'm thinking that I can probably only cover one facet of what makes Clojure
cool.

Any ideas how you all might approach tis 15 minute presentation?

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

Re: ANN: Dr. Evil - the evil web debugger

2010-12-07 Thread Miki
> > Comments/criticism/improvements welcomed.
>
> "EVIL" doesn't have to be a macro. You could just make it a function:
>
> (defn EVIL [path]
>   (GET path [expr]
>     (if (nil? expr)
>       (html path)
>       (json-str (eval-expr expr

Right you are kind Sir.
Pushed to clojars.

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

2010-12-07 Thread Jay Fields
Getting started with clojure via clojure.test would probably be practical for 
getting people to try it out. Especially ruby people (who generally put more 
than average emphasis on testing).

Sent from my iPhone

On Dec 7, 2010, at 7:56 PM, Alex Baranosky  
wrote:

> Hi guys,
> 
> I'm going to be doing a 15 minute Clojure lighting talk in a few weeks for 
> work.  I've been having trouble finding a nice topic for 15 minutes, mostly 
> because it is too short of a time to cover a wide array of... anything.
> 
> The audience does Java / Ruby so I am concerned about the syntax slowing down 
> the presentation, because they'll need some time to digest the slides, I'm 
> sure.
> 
> I'm thinking that I can probably only cover one facet of what makes Clojure 
> cool.
> 
> Any ideas how you all might approach tis 15 minute presentation?
> 
> Best, 
> 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 post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Giving a 15 minute Clojure lightning talk. Any ideas?

2010-12-07 Thread javajosh
The three things that I've seen that impressed me (and I'm a newb)
were:

1. Swing GUI construction. Clojure's psuedo "with" syntax makes it
very elegant.
2. Multi-threaded ant simulation. Although, I might try to do
something simpler.
3. Numerical calculations. The fact that Clojure uses arbitrary
precision and Ratios is very nice.
4. (Bonus) An Incanter demo.

On Dec 7, 4:56 pm, Alex Baranosky 
wrote:
> Hi guys,
>
> I'm going to be doing a 15 minute Clojure lighting talk in a few weeks for
> work.  I've been having trouble finding a nice topic for 15 minutes, mostly
> because it is too short of a time to cover a wide array of... anything.
>
> The audience does Java / Ruby so I am concerned about the syntax slowing
> down the presentation, because they'll need some time to digest the slides,
> I'm sure.
>
> I'm thinking that I can probably only cover one facet of what makes Clojure
> cool.
>
> Any ideas how you all might approach tis 15 minute presentation?
>
> Best,
> 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


Re: advantage of clojure over non lisp languages

2010-12-07 Thread Ken Wesson
On Tue, Dec 7, 2010 at 6:57 PM, Alan  wrote:
> I remember I was very excited about Java 1.5 when it came out, because
> of all the syntactic sugar it provided. I was tired of typing
>
> for (int i = 0; i < foo.length; i++) {
>    Bar b = foo[i];
>    // do stuff with b
> }
>
> 1.5 introduced the foreach loop syntax, so that I could instead write
>
> for (Bar b : foo)
>  // do stuff with b
>
> At the time this was great, but on reflection it took a very long time
> for such a simple source-level improvement to be added to java.
> Wouldn't it be nice if I could write my own version of this instead of
> waiting for Sun to do it? In a lisp, this is trivial. Let's imagine
> that clojure had an ugly java-looking (for) syntax, instead of the
> lovely list-comprehension style it has now. Maybe it looks like this:
>
> (for i 0 (< i (.length foo)) (inc i)
>  (let [bar (aget foo i)]
>    (comment do stuff with bar)))
>
> And I've noticed I write the above code a lot and would like it to be
> shorter. It's not hard to write a foreach macro myself:
>
> (defmacro foreach [[name array] & body]
>  `(for i# 0 (< i# (.length ~array)) (inc i#)
>     (let [~name (aget ~array i#)]
>       (do ~...@body
>
> (foreach [bar foo]
>  (comment do stuff with bar))
>
> I don't know anything about Scala, but try doing this in java and
> you'll see why lisps are so powerful.

Good example; though your foreach macro evaluates array twice. I'd go with:

(defmacro foreach [[name array] & body]
  `(let [a# ~array]
 (for i# 0 (< i# (.length a#)) (inc i#)
       (let [~name (aget a# i#)]
         (do ~...@body)

in case the expression for the array at some call site is big and
expensive to evaluate, like (generate-prime-sieve 1e8) or something,
or, worse, has side-effects. :)

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

2010-12-07 Thread Ken Wesson
On Tue, Dec 7, 2010 at 3:05 PM, Jason Wolfe  wrote:
> http://dev.clojure.org/jira/browse/CONTRIB-102

Link doesn't work. It goes to a login prompt and not to ... well,
whatever you intended it to go to.

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

2010-12-07 Thread Ken Wesson
On Tue, Dec 7, 2010 at 12:28 PM, Mike Meyer
 wrote:
> On Tue, 7 Dec 2010 02:58:11 -0500
> Ken Wesson  wrote:
>> On Tue, Dec 7, 2010 at 2:15 AM, javajosh  wrote:
>> > Mike also points out that things that aren't functions (not used in
>> > that context) can't be aliased with def or use.
>>
>> Really?
>>
>> user=> (def a 3)
>> #'user/a
>> user=> (def b a)
>> #'user/b
>> user=> b
>> 3
>
> This one I flubbed, because my vocabulary failed me. There are three
> classes of values that can work when they show up in the first
> position in an executable expression:
>
> 1) Functions, which can also be passed to higher order functions.
> 2) Macros, which can't, but can be aliased by def or use.
> 3) Java interop things (#6 6 & 7 on his list), which can't be aliased
>   by def or use.

Ah, it's inability to alias Java methods and classnames that bugs you.
Actually, that bugs me too and I proposed alterations to the ns macro
recently to allow that (with an eye to also making it easier to write
code that works on both clojure-CLR and clojure-JVM, as there are some
cases where C# and Java have nearly identical-semantics classes with
different names).

But yes, I think it would be nice to be able to alias at least
classnames using at least the import/:import forms. (I don't object if
the aliasing isn't dynamic; it isn't be for macros either. That is, it
would be ok if you couldn't (let [x Integer] (x. 278)) or anything
like that. Some cases where you'd like to pass a class as a parameter
can be handled with multimethods or other means, for the most part; or
passing the java.lang.Class instance itself around and using
reflection.)

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

2010-12-07 Thread Alan
Link works fine. You have to be logged in (this is a point of
contention, I think).

On Dec 7, 6:58 pm, Ken Wesson  wrote:
> On Tue, Dec 7, 2010 at 3:05 PM, Jason Wolfe  wrote:
> >http://dev.clojure.org/jira/browse/CONTRIB-102
>
> Link doesn't work. It goes to a login prompt and not to ... well,
> whatever you intended it to go to.

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

2010-12-07 Thread Jeff Heon
Hi Alex,

The first part of these slides covers Ruby / Clojure syntax and might
be useful:
http://www.slideshare.net/jfheon/clojure-forrubyists

Break a leg ;)

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

2010-12-07 Thread Ken Wesson
On Tue, Dec 7, 2010 at 10:53 PM, Alan  wrote:
> Link works fine.

Does it?

> You have to be logged in

Then, in my opinion, it does NOT work fine. I should be able to VIEW
anything non-confidential without logging in, though I expect to
possibly have to login to POST stuff. (And if something IS
confidential, but is also intended for me, then I should actually have
whatever login is needed to view it. Say, the login for my gmail
account.)

Furthermore, the link was posted as a response to one of my posts
here. This implies that the link is meant for me, and that I should be
able to read whatever's there (the actual meat of the response to my
post, presumably) with my existing access credentials.

Posting a reply to someone that consists solely of a link that, when
accessed by that someone, throws up an access denied message in their
face, is an equivalent act to sending them an encrypted reply for
which they don't have the key, or handing them a locked briefcase for
which they don't know the combination. So, kind of silly, and
ineffective at actually communicating with them since they can't read
your reply.

Hence my assumption that a mistake of some sort had been made. It
seems unlikely that someone would intentionally send me a reply I
can't actually read, so I figured they did not intend that effect, but
technical problems of some kind occurred or they simply misspelled the
URL.

Now I'm simply confused. What, exactly, was intended? And if there's
nothing actually private-to-me about the attempted communication and
someone here is prviy to its contents, perhaps they could simply
repost those contents here?

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


Re: Bug in clojure.contrib.core/-?> (improper quoting?)

2010-12-07 Thread Stuart Halloway
The permissions were not set correctly for anonymous read access. I have 
changed them, you should be able to get there now: 
http://dev.clojure.org/jira/browse/CONTRIB-102.

Effective communication tip: Please preserve links in responses, so that when 
somebody is trying to track down issues they don't have to work back through 
the thread to find links.

Stu

> On Tue, Dec 7, 2010 at 10:53 PM, Alan  wrote:
>> Link works fine.
> 
> Does it?
> 
>> You have to be logged in
> 
> Then, in my opinion, it does NOT work fine. I should be able to VIEW
> anything non-confidential without logging in, though I expect to
> possibly have to login to POST stuff. (And if something IS
> confidential, but is also intended for me, then I should actually have
> whatever login is needed to view it. Say, the login for my gmail
> account.)
> 
> Furthermore, the link was posted as a response to one of my posts
> here. This implies that the link is meant for me, and that I should be
> able to read whatever's there (the actual meat of the response to my
> post, presumably) with my existing access credentials.
> 
> Posting a reply to someone that consists solely of a link that, when
> accessed by that someone, throws up an access denied message in their
> face, is an equivalent act to sending them an encrypted reply for
> which they don't have the key, or handing them a locked briefcase for
> which they don't know the combination. So, kind of silly, and
> ineffective at actually communicating with them since they can't read
> your reply.
> 
> Hence my assumption that a mistake of some sort had been made. It
> seems unlikely that someone would intentionally send me a reply I
> can't actually read, so I figured they did not intend that effect, but
> technical problems of some kind occurred or they simply misspelled the
> URL.
> 
> Now I'm simply confused. What, exactly, was intended? And if there's
> nothing actually private-to-me about the attempted communication and
> someone here is prviy to its contents, perhaps they could simply
> repost those contents here?
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

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

2010-12-07 Thread Tim Daly

 Ask Rich if you can use his Ants example.
His comment about running it on the Azul(?) machine
is interesting.

On 12/7/2010 7:56 PM, Alex Baranosky wrote:

Hi guys,

I'm going to be doing a 15 minute Clojure lighting talk in a few weeks 
for work.  I've been having trouble finding a nice topic for 15 
minutes, mostly because it is too short of a time to cover a wide 
array of... anything.


The audience does Java / Ruby so I am concerned about the syntax 
slowing down the presentation, because they'll need some time to 
digest the slides, I'm sure.


I'm thinking that I can probably only cover one facet of what makes 
Clojure cool.


Any ideas how you all might approach tis 15 minute presentation?

Best,
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 post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Bug in clojure.contrib.core/-?> (improper quoting?)

2010-12-07 Thread Ken Wesson
On Wed, Dec 8, 2010 at 12:02 AM, Stuart Halloway
 wrote:
> The permissions were not set correctly for anonymous read access. I have 
> changed them, you should be able to get there now: 
> http://dev.clojure.org/jira/browse/CONTRIB-102.

Ah, so there was indeed a technical snafu. Glad that's cleared up.

> Effective communication tip: Please preserve links in responses, so that when 
> somebody is trying to track down issues they don't have to work back through 
> the thread to find links.

Sorry. I'm using gmail's web interface, which gives a very good
presentation of discussion threads and read/unread. (My first post
excepted; I was replying to a post that was posted before I
subscribed, so it wasn't mailed to me, and so I used the icky Google
Groups interface to reply to that one. In particular, the link's just
there a click away from any post to this thread -- at least, it is for
me. I guess if you're using other mail software (or deleting old
messages once read) you'd have more trouble finding 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


Re: Bug in clojure.contrib.core/-?> (improper quoting?)

2010-12-07 Thread Jason Wolfe
> Posting a reply to someone that consists solely of a link that, when
> accessed by that someone, throws up an access denied message in their
> face, is an equivalent act to sending them an encrypted reply for
> which they don't have the key, or handing them a locked briefcase for
> which they don't know the combination. So, kind of silly, and
> ineffective at actually communicating with them since they can't read
> your reply.
>
> Hence my assumption that a mistake of some sort had been made. It
> seems unlikely that someone would intentionally send me a reply I
> can't actually read, so I figured they did not intend that effect, but
> technical problems of some kind occurred or they simply misspelled the
> URL.
>
> Now I'm simply confused. What, exactly, was intended? And if there's
> nothing actually private-to-me about the attempted communication and
> someone here is prviy to its contents, perhaps they could simply
> repost those contents here?

I apologize for my terseness;  thanks for your contribution to the
discussion.   I was in a rush, and assumed the link was world-
viewable; it certainly didn't look protected, and I knew that issues
for Clojure (but I guess not C-C) were publicly browsable without an
account from prior experience.  Looks like Stuart has fixed this wart
(thanks!).

-Jason


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

2010-12-07 Thread Ken Wesson
On Wed, Dec 8, 2010 at 1:08 AM, Jason Wolfe  wrote:
>> Posting a reply to someone that consists solely of a link that, when
>> accessed by that someone, throws up an access denied message in their
>> face, is an equivalent act to sending them an encrypted reply for
>> which they don't have the key, or handing them a locked briefcase for
>> which they don't know the combination. So, kind of silly, and
>> ineffective at actually communicating with them since they can't read
>> your reply.
>>
>> Hence my assumption that a mistake of some sort had been made. It
>> seems unlikely that someone would intentionally send me a reply I
>> can't actually read, so I figured they did not intend that effect, but
>> technical problems of some kind occurred or they simply misspelled the
>> URL.
>>
>> Now I'm simply confused. What, exactly, was intended? And if there's
>> nothing actually private-to-me about the attempted communication and
>> someone here is prviy to its contents, perhaps they could simply
>> repost those contents here?
>
> I apologize for my terseness;  thanks for your contribution to the
> discussion.   I was in a rush, and assumed the link was world-
> viewable; it certainly didn't look protected, and I knew that issues
> for Clojure (but I guess not C-C) were publicly browsable without an
> account from prior experience.  Looks like Stuart has fixed this wart
> (thanks!).

That's OK. Thanks.

I can confirm that the link works now.

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