Re: Why I get IllegalArgumentException: No matching ctor found

2012-12-16 Thread jarppe
I think you are right, when ever the function returns a closure I get the 
exception. I think it should work with closures anyhow.

-- 
-jarppe


On Sunday, December 16, 2012 7:49:30 PM UTC+2, juan.facorro wrote:
>
> I think it has to do with the closure in the *fn *used when generating 
> the form in the macro. 
>
>>
>>

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

2012-12-16 Thread Simon Holgate
London Clojurians has a periodic update of who's using Clojure in 
production.

The latest thread is here:
https://groups.google.com/forum/?fromgroups#!topic/london-clojurians/ES8AuxXI0Nk

There are a few here that haven't been mentioned elsewhere such as 
Likely.co, MastodonC, uSwitch, Trampoline, UBS, Deustche Bank. I think I 
covered them all :)

Simon

On Tuesday, 19 April 2011 15:38:14 UTC+1, Damien wrote:
>
> Hi Everyone,
>
> I'm on a mission: introducing Clojure in my company, which is a big 
> consulting company like many others.
>
> I started talking about Clojure to my manager yesterday.
> I was prepared to talk about all the technical benefits and he was 
> interested.
> I still have a long way to go but I think that was a good start.
>
> However I need to figure out how to answer to one of his questions: who is 
> using Clojure?
>
> Obviously I know each of you is using Clojure, that makes almost 5,000 
> people.
> I know there is Relevance and Clojure/core.
> I read about BackType or FlightCaster using Clojure.
>
> But, let's face it, that doesn't give me a killer answer.
>
> What could help is a list of success stories, a bit like MongoDB published 
> here:
> http://www.mongodb.org/display/DOCS/Production+Deployments
>
> Is there a place where I could find this kind of information for Clojure?
>
> Thanks
>
> -- 
> Damien Lepage
> http://damienlepage.com
>
>

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

2012-12-16 Thread Ambrose Bonnaire-Sergeant
Symbols are functions. See
http://clojure.org/data_structures#Data%20Structures-Symbols

Thanks,
Ambrose

On Mon, Dec 17, 2012 at 12:12 PM, Paul Sholtz  wrote:

> I was messing around with the Clojure interpreter and typed this:
>
> user=> ('+ 3 4)
>
> The interpreter responded with "4".
>
> That's odd (but interesting)..
>
> Clearly if I had typed (+ 3 4), it would have responded with 7, and it I
> had typed '(3 4), it would have responded with a list (3 4), but why does
> this expression evaluate to "4"?
>
> Most other Lisps/Schemes I'm familiar with would throw an error at this
> point..
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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

Expression Evaluation

2012-12-16 Thread Paul Sholtz
I was messing around with the Clojure interpreter and typed this:

user=> ('+ 3 4)

The interpreter responded with "4".

That's odd (but interesting).. 

Clearly if I had typed (+ 3 4), it would have responded with 7, and it I 
had typed '(3 4), it would have responded with a list (3 4), but why does 
this expression evaluate to "4"? 

Most other Lisps/Schemes I'm familiar with would throw an error at this 
point.. 

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

[ANN] lein-cljsbuild 0.2.10

2012-12-16 Thread Evan Mezeske
Hello,

After a very long three weeks without a home internet connection, I've 
finally gotten around to releasing version 0.2.10 of lein-cljsbuild.  Thank 
you all for your patience, I know that there hasn't been a release in a 
while!

This release will default to using the upstream ClojureScript compiler 
version r1552.

As usual, please create issues on Github if you note any problems.

Release Notes: 
https://github.com/emezeske/lein-cljsbuild/blob/master/doc/RELEASE-NOTES.md
Repo: https://github.com/emezeske/lein-cljsbuild

Thanks,
-Evan

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

Re: Clojure syntax coloring for wordpress blogs

2012-12-16 Thread Nick Gonzalez
When I move it off of wordpress I will use highlight.js.  Unfortunately I'm 
using a free hosted wordpress.com site and can't install plugins.  So it 
looks like I'm out of luck for now.  If I end up keeping this blog up, I'll 
pay the couple of bucks and move it to a real host and setup the plugin you 
described.  Thanks.

On Saturday, December 15, 2012 6:03:09 PM UTC-5, Alexander Solovyov wrote:
>
> On Sat, Dec 15, 2012 at 11:02 PM, Nick Gonzalez 
> 
> > wrote:
>
>> Does anyone have a good method for syntax coloring clojure code snippets 
>> for a wordpress blog?  I've recently started my new blog, and I'm posting 
>> clojure snippets, and would like for them to be syntax highlighted and 
>> indented properly.
>
>
> Highlight.js maybe? 
>
> http://softwaremaniacs.org/soft/highlight/en/
>
> There is a plugin for wordpress: 
>
> http://wordpress.org/extend/plugins/wp-highlightjs/
>
> -- 
> Alexander
>  

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

2012-12-16 Thread Leif
Hi, Ray.

When you are doing things that have a relational algebra feel to them 
(joins, etc.), you might want to consider the fns in the clojure.set 
namespace.  E.g.:

;; convert vectors of records to sets, then:
> (clojure.set/join 
  (clojure.set/rename items {:id :iid :name :iname}) ; to prevent 
overwriting keys in the result
  products 
  {:product :id}) ; 'where items.product = products.id'
=>
#{
  {:prices #user.Price{:price 45.99, :tax-rate 21, :currency "EURO"}, 
   :description "Slim Fit White Vest Shirt", 
   :name "Shirt", :id "P-678", 
   :iid 3, 
   :product "P-678", 
   :quantity 1, 
   :purchased true, 
   :iname "Shirt"}
  ...}

It might look even nicer if you just used regular maps with namespaced keys 
instead of records:
(clojure.set/join items products {:item/product :product/id})

Hope that helps,
Leif

On Saturday, December 15, 2012 11:25:59 AM UTC-5, mond wrote:
>
> I have defined these types of records for modelling a simple shopping cart:
>
> ; An item in the cart
> (defrecord Item [id name product quantity purchased])
>
> ; The product that relates to the item in the cart
> (defrecord Product [id name description prices])
>
> ; A price definition
> (defrecord Price [price tax-rate currency])
>
>
> ; Sample items
> (def items [
>  (->Item 1 "Brogues" "P-123" 1 true)
>  (->Item 2 "Underpants" "P-345" 1 false)
>  (->Item 3 "Shirt" "P-678" 1 true)
>  ])
>
> ; Sample products
> (def products [
> (->Product "P-123" "Brogues" "Men's Leather Slip on 
> Brogues" (->Price 93.00 21 "EURO"))
> (->Product "P-345" "Underpants" "CK Y Fronts" (->Price 
> 23.50 21 "EURO"))
> (->Product "P-678" "Shirt" "Slim Fit White Vest Shirt" 
> (->Price 45.99 21 "EURO"))
> (->Product "P-1231" "Table" "Coffee Table" (->Price 375 21 
> "EURO"))
> (->Product "P-3451" "Chairs" "Set of Four(4) chairs" 
> (->Price 200 21 "EURO"))
> (->Product "P-6781" "TableCloth" "Classic red and white 
> checks 2m x 2m" (->Price 17.99 21 "EURO"))
> ])
>
> My requirement is to combine data from the two collections such that I can 
> show the detailed product information for any item, for example:
>
>  (->Item 3 "Shirt" "Slim Fit White Vest Shirt" (->Price 45.99 
> 21 "EURO") 1 true)
>
> When I tried to use merge-with union I had an error which surprised me 
> since I thought records are also maps:
>
> user=> (merge-with union items products)
> ClassCastException user.Product cannot be cast to java.util.Map$Entry 
>  clojure.core/key (core.clj:1465)
>
> Although I will fight on, any tips from any of you that have done this 
> before would be greatly helped.
>
> Thanks
>
> ray
>

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

Re: Using functions from Java packages

2012-12-16 Thread Softaddicts
The problem if you dive into Java is that it may bring to your attention a 
myriad of details
that may not be worth the trouble of learning if you do not expect to
dive into Java and stay on the Clojure side of the fence.

No ready-fit light reading comes to my mind. Maybe a "learn java in 21 days" 
primer
might be just enough but you would still have to fill the gap from the
perspective of calling java libs from Clojure.

Every Clojure books that I know of has a chapter on interop but that may not be
enough alone depending of your interop needs.

I would suggest narrowing the subject on how to understand Javadoc (most libs 
APIs are 
documented) and how to translate this to Clojure usable forms. The java primer
might be a start to understand the API terminology(class, static, abstract 
class, ).

You may be able to pick up only the pieces you
need along the way instead of digesting the whole thing at once.

Luc


> Thank you, gentlemen. Jim and Luc, your answers are both helpful. Luc's 
> answer illustrates why a Java tyro often has problems understanding 
> Clojure. Somebody like me who is trying to master Clojure, having come 
> to it via a language path that doesn't include Java, needs a 
> prerequisite crash course in Java concepts. (I hope it isn't necessary 
> for him actually to learn Java programming skills. Reserving 
> programming-skill learning for Clojure is a lot more fun!) Anybody have 
> any recommendations of a book that could be used for such a crash course?
>--Larry
> 
> 
> On 12/16/12 1:53 PM, Softaddicts wrote:
> > First example tries to access a public static field in the Math class.
> >
> > Second example calls the static member function of the Math class.
> >
> > The difference is in the missing set of parenthesis.
> >
> > A static field or member function is attached to the class, not to a 
> > specific object
> > and can be accessed through the class itself. Hence the / notation.
> >
> > On the other hand, (.addListener x ...) refers to the member fn addListener 
> > of the given object x.
> >
> > You will rarely find Java object specific public fields directly 
> > accessible, most of the
> > time you need to use a getter to access them, hence the profusion of 
> > .getXzzz
> > when you look at interop code.
> >
> > Static fields attached to a class are most of the time immutable, they are 
> > a way
> > to make constants public and avoid the getter wrapper syndrom.
> >
> > Last thing, a class can define classes so you may need to access
> > Aclass$Bclass/field to get access to a class static field defined within a 
> > class.
> >
> > This does not apply to an object of class B, the usual (.memberFn object 
> > ...)
> > would still apply assuming you are handed an object created from an inner 
> > class.
> >
> >
> > Luc P.
> >
> >
> >
> >> It almost certainly has something to do with my abysmal ignorance about
> >> things Java, but I don't understand this difference:
> >>
> >> (1)
> >> user> (map  Math/sqrt  [5  6  16])
> >>
> >> Unable to find static field: sqrt in class java.lang.Math
> >> [Thrown class java.lang.RuntimeException]
> >>
> >> (2)
> >> user> (map  #(Math/sqrt  %)  [5  6  16])
> >> (2.23606797749979  2.449489742783178  4.0)
> >>
> >> Thanks for helping me understand.
> >> --Larry
> >>
> >> -- 
> >> You received this message because you are subscribed to the Google
> >> Groups "Clojure" group.
> >> To post to this group, send email to clojure@googlegroups.com
> >> Note that posts from new members are moderated - please be patient with 
> >> your first post.
> >> To unsubscribe from this group, send email to
> >> clojure+unsubscr...@googlegroups.com
> >> For more options, visit this group at
> >> http://groups.google.com/group/clojure?hl=en
> >>
> > --
> > Softaddicts sent by ibisMail from my ipad!
> >
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> 
--
Softaddicts sent by ibisMail from my ipad!

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

2012-12-16 Thread Softaddicts
It depends on the relationship between args. If the second arg narrows the 
semantic
of the first and so on, 4th arity fns may not be hard at all. Otherwise it may 
confuse the reader.


> Any time I'm tempted to adda  3rd arity to a function I strongly consider
> using keyword args.
> 
> On Sun, Dec 16, 2012 at 3:39 PM, Softaddicts 
> wrote:
> 
> > I would say that above 4 args, it starts to exercise your memory except if
> > you
> > have auto-completion and a tool tip provided by your IDE.
> >
> > Optional arguments are better handled with keywords than with an option
> > map or
> > multiple signatures.
> > This the area were you can get lost. At least with keyword de structuring
> > you get
> > an error if you misspelled one and the names might ease up the memory
> > stress if they are chosen properly.
> >
> > Luc
> >
> > > I think one of the main reasons we don't use keyword arguments
> > > everywhere is their verbosity. Most function names implicate the order
> > > of arguments, and many functions don't take more than two or three.
> > > It's a trade-off between how much a programmer has to remember and how
> > > much he has to code.
> > >
> > >
> > >
> > > On Sun, Dec 16, 2012 at 11:34 PM, Michael Hanson
> > >  wrote:
> > > > I remember in Rich Hickey's talk "Simplicity Matters", he mentioned
> > that
> > > > forcing the user to remember the order of function arguments, as
> > opposed to
> > > > using keyword arguments, is overly-complex; yet, reading Clojure
> > source code
> > > > and looking at the standard functions, I find that keyword arguments
> > are
> > > > never used. Why is that? Am I missing something or an explanation
> > somewhere?
> > > >
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Clojure" group.
> > > > To post to this group, send email to clojure@googlegroups.com
> > > > Note that posts from new members are moderated - please be patient
> > with your
> > > > first post.
> > > > To unsubscribe from 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
> > >
> > --
> > Softaddicts sent by ibisMail from my ipad!
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from 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
--
Softaddicts sent by ibisMail from my ipad!

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


Re: Using functions from Java packages

2012-12-16 Thread Larry Travis
Thank you, gentlemen. Jim and Luc, your answers are both helpful. Luc's 
answer illustrates why a Java tyro often has problems understanding 
Clojure. Somebody like me who is trying to master Clojure, having come 
to it via a language path that doesn't include Java, needs a 
prerequisite crash course in Java concepts. (I hope it isn't necessary 
for him actually to learn Java programming skills. Reserving 
programming-skill learning for Clojure is a lot more fun!) Anybody have 
any recommendations of a book that could be used for such a crash course?

  --Larry


On 12/16/12 1:53 PM, Softaddicts wrote:

First example tries to access a public static field in the Math class.

Second example calls the static member function of the Math class.

The difference is in the missing set of parenthesis.

A static field or member function is attached to the class, not to a specific 
object
and can be accessed through the class itself. Hence the / notation.

On the other hand, (.addListener x ...) refers to the member fn addListener of 
the given object x.

You will rarely find Java object specific public fields directly accessible, 
most of the
time you need to use a getter to access them, hence the profusion of .getXzzz
when you look at interop code.

Static fields attached to a class are most of the time immutable, they are a way
to make constants public and avoid the getter wrapper syndrom.

Last thing, a class can define classes so you may need to access
Aclass$Bclass/field to get access to a class static field defined within a 
class.

This does not apply to an object of class B, the usual (.memberFn object ...)
would still apply assuming you are handed an object created from an inner class.


Luc P.




It almost certainly has something to do with my abysmal ignorance about
things Java, but I don't understand this difference:

(1)
user> (map  Math/sqrt  [5  6  16])

Unable to find static field: sqrt in class java.lang.Math
[Thrown class java.lang.RuntimeException]

(2)
user> (map  #(Math/sqrt  %)  [5  6  16])
(2.23606797749979  2.449489742783178  4.0)

Thanks for helping me understand.
--Larry

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


--
Softaddicts sent by ibisMail from my ipad!



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

2012-12-16 Thread Softaddicts
I would say that above 4 args, it starts to exercise your memory except if you
have auto-completion and a tool tip provided by your IDE.

Optional arguments are better handled with keywords than with an option map or
multiple signatures.
This the area were you can get lost. At least with keyword de structuring you 
get
an error if you misspelled one and the names might ease up the memory
stress if they are chosen properly.

Luc

> I think one of the main reasons we don't use keyword arguments
> everywhere is their verbosity. Most function names implicate the order
> of arguments, and many functions don't take more than two or three.
> It's a trade-off between how much a programmer has to remember and how
> much he has to code.
> 
> 
> 
> On Sun, Dec 16, 2012 at 11:34 PM, Michael Hanson
>  wrote:
> > I remember in Rich Hickey's talk "Simplicity Matters", he mentioned that
> > forcing the user to remember the order of function arguments, as opposed to
> > using keyword arguments, is overly-complex; yet, reading Clojure source code
> > and looking at the standard functions, I find that keyword arguments are
> > never used. Why is that? Am I missing something or an explanation somewhere?
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with your
> > first post.
> > To unsubscribe from 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
> 
--
Softaddicts sent by ibisMail from my ipad!

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

2012-12-16 Thread Moritz Ulrich
I think one of the main reasons we don't use keyword arguments
everywhere is their verbosity. Most function names implicate the order
of arguments, and many functions don't take more than two or three.
It's a trade-off between how much a programmer has to remember and how
much he has to code.



On Sun, Dec 16, 2012 at 11:34 PM, Michael Hanson
 wrote:
> I remember in Rich Hickey's talk "Simplicity Matters", he mentioned that
> forcing the user to remember the order of function arguments, as opposed to
> using keyword arguments, is overly-complex; yet, reading Clojure source code
> and looking at the standard functions, I find that keyword arguments are
> never used. Why is that? Am I missing something or an explanation somewhere?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from 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


The idiomatic use of keyword arguments

2012-12-16 Thread Michael Hanson
I remember in Rich Hickey's talk "Simplicity Matters", he mentioned that 
forcing the user to remember the order of function arguments, as opposed to 
using keyword arguments, is overly-complex; yet, reading Clojure source 
code and looking at the standard functions, I find that keyword arguments 
are never used. Why is that? Am I missing something or an explanation 
somewhere?

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

Re: How to structure a Clojure day for noobs?

2012-12-16 Thread ulsa
Interesting idea. Let me ponder that.

When one starts pulling on a thread like metadata for example, all kinds of 
interesting facets pop up. That's what I meant with my comment about the XP 
practices graph thing. Different Clojure capabilities support and enable 
other capabilities, and you need to be prepared to explain those other 
capabilities. They're all (well maybe not all) interconnected and I think 
it's hard to know which thread to start pulling on.


On Sunday, 16 December 2012 22:58:56 UTC+1, Devin Walters (devn) wrote:
>
> I think showing people how metadata works usually makes people start 
> dreaming, and exposes them to docstrings and arglists which I think is 
> crucial to self-directed learning.
>
> So, I think I'd show them: (doc ...), and then show how that is metadata, 
> and for quicker folks you could show how to add metadata, use ns-publics 
> which means introducing var-quote, etc.
>
> There's a lot in that exercise that's exciting IMHO. If you want help 
> organizing something like that ping me privately.
>
> Cheers,
> '(Devin Walters)
>
> On Dec 16, 2012, at 2:44 PM, Marko Topolnik 
> > 
> wrote:
>
>
> My plan was to do something like this:
>>
>> *First half of the day*
>>
>> 1. install Leiningen and learn the basics
>> 2. get everyone an editing environment, with the option of using either 
>> Emacs, IntelliJ, or Eclipse
>> 3. teach the basics and let everyone follow along in their own environment
>>
>> *Second half of the day*
>>
>> Either: solve a smaller problem, like Game of Life, Langton's ant, or 
>> something similar
>> or: just build a Compojure web app, and incrementally improve this, and 
>> have it deployed in CloudBees or Heroku
>>
>
> Given this choice I'd go with the web app because it 
>
>- has greater impact (a publicly visible app) and 
>- doesn't involve the dullness of desktop GUI 
>
> There are a few basic things that I think they need to see:
>>
>>- how do I get started
>>- how is code modularized and packaged
>>- how can it be deployed and executed
>>- how does Java interop work
>>- how do I handle the regular problems I have previously used 
>>for-loops to solve
>>
>> Quite a good plan. Of course, don't forget the REPL :) 
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com 
> Note that posts from new members are moderated - please be patient with 
> your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
>

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

Re: How to structure a Clojure day for noobs?

2012-12-16 Thread ulsa
Thanks, I won't forget the REPL. 

I think, however, that there is a risk of a disconnect, where newcomers 
don't really grasp that there is a JVM running and that code is actually 
compiled and injected into it, and that it's for real. They are used to 
mickey mouse interactive tools that don't provide the real thing, and 
struggle to bridge the apparent gap between running code in the REPL and 
"properly compiling and running" files. There is no gap, but one needs to 
explain that, I think.

"When in doubt, lein repl."

On Sunday, 16 December 2012 21:44:33 UTC+1, Marko Topolnik wrote:
>
>
> My plan was to do something like this:
>>
>> *First half of the day*
>>
>> 1. install Leiningen and learn the basics
>> 2. get everyone an editing environment, with the option of using either 
>> Emacs, IntelliJ, or Eclipse
>> 3. teach the basics and let everyone follow along in their own environment
>>
>> *Second half of the day*
>>
>> Either: solve a smaller problem, like Game of Life, Langton's ant, or 
>> something similar
>> or: just build a Compojure web app, and incrementally improve this, and 
>> have it deployed in CloudBees or Heroku
>>
>
> Given this choice I'd go with the web app because it 
>
>- has greater impact (a publicly visible app) and 
>- doesn't involve the dullness of desktop GUI 
>
> There are a few basic things that I think they need to see:
>>
>>- how do I get started
>>- how is code modularized and packaged
>>- how can it be deployed and executed
>>- how does Java interop work
>>- how do I handle the regular problems I have previously used 
>>for-loops to solve
>>
>> Quite a good plan. Of course, don't forget the REPL :) 
>

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

Re: How to structure a Clojure day for noobs?

2012-12-16 Thread Devin Walters
I think showing people how metadata works usually makes people start dreaming, 
and exposes them to docstrings and arglists which I think is crucial to 
self-directed learning.

So, I think I'd show them: (doc ...), and then show how that is metadata, and 
for quicker folks you could show how to add metadata, use ns-publics which 
means introducing var-quote, etc.

There's a lot in that exercise that's exciting IMHO. If you want help 
organizing something like that ping me privately.

Cheers,
'(Devin Walters)

On Dec 16, 2012, at 2:44 PM, Marko Topolnik  wrote:

> 
> My plan was to do something like this:
> 
> First half of the day
> 
> 1. install Leiningen and learn the basics
> 2. get everyone an editing environment, with the option of using either 
> Emacs, IntelliJ, or Eclipse
> 3. teach the basics and let everyone follow along in their own environment
> 
> Second half of the day
> 
> Either: solve a smaller problem, like Game of Life, Langton's ant, or 
> something similar
> or: just build a Compojure web app, and incrementally improve this, and have 
> it deployed in CloudBees or Heroku
> 
> Given this choice I'd go with the web app because it 
> has greater impact (a publicly visible app) and 
> doesn't involve the dullness of desktop GUI 
> There are a few basic things that I think they need to see:
> how do I get started
> how is code modularized and packaged
> how can it be deployed and executed
> how does Java interop work
> how do I handle the regular problems I have previously used for-loops to solve
> Quite a good plan. Of course, don't forget the REPL :) 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from 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: abysmal multicore performance, especially on AMD processors

2012-12-16 Thread Lee Spector

On Dec 14, 2012, at 10:41 PM, cameron wrote:
> Until Lee has a representative benchmark for his application it's difficult 
> to tell if he's
> experiencing the same problem but there would seem to be a case for changing 
> the PersistentList
> implementation in clojure.lang.

We put together a version of our application in which we just replaced all of 
the random calls with deterministic functions (returning either constants or 
deterministic functions of their arguments). 

What we saw was a maximum speedup of less than x2 on a 48 core machine, which 
was interesting in part because the determinism meant that only a tiny subset 
of our code was being executed (because all of the Push programs in the 
population were identical and used only a single Push instruction). So I think 
that this may indeed help us to hone in on the problem.

Before we share that code, however, we should make sure that the evaluations 
that are being done concurrently are sufficiently long-running, and maybe tweak 
a couple of other things. I think we'll have a chance to do that early in the 
week and we'll share the results/code when we do.

Thanks,

 -Lee

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

2012-12-16 Thread Lee Spector

On Dec 15, 2012, at 1:14 AM, cameron wrote:
> 
> Originally I was using ECJ (http://cs.gmu.edu/~eclab/projects/ecj/) in java 
> for my GP work but for the last few years it's been GEVA with a clojure 
> wrapper I wrote (https://github.com/cdorrat/geva-clj).

Ah yes -- I've actually downloaded and played a bit with your GEVA via Clojure. 
I've thought it would be interesting to try using GEVA to evolve Push programs 
(which have a trivial grammar), but haven't had the time to try that.

I've also used ECJ for some projects but haven't looked at its multicore 
performance. Sean Luke (ECJ's author and incidentally a former student of mine) 
even hacked together a way to use it to evolve Push programs but it was nasty 
(generating Push programs as strings) and would be low-performance for other 
reasons.

 -Lee

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

2012-12-16 Thread Ray
Hilarious - I am so conditioned already to have everything in a list :)

Thanks for your patient explanation. Merry xmas.

ray 


Ray


On Sunday 16 December 2012 at 22:20, Benjamin R. Haskell wrote:

> On Sun, 16 Dec 2012, mond wrote:
> 
> > One small thing Ben... when I try to use the final formulation I receive an 
> > error:
> > (def joined-products (map product-with-item products))
> > 
> > user=> (joined-products)
> > ClassCastException clojure.lang.LazySeq cannot be cast to clojure.lang.IFn  
> > user/eval241 (NO_SOURCE_FILE:9)
> > 
> > Any ideas?
> 
> To evaluate a list, Clojure tries to call the first element as a 
> function, with the remaining elements as its arguments. So, in this 
> case:
> 
> (joined-products)
> 
> Clojure tries to cast the first element of the list (joined-products) to 
> be used as a Clojure function (clojure.lang.IFn), but it's a lazy 
> sequence (clojure.lang.LazySeq).
> 
> You just don't need the list:
> 
> user=> joined-products
> (#user.Product{...} #user.Product{...} #user.Product{...} ...)
> 
> -- 
> Best,
> Ben
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com 
> (mailto:clojure@googlegroups.com)
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com 
> (mailto: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: another n00b defrecord combination question

2012-12-16 Thread Benjamin R. Haskell

On Sun, 16 Dec 2012, mond wrote:


One small thing Ben... when I try to use the final formulation I receive an 
error:
(def joined-products (map product-with-item products))

user=> (joined-products)
ClassCastException clojure.lang.LazySeq cannot be cast to clojure.lang.IFn  
user/eval241 (NO_SOURCE_FILE:9)

Any ideas?


To evaluate a list, Clojure tries to call the first element as a 
function, with the remaining elements as its arguments.  So, in this 
case:


  (joined-products)

Clojure tries to cast the first element of the list (joined-products) to 
be used as a Clojure function (clojure.lang.IFn), but it's a lazy 
sequence (clojure.lang.LazySeq).


You just don't need the list:

user=> joined-products
(#user.Product{...} #user.Product{...} #user.Product{...} ...)

--
Best,
Ben

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

2012-12-16 Thread mond
One small thing Ben... when I try to use the final formulation I receive an 
error:

(def joined-products (map product-with-item products))

user=> (joined-products)
ClassCastException clojure.lang.LazySeq cannot be cast to clojure.lang.IFn 
 user/eval241 (NO_SOURCE_FILE:9)

Any ideas?

Thanks in advance

ray

On Saturday, December 15, 2012 10:54:42 PM UTC+1, Benjamin R. Haskell wrote:
>
> On Sat, 15 Dec 2012, mond wrote: 
>
> > Thanks for picking up the cudgels Ben! 
>
> Ha.  It's nice to have reached a point where I feel at-all confident 
> with any of this... happy to help. 
>
>
> > To be honest I am struggling to repeat your advice in the REPL.  In 
> > any case, I decided to change the data structures in line with your 
> > advice and put the IDs into maps rather than the records. 
> > 
> > (defrecord Item [name product quantity purchased]) 
> > 
> > (defrecord Product [name description prices]) 
> > 
> > (defrecord Price [price tax currency]) 
> > 
> > (def items [ {:id 1 :item (->Item "Brogues" "P-123" 1 true)} 
> >  {:id 2 :item (->Item "Underpants" "P-345" 2 false)} 
> >  {:id 3 :item (->Item "Shirt" "P-678" 1 true)} ]) 
> > 
> > (def carts [ (->Cart "Birthday" (first items)) 
> >  (->Cart "Xmas" (rest items)) ]) 
> > 
> > (def products [ {:id "P-1231" :product (->Product "Table" "Coffee Table" 
> (->Price 375 21 "EURO"))} 
> > {:id "P-3451" :product (->Product "Chairs" "Set of 
> Four(4) chairs" (->Price 200 21 "EURO"))} 
> > {:id "P-123" :product (->Product "Brogues" "Men's 
> Leather Slip on Brogues" (->Price 93.00 21 "EURO"))} 
> > {:id "P-345" :product (->Product "Underpants" "CK Y 
> Fronts" (->Price 23.50 21 "EURO"))} 
> > {:id "P-678" :product (->Product "Shirt" "Slim Fit White 
> Vest Shirt" (->Price 45.99 21 "EURO"))} 
> > {:id "P-6781" :product (->Product "TableCloth" "Classic 
> red and white checks 2m x 2m" (->Price 17.99 21 "EURO"))} ]) 
> > 
> > Do you think the zipmap is still the way to go (to resolve the 
> > 'foreign key' or could there be an easier way? I guess the fact that 
> > only items have to zipmapped is one advantage. 
>
> It seems like items and products should still have an :id property, so I 
> don't think you need to detach the ID from its entity.  The zipmap'ed 
> version is useful as an index, not really as its own structure.  So, it 
> ends up as just a single map (not an array of maps) with ID's as keys, 
> and the corresponding entity as the value: 
>
>
> (defrecord Item [id name product quantity purchased]) 
>
> (defrecord Product [id name description prices]) 
>
> (defrecord Price [price tax currency]) 
>
> (def items [ (->Item 1 "Brogues" "P-123" 1 true) 
>  (->Item 2 "Underpants" "P-345" 2 false) 
>  (->Item 3 "Shirt" "P-678" 1 true) ]) 
>
> (def products [ (->Product "P-1231" "Table" "Coffee Table" (->Price 375 21 
> "EURO")) 
> (->Product "P-3451" "Chairs" "Set of Four(4) chairs" 
> (->Price 200 21 "EURO")) 
> (->Product "P-123" "Brogues" "Men's Leather Slip on 
> Brogues" (->Price 93.00 21 "EURO")) 
> (->Product "P-345" "Underpants" "CK Y Fronts" (->Price 
> 23.50 21 "EURO")) 
> (->Product "P-678" "Shirt" "Slim Fit White Vest Shirt" 
> (->Price 45.99 21 "EURO")) 
> (->Product "P-6781" "TableCloth" "Classic red and white 
> checks 2m x 2m" (->Price 17.99 21 "EURO")) ]) 
>
> ; two useful indexes(/indices?): 
>
> (def prod->item 
>"An index from Product ID to an Item" 
>(zipmap (map :product items) items)) 
>
> (def id->product 
>"An index from Product ID to a Product" 
>(zipmap (map :id products) products)) 
>
> ; Then you can use that to get the products joined with their items: 
>
> (defn product-with-item 
>"Find the Item info and merge it into the product, without overwriting 
> :id" 
>[product] 
>(merge-with (fn [a b] a) product (prod->item (:id product 
>
> ; example usage: 
>
> (product-with-item (id->product "P-345")) 
> ;=> #user.Product{:id 2, 
> ; :name "Underpants", 
> ; :description "CK Y Fronts", 
> ; :prices #user.Price{:price 23.5, :tax 21, :currency 
> "EURO"}, 
> ; :purchased false, 
> ; :quantity 2, 
> ; :product "P-345"} 
>
> (def joined-products (map product-with-item products)) 
> ;=> A list of all the products joined with their items 
>
> -- 
> Best, 
> Ben
>
>  

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

Re: How to structure a Clojure day for noobs?

2012-12-16 Thread Marko Topolnik


> My plan was to do something like this:
>
> *First half of the day*
>
> 1. install Leiningen and learn the basics
> 2. get everyone an editing environment, with the option of using either 
> Emacs, IntelliJ, or Eclipse
> 3. teach the basics and let everyone follow along in their own environment
>
> *Second half of the day*
>
> Either: solve a smaller problem, like Game of Life, Langton's ant, or 
> something similar
> or: just build a Compojure web app, and incrementally improve this, and 
> have it deployed in CloudBees or Heroku
>

Given this choice I'd go with the web app because it 

   - has greater impact (a publicly visible app) and 
   - doesn't involve the dullness of desktop GUI 

There are a few basic things that I think they need to see:
>
>- how do I get started
>- how is code modularized and packaged
>- how can it be deployed and executed
>- how does Java interop work
>- how do I handle the regular problems I have previously used 
>for-loops to solve
>
> Quite a good plan. Of course, don't forget the REPL :) 

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

Re: How to structure a Clojure day for noobs?

2012-12-16 Thread ulsa
Good points, thanks. 

It's so easy to overload them, because one wants to teach them every little 
piece of gold that's in there. I think it was in one of the old XP books, 
where there was this graph that showed which practices were supported by or 
enabled other practices. I would love to see something similar for the 
capabilities in Clojure. It would make it easier to see what can and can 
not be cut out from an introduction course.

My plan was to do something like this:

*First half of the day*

1. install Leiningen and learn the basics
2. get everyone an editing environment, with the option of using either 
Emacs, IntelliJ, or Eclipse
3. teach the basics and let everyone follow along in their own environment

*Second half of the day*

Either: solve a smaller problem, like Game of Life, Langton's ant, or 
something similar
or: just build a Compojure web app, and incrementally improve this, and 
have it deployed in CloudBees or Heroku

There are a few basic things that I think they need to see:

   - how do I get started
   - how is code modularized and packaged
   - how can it be deployed and executed
   - how does Java interop work
   - how do I handle the regular problems I have previously used for-loops 
   to solve
   

On Saturday, 15 December 2012 23:57:48 UTC+1, Marko Topolnik wrote:
>
> There is one advice I can give from my teaching experience: don't 
> overwhelm them with data. A person can assimilate only so many concepts in 
> a day, no matter whether the workshop lasts two or eight hours. 
>
> Pick a few key concepts and spend much time on approaching each concept 
> from many different angles. Have everyone involved with exercises. Make 
> layered exercises: each of those ten people is going to progress at their 
> own pace. Allow enough time for the slowest ones to get through the basic 
> part of the exercise, but have a stash of extra stuff for the quicker ones, 
> so they don't get bored and frustrated while waiting on others.
>
> On Saturday, December 15, 2012 11:13:21 PM UTC+1, ulsa wrote:
>>
>> In a couple of months, I'll have a whole day of teaching Clojure to ten 
>> of my colleagues. They are experienced Java programmers, but otherwise 
>> Clojure rookies. Any tips on how to structure such a workshop day?
>>
>

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

Re: Why I get IllegalArgumentException: No matching ctor found

2012-12-16 Thread Jonathan Fischer Friberg
I don't know why it doesn't work. However, changing defgreeter to the
following seems work.

(defmacro defgreeter [greeter-name]
  (let [greeter (make-greeter)]
`(def ~greeter-name ~greeter)))

Might be a clue. :)

Jonathan


On Sun, Dec 16, 2012 at 6:49 PM, juan.facorro wrote:

> I think it has to do with the closure in the *fn *used when generating
> the form in the macro.
>
> If you change this function:
>
> *(defn make-greeter []*
> *  (let [message "hello"]*
> *(fn [user-name]*
> *  (str message ", " user-name*
>
> To this one:
>
> *(defn make-greeter []
> *
> *  (fn [user-name]*
> *(let [message "**hello**"]*
> *  (str message ", " user-name*
>
> There's no closure on the *message* local var, so you don't get any
> errors when the form the macro produces is compiled.
>
> *constantly** *also creates a closure on its argument:
>
> *(defn constantly*
> *  "Returns a function that takes any number of arguments and returns x."*
> *  {:added "1.0"*
> *   :static true}*
> *  [x] (fn [& args] x))*
>
> So the source of the problem seems to be the same.
>
> Although I'm not completely sure why this doesn't work, I think it kind of
> makes sense since the *fn* returned by *make-greeter* is actually
> produced in the *defmacro* body and not in the form generated, somehow
> the closure is lost and the error is generated.
>
> Someone with a better understanding of macros please jump in.
>
> Juan
>
> On Sunday, December 16, 2012 11:24:35 AM UTC-3, jarppe wrote:
>>
>> Hi,
>>
>> I have this macro (complete file 
>> https://www.refheap.com/paste/**7633
>> ):
>>
>> *(*defmacro defgreeter [greeter-name]
>>
>>   *(*let [greeter *(*make-greeter*)*]
>>
>> `*(*do
>>
>>*(*defn ~greeter-name [user-name#]
>>
>>  *(*~greeter user-name#*)**)**)**)**)*
>>
>>
>> It works as expected when make-greeter is defined like this:
>>
>> *(*defn make-greeter []
>>
>>   *(*fn [user-name]
>>
>> *(*str "Hello, " user-name*)**)**)*
>>
>>
>> I can use it like this:
>>
>> *(*defgreeter hello*)*
>>
>> *(*hello "jarppe"*)*
>>
>> How ever, if I change make-greeter to this I get IllegalArgumentException:
>>
>> *(*defn make-greeter []
>>
>>   *(*let [message "hello"]
>>
>> *(*fn [user-name]
>>
>>   *(*str message ", " user-name*)**)**)**)*
>>
>>
>> Interestingly, this does not work either:
>>
>> *(*defn make-greeter []
>>
>>   *(*constantly "what erver"*)**)*
>>
>> What am I missing?
>>
>> --
>> -jarppe
>>
>>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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: Using functions from Java packages

2012-12-16 Thread Softaddicts
First example tries to access a public static field in the Math class.

Second example calls the static member function of the Math class.

The difference is in the missing set of parenthesis.

A static field or member function is attached to the class, not to a specific 
object
and can be accessed through the class itself. Hence the / notation.

On the other hand, (.addListener x ...) refers to the member fn addListener of 
the given object x.

You will rarely find Java object specific public fields directly accessible, 
most of the
time you need to use a getter to access them, hence the profusion of .getXzzz
when you look at interop code.

Static fields attached to a class are most of the time immutable, they are a way
to make constants public and avoid the getter wrapper syndrom.

Last thing, a class can define classes so you may need to access
Aclass$Bclass/field to get access to a class static field defined within a 
class.

This does not apply to an object of class B, the usual (.memberFn object ...)
would still apply assuming you are handed an object created from an inner class.


Luc P.



> It almost certainly has something to do with my abysmal ignorance about 
> things Java, but I don't understand this difference:
> 
> (1)
> user> (map  Math/sqrt  [5  6  16])
> 
> Unable to find static field: sqrt in class java.lang.Math
>[Thrown class java.lang.RuntimeException]
> 
> (2)
> user> (map  #(Math/sqrt  %)  [5  6  16])
> (2.23606797749979  2.449489742783178  4.0)
> 
> Thanks for helping me understand.
>--Larry
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> 
--
Softaddicts sent by ibisMail from my ipad!

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


Re: Using functions from Java packages

2012-12-16 Thread Jim - FooBar();
Java methods are not first-class...you cannot use them like that...you 
need an object to call the method on...by wrapping the java call with an 
anonymous fn you are able to use Math/sqrt as 1st-class...

Hope it is clearer now...

Jim


On 16/12/12 19:33, Larry Travis wrote:
It almost certainly has something to do with my abysmal ignorance 
about things Java, but I don't understand this difference:


(1)
user> (map  Math/sqrt  [5  6  16])

Unable to find static field: sqrt in class java.lang.Math
  [Thrown class java.lang.RuntimeException]

(2)
user> (map  #(Math/sqrt  %)  [5  6  16])
(2.23606797749979  2.449489742783178  4.0)

Thanks for helping me understand.
  --Larry



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

2012-12-16 Thread Marko Topolnik


> However, the fact that you can write funcall so easily as #(%1 %2) 
> illustrates that funcall adds no real expressiveness to the language, 
> whereas apply is really fundamental to being able to pass lists to 
> multi-arg functions.  It's hard to imagine how to write apply at all if it 
> weren't built in to the language.
>
> funcall, on the other hand, can be described easily as "funcall is a 
> function that takes a function f, and a value v and applies f to v".
> We write funcall the exact same way we write any other "function that 
> takes a blah and blah and does blah":
> (defn funcall [f v] (f v))
> or as you noted, #(%1 %2).
>
> Since we have a way to apply a function to a value (i.e., (f v)), if you 
> want a function that applies a function to a value, you can easily express 
> that using ordinary techniques, if needed.
>

Exactly. As I pointed out, Clojure users are hardly "out of luck" when 
confronted with a need for funcall. Quite the contrary: the function is *too 
trivial* to even deserve a name in the core namespace. 

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

Using functions from Java packages

2012-12-16 Thread Larry Travis
It almost certainly has something to do with my abysmal ignorance about 
things Java, but I don't understand this difference:


(1)
user> (map  Math/sqrt  [5  6  16])

Unable to find static field: sqrt in class java.lang.Math
  [Thrown class java.lang.RuntimeException]

(2)
user> (map  #(Math/sqrt  %)  [5  6  16])
(2.23606797749979  2.449489742783178  4.0)

Thanks for helping me understand.
  --Larry

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

2012-12-16 Thread Mark Engelberg
On Sun, Dec 16, 2012 at 10:04 AM, Marko Topolnik
wrote:

>
> Well, why don't you start with my example? Try rewriting this without OP's
> *apply*, implemented here as #(%1 %2).
>
>  (defn apply-curried [f & args] (reduce #(%1 %2) f args))
>
>
>
To avoid confusion, I'm going to refer to the OP's conception of apply as
"funcall" versus Clojure's "apply".

Ok, I see your point that the concept of funcall can be a useful one.

However, the fact that you can write funcall so easily as #(%1 %2)
illustrates that funcall adds no real expressiveness to the language,
whereas apply is really fundamental to being able to pass lists to
multi-arg functions.  It's hard to imagine how to write apply at all if it
weren't built in to the language.

funcall, on the other hand, can be described easily as "funcall is a
function that takes a function f, and a value v and applies f to v".
We write funcall the exact same way we write any other "function that takes
a blah and blah and does blah":
(defn funcall [f v] (f v))
or as you noted, #(%1 %2).

Since we have a way to apply a function to a value (i.e., (f v)), if you
want a function that applies a function to a value, you can easily express
that using ordinary techniques, if needed.

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

2012-12-16 Thread Mark Engelberg
On Sun, Dec 16, 2012 at 10:06 AM, Armando Blancas wrote:

>  I'm not going out of my way to be pseudonymous, it just seems to be a
>> feature of the group.
>
>
>>
>
> I thought, Mark asking how to run a script? An usurper!
>
>
>
Ah yes.  My understanding of Clojure runs fairly deep, but when it comes to
understanding the mundane aspects of how to build and run Clojure and
Clojure files from java/maven/etc, I am but a babe in the woods :)   I have
my toolchain that works for me (most of the time) and keeps me sheltered
from those details, but once I get outside of that, I'm lost.

--Mark

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

2012-12-16 Thread Armando Blancas

>
>  I'm not going out of my way to be pseudonymous, it just seems to be a 
> feature of the group. 

 
>
 
I thought, Mark asking how to run a script? An usurper!

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

2012-12-16 Thread Marko Topolnik


> As for your suggestion of a (funcall f [i]) that behaves just like (f 
> [i]), I can't imagine any possible purpose for that in Clojure.  Why would 
> you not just write (f [i])?  
>

Well, why don't you start with my example? Try rewriting this without OP's *
apply*, implemented here as #(%1 %2).

 (defn apply-curried [f & args] (reduce #(%1 %2) f args))

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

2012-12-16 Thread Mark Engelberg
On Sun, Dec 16, 2012 at 2:59 AM, Peter West  wrote:

So it sounds like you just thought apply was something other than the
list->arguments adapter that it is.  One of the best resources for learning
about clojure's functions is clojuredocs.org.  Most of the functions are
accompanied by a number of concrete examples that help gain a deeper
understanding than the brief docstring.

http://clojuredocs.org/clojure_core/clojure.core/apply

As for your suggestion of a (funcall f [i]) that behaves just like (f [i]),
I can't imagine any possible purpose for that in Clojure.  Why would you
not just write (f [i])?

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

Re: Why I get IllegalArgumentException: No matching ctor found

2012-12-16 Thread juan.facorro
I think it has to do with the closure in the *fn *used when generating the 
form in the macro. 

If you change this function:

*(defn make-greeter []*
*  (let [message "hello"]*
*(fn [user-name]*
*  (str message ", " user-name*

To this one:

*(defn make-greeter []
*
*  (fn [user-name]*
*(let [message "**hello**"]*
*  (str message ", " user-name*

There's no closure on the *message* local var, so you don't get any errors 
when the form the macro produces is compiled.

*constantly** *also creates a closure on its argument:

*(defn constantly*
*  "Returns a function that takes any number of arguments and returns x."*
*  {:added "1.0"*
*   :static true}*
*  [x] (fn [& args] x))*

So the source of the problem seems to be the same.

Although I'm not completely sure why this doesn't work, I think it kind of 
makes sense since the *fn* returned by *make-greeter* is actually produced 
in the *defmacro* body and not in the form generated, somehow the closure 
is lost and the error is generated.

Someone with a better understanding of macros please jump in.

Juan

On Sunday, December 16, 2012 11:24:35 AM UTC-3, jarppe wrote:
>
> Hi,
>
> I have this macro (complete file https://www.refheap.com/paste/7633):
>
> *(*defmacro defgreeter [greeter-name]
>
>   *(*let [greeter *(*make-greeter*)*]
>
> `*(*do
>
>*(*defn ~greeter-name [user-name#]
>
>  *(*~greeter user-name#*)**)**)**)**)*
>
>
> It works as expected when make-greeter is defined like this:
>
> *(*defn make-greeter []
>
>   *(*fn [user-name]
>
> *(*str "Hello, " user-name*)**)**)*
>
>
> I can use it like this:
>
> *(*defgreeter hello*)*
>
> *(*hello "jarppe"*)*
>
> How ever, if I change make-greeter to this I get IllegalArgumentException:
>
> *(*defn make-greeter []
>
>   *(*let [message "hello"]
>
> *(*fn [user-name]
>
>   *(*str message ", " user-name*)**)**)**)*
>
>
> Interestingly, this does not work either:
>
> *(*defn make-greeter []
>
>   *(*constantly "what erver"*)**)*
>
> What am I missing?
>
> -- 
> -jarppe
>
>

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

2012-12-16 Thread Shantanu Kumar
Hi Aaron,

On Sunday, 16 December 2012 04:45:16 UTC+5:30, Aaron wrote:
>
> Cool.  I'm just seeing this now.  I actually spent some time a while back 
> getting a very simple nleiningen working in ClojureCLR.  I had nuget 
> downloads working and also the ability to AOT compile namespaces and merge 
> them into a single DLL.  It's not fully ready for prime time yet though, in 
> part because it depends on some custom modifications to the ClojureCLR 
> compiler.  In the long run, I'd like to work together on getting a full 
> lein clr implementation working.  I'd love to discuss further if you have 
> time.


I would also be happy to discuss -- my contact details are in the lein-clr 
repo README. As of now, lein-clr runs on the JVM and tunnels the 
input/output from the Clojure.Compile.exe and Clojure.Main.exe processes. 
As part of the next (0.3.0) release I am currently focusing on compilation 
support for CLR languages e.g. C#, F# etc.

tools.logging and pinvoke (https://github.com/aaronc/ClojureClrEx) - 
> logging is mostly ported but with only one backend working, 
> pinvoke/dllimport works great, but no docs
> a nice interface to WPF (https://github.com/aaronc/ClojureWpf) - pretty 
> stable, but again no docs yet
> nrepl (https://github.com/aaronc/tools.nrepl/tree/clr) - needs quite a 
> bit more work
>

Nice to know they are on track. nREPL would be a great addition for 
ClojureCLR tooling support.

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

Why I get IllegalArgumentException: No matching ctor found

2012-12-16 Thread jarppe
Hi,

I have this macro (complete file https://www.refheap.com/paste/7633):

*(*defmacro defgreeter [greeter-name]

  *(*let [greeter *(*make-greeter*)*]

`*(*do

   *(*defn ~greeter-name [user-name#]

 *(*~greeter user-name#*)**)**)**)**)*


It works as expected when make-greeter is defined like this:

*(*defn make-greeter []

  *(*fn [user-name]

*(*str "Hello, " user-name*)**)**)*


I can use it like this:

*(*defgreeter hello*)*

*(*hello "jarppe"*)*

How ever, if I change make-greeter to this I get IllegalArgumentException:

*(*defn make-greeter []

  *(*let [message "hello"]

*(*fn [user-name]

  *(*str message ", " user-name*)**)**)**)*


Interestingly, this does not work either:

*(*defn make-greeter []

  *(*constantly "what erver"*)**)*

What am I missing?

-- 
-jarppe

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

2012-12-16 Thread Christian Sperandio
I did some changes.

First and foremost, I change the project's name to a more formal one: it 
has became clj-javafx and the link is now 
https://github.com/chrix75/clj-javafx

I cleaned the code too, thus:

   - I remove the ugly Thread/sleep for promise and deliver
   - make the code cleaner



Le dimanche 16 décembre 2012 00:24:34 UTC+1, Christian Sperandio a écrit :
>
> I had a test to show how it work.
>
>
> Le samedi 15 décembre 2012 22:10:50 UTC+1, Christian Sperandio a écrit :
>>
>> Hi,
>>
>> After some studies about JavaFX with Clojure, and bricks broke with my 
>> head, I wrote a sort of wrapper to work more easily with both.
>> It's here : https://github.com/chrix75/javafx-clj
>>
>> You can play with JavaFX in your REPL and you have the macro with-javax 
>> and wit-javafx-let that let you write JavaFX code  without managing the 
>> JavaFX runtime thread.
>>
>> I hope it can help.
>>
>> Chris
>>
>>

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

2012-12-16 Thread Marko Topolnik


> If you are looking, for some reason I can't imagine at the moment, for a 
> function that acts just like a funcall, so that
> (funcall f [i]) is exactly equivalent to (f [i]), I guess you are out of 
> luck.
>

I can give you a reason: applying a curried function. On first sight that 
may seem like a rare use case, but actually nested maps are just that, and 
quite common. But Clojure users are far from being out of luck:

(defn apply-curried [f & args] (reduce #(%1 %2) f args))

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

2012-12-16 Thread Marko Topolnik

>
> Users of clojure learn that pretty quickly. I've just learned it. Doc 
> doesn't help.


> user=> (doc apply)
>>
>> -
>>
>> clojure.core/apply
>>
>> ([f args] [f x args] [f x y args] [f x y z args] [f a b c d & args])
>>
>>   Applies fn f to the argument list formed by prepending intervening 
>>> arguments to args.
>>
>> nil
>>
>>
Clojure core docs are indeed terse and demand very careful reading, which 
can be quite uninviting to a newcomer. However, if you do read the one you 
quote very carefully, it says that it will apply *f* to the *argument list* 
formed 
as explained. This is exactly and unambiguously what it really does.

I should also add that the learning process in Clojure involves the docs *and 
the repl*. There is hardly a more direct path to knowledge than just typing 
in a line of code and seeing the result. This is why I never really felt 
any frustration with the core docs.

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

2012-12-16 Thread mond
Great stuff Ben. Thanks.

ray

On Saturday, December 15, 2012 10:54:42 PM UTC+1, Benjamin R. Haskell wrote:
>
> On Sat, 15 Dec 2012, mond wrote: 
>
> > Thanks for picking up the cudgels Ben! 
>
> Ha.  It's nice to have reached a point where I feel at-all confident 
> with any of this... happy to help. 
>
>
> > To be honest I am struggling to repeat your advice in the REPL.  In 
> > any case, I decided to change the data structures in line with your 
> > advice and put the IDs into maps rather than the records. 
> > 
> > (defrecord Item [name product quantity purchased]) 
> > 
> > (defrecord Product [name description prices]) 
> > 
> > (defrecord Price [price tax currency]) 
> > 
> > (def items [ {:id 1 :item (->Item "Brogues" "P-123" 1 true)} 
> >  {:id 2 :item (->Item "Underpants" "P-345" 2 false)} 
> >  {:id 3 :item (->Item "Shirt" "P-678" 1 true)} ]) 
> > 
> > (def carts [ (->Cart "Birthday" (first items)) 
> >  (->Cart "Xmas" (rest items)) ]) 
> > 
> > (def products [ {:id "P-1231" :product (->Product "Table" "Coffee Table" 
> (->Price 375 21 "EURO"))} 
> > {:id "P-3451" :product (->Product "Chairs" "Set of 
> Four(4) chairs" (->Price 200 21 "EURO"))} 
> > {:id "P-123" :product (->Product "Brogues" "Men's 
> Leather Slip on Brogues" (->Price 93.00 21 "EURO"))} 
> > {:id "P-345" :product (->Product "Underpants" "CK Y 
> Fronts" (->Price 23.50 21 "EURO"))} 
> > {:id "P-678" :product (->Product "Shirt" "Slim Fit White 
> Vest Shirt" (->Price 45.99 21 "EURO"))} 
> > {:id "P-6781" :product (->Product "TableCloth" "Classic 
> red and white checks 2m x 2m" (->Price 17.99 21 "EURO"))} ]) 
> > 
> > Do you think the zipmap is still the way to go (to resolve the 
> > 'foreign key' or could there be an easier way? I guess the fact that 
> > only items have to zipmapped is one advantage. 
>
> It seems like items and products should still have an :id property, so I 
> don't think you need to detach the ID from its entity.  The zipmap'ed 
> version is useful as an index, not really as its own structure.  So, it 
> ends up as just a single map (not an array of maps) with ID's as keys, 
> and the corresponding entity as the value: 
>
>
> (defrecord Item [id name product quantity purchased]) 
>
> (defrecord Product [id name description prices]) 
>
> (defrecord Price [price tax currency]) 
>
> (def items [ (->Item 1 "Brogues" "P-123" 1 true) 
>  (->Item 2 "Underpants" "P-345" 2 false) 
>  (->Item 3 "Shirt" "P-678" 1 true) ]) 
>
> (def products [ (->Product "P-1231" "Table" "Coffee Table" (->Price 375 21 
> "EURO")) 
> (->Product "P-3451" "Chairs" "Set of Four(4) chairs" 
> (->Price 200 21 "EURO")) 
> (->Product "P-123" "Brogues" "Men's Leather Slip on 
> Brogues" (->Price 93.00 21 "EURO")) 
> (->Product "P-345" "Underpants" "CK Y Fronts" (->Price 
> 23.50 21 "EURO")) 
> (->Product "P-678" "Shirt" "Slim Fit White Vest Shirt" 
> (->Price 45.99 21 "EURO")) 
> (->Product "P-6781" "TableCloth" "Classic red and white 
> checks 2m x 2m" (->Price 17.99 21 "EURO")) ]) 
>
> ; two useful indexes(/indices?): 
>
> (def prod->item 
>"An index from Product ID to an Item" 
>(zipmap (map :product items) items)) 
>
> (def id->product 
>"An index from Product ID to a Product" 
>(zipmap (map :id products) products)) 
>
> ; Then you can use that to get the products joined with their items: 
>
> (defn product-with-item 
>"Find the Item info and merge it into the product, without overwriting 
> :id" 
>[product] 
>(merge-with (fn [a b] a) product (prod->item (:id product 
>
> ; example usage: 
>
> (product-with-item (id->product "P-345")) 
> ;=> #user.Product{:id 2, 
> ; :name "Underpants", 
> ; :description "CK Y Fronts", 
> ; :prices #user.Price{:price 23.5, :tax 21, :currency 
> "EURO"}, 
> ; :purchased false, 
> ; :quantity 2, 
> ; :product "P-345"} 
>
> (def joined-products (map product-with-item products)) 
> ;=> A list of all the products joined with their items 
>
> -- 
> Best, 
> Ben

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

2012-12-16 Thread Peter West
Thanks again. I do get it. I'm not saying that apply has effects other than 
the result it returns. No, it's not a side-effect; it doesn't change 
something in the environment in passing. What it changes is the expected 
result, if you expect that, as Rich Hickey is supposed to have written,
 (apply f [i]) can be written (f i)

This effect is, on the face of it, unpredictable: you just have to know 
that that is what apply does.  Users of clojure learn that pretty quickly. 
I've just learned it. Doc doesn't help.

user=> (doc apply)
>
> -
>
> clojure.core/apply
>
> ([f args] [f x args] [f x y args] [f x y z args] [f a b c d & args])
>
>   Applies fn f to the argument list formed by prepending intervening 
>> arguments to args.
>
> nil
>
>
>  

If you are looking, for some reason I can't imagine at the moment, for a 
function that acts just like a funcall, so that
(funcall f [i]) is exactly equivalent to (f [i]), I guess you are out of 
luck.

I don't know how other lisps deal with "linearising" argument lists? I'd be 
interested to hear.

On Sunday, 16 December 2012 10:21:36 UTC+10, puzzler wrote:
>
> On Sat, Dec 15, 2012 at 3:58 PM, Peter West 
> > wrote:
>
>> But it can't, can it? In this context (apply f [i]) with respect to (f i)
>> * apply *has *side-effects*!
>>
>
> This doesn't really make any sense.  There are no side effects here.  I 
> think maybe you just don't understand what apply does.  Let me try to 
> explain it a different way.
>
> Some functions, like +, are designed to take 1, 2, 3, 4, 5, or any number 
> of arguments.  You can write:
> (+ 1 2)
> (+ 1 2 3)
> (+ 1 2 3 4)
> (+ 1 2 3 4 5)
> etc.
> The "contract" for + is that it takes any number of numbers as an input.
>
> One thing + can't do is add up the numbers in a list, at least not when 
> written in this way:
> (+ [1 2 3 4 5])
> This doesn't make any sense, because + is expecting numbers, and we passed 
> it a vector.
>
> It might seem somewhat ironic that + can't take a list of numbers.  
> Obviously, it knows how to add a series of numbers, it just expects them to 
> be one after each other, as arguments, not all bundled up in a list.
>
> If only we could delete those brackets around [1 2 3 4 5]...  If only we 
> had some sort of "adapter" that could take a list/vector of items, and pass 
> them in as multiple arguments to a function that was designed to take 
> multiple arguments...
>
> That is what apply does.
>
> (apply + [1 2 3 4 5]) turns into
> (+ 1 2 3 4 5)
>
> Similarly,
> (apply str [\a \b \c \d]) turns into
> (str \a \b \c \d)
>
>
>

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

2012-12-16 Thread Marko Topolnik
On Sunday, December 16, 2012 5:12:36 AM UTC+1, Armando Blancas wrote:

> Why are you using puzzler's account and what did you did to him?!
>

And who, in your opinion, is puzzler, if not Mark Engelberg?
 

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