debug-repl now uses defmacro's new implicit &env arg

2010-02-01 Thread George Jahad
I've also added an (exit-dr) function that allows you to exit the
debug-repl all the way, if you are nested many levels.

You can get it here:

http://clojars.org/org.clojars.gjahad/debug-repl

(Use the "0.2.0-SNAPSHOT" of the debug-repl if you are not using the
latest Clojure with the new &env arg)

To use it, just add "(use 'alex-and-georges.debug-repl)" to your file,
and insert the "(debug-repl)" command wherever you'd like to see it
pop up.

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

2010-02-01 Thread ataggart
You can generate a Java class with a main method (as you have done),
or you can use clojure.main:

http://clojure.org/repl_and_main


On Jan 31, 2:32 pm, Wardrop  wrote:
> I'm having trouble finding any resources on the net for telling me how
> to initiate a Clojure application. I'm currently using Netbeans with a
> Clojure plugin, and from what I gather from one of the examples, I
> need to define a main function as the launching point for my app, but
> there seems to be a little more to it.
>
> The only example code I've found which works is this...
>
> (ns localhost.test
>     (:gen-class))
>
> (defn -main
>     ([greetee]
>   (println (str "Hello " greetee "!")))
>   ([] (-main "world")))
>
> Could someone step me through the idea behind the -main function
> (which I've also seen written as just "main" without the hyphen). I'm
> new to the JVM so I'm basically learning both Clojure and the workings
> of the JVM at the same time.

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


Transients question/feedback

2010-02-01 Thread Moss Prescott
Hi,

As a very green Clojure user and a big fan of persistent data
structures, I'm struggling to grasp the significance of transients in
Clojure 1.1. In particular, the implementation seems to be less safe
and less consistent than it could be.

Consider this somewhat silly REPL session:

user=> (def t (transient []))
#'user/t
user=> (def t2 (conj! t 1))
#'user/t2
user=> (def t3 (conj! t2 2))
#'user/t3
user=> (persistent! t)
[1 2]

This corresponds to an equivalent interaction with a persistent vector
until the last line, when the original vector is made persistent, and
is found to contain the elements that were conj!-ed onto the later
versions! The problem is that each conj! operation mutates the data
structure, but leaves the old reference to it around:

user=> t
#
user=> t2
#
user=> t3
#

(note: all three names refer to the same object)

This means that although a properly "functional" vector-building
sequence will do the right thing (that is, the same thing it would do
with a persistent vector), if your code is not "correct" you get not a
failure, but a different result than you would otherwise. In the above
example, the final result is [1,2] instead of []. I think a non-silly
example could probably be constructed, where this kind of thing
happens for a better reason (say, if you build a vector by visiting
some other data structure, get to the end and for some reason end up
returning the version before you added the last element -- which might
be the easiest way to do it in some cases and works perfectly well if
you're using regular persistent vectors).

My question is: why not have each conj! produce a new, lightweight
TransientVector instance pointing to the same shared data? The
previous instance would be marked as dead, in the same way as the
single instance is currently made a zombie when persistent! is finally
called. The result would be that as soon as the program deviated from
single-path usage of the transient, an exception would immediately be
thrown. This would signal the programmer that either the code has a
bug or it simply isn't suited to use transients.

My guess is that the resulting ephemeral garbage would have only a
small effect on performance, retaining most of the advantage of
transients, but improving their safety. Would any of the Clojure
experts care to comment on whether this seems like a worthwhile
exercise?

I don't think it would be hard for someone more familiar with the
implementation to prototype this, and I'd be very interested in a
report of how well it works and any performance impact. If no one
bites, I'll probably eventually get around to giving it a try, in
which case I'll definitely post my observations.

- moss

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

2010-02-01 Thread Erik Price
On Sun, Jan 31, 2010 at 10:33 PM, Barry Dahlberg
 wrote:
> Perhaps I'll write up my findings once the language stops intimidating
> me.
>
> At the moment I'm writing an account "object".  I have some standard
> CRUD type functions which operate on a map behind the scenes.  I would
> like to add some metadata to start specifying rules for validation, UI
> generation and so on.  The trouble is I can't really figure out where
> to attach this metadata as I don't have a type definition as such,
> e.g. I would do this in C#:
>
>    [Required, MaxLength(50)]
>    public string Name { get; set; }
>
> defstruct seems promising though I can't find an example with
> metadata.
>
> Any pointers of where to start looking?

You can attach metadata to Clojure constructs using the with-meta function:

user=> (def x {:name "Frank"})
#'user/x
user=> (def x-with-metadata (with-meta x {:RequiredParameter true,
:MaxLength 50}))
#'user/x-with-metadata
user=> (:MaxLength (meta x-with-metadata))
50

As for whether you want to define the metadata directly on your map,
or on functions that construct/operate on your map, or somewhere else,
that's your design decision.

e

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

2010-02-01 Thread Stuart Halloway

My guess is that the resulting ephemeral garbage would have only a
small effect on performance, retaining most of the advantage of
transients, but improving their safety. Would any of the Clojure
experts care to comment on whether this seems like a worthwhile
exercise?


Having spent a ton of hours last week tuning an app to remove  
ephemeral garbage, I am glad that Clojure doesn't make any more than  
it does. That said, I want to move toward having separate debug   
builds (of Clojure itself, and of my own code), and this kind of thing  
might be a good candidate for the debug build.


The next task for enabling debug builds is for someone with ant and  
maven fu to light the path for propagating the clojure.debug property  
[1] through the various builds and generated artifacts. Volunteers  
wanted. Feel free to contact me directly to discuss approach.


Stu

[1] http://www.assembla.com/spaces/clojure/tickets/250

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

2010-02-01 Thread Joop Kiefte
If you are the copyright owner, you always have the final word on what
you do with your stuff. The license is for users of your product. This
means you can arrange another license for paying people if you want,
this is what is done when dual-licensing.

If you reuse things of other people however, this must be in consent
with those licenses.

Please correct me if I'm wrong.

2010/2/1 Richard Lyman :
> I have a few questions I'm hoping to get some feedback on.
>
>
>  = Releasing source code =
> If I understand the EPL 1.0 correctly, under section 3(b) part IV, I'm
> forced to release my source code - right?
>
> I _cannot_ just release an AOT JAR under the EPL 1.0 and keep the source
> code under a different licence - right?
>
> Or does that only apply to everyone _other_ that the initial Contributor?
>
>
>  = Other's commercial profit =
> Under 2(a) and 2(b) I've pretty much given each Recipient full patent and
> copyright permissions. There's nothing available to me if I want to profit
> from it in the future. I have to change the license on some future release,
> and even then they still would have the full permissions I had granted in
> some past release - right?
>
> Under 2(c), even though I've given the permissions I can, the Recipient
> still might not be able to distribute my Contribution if my Contribution
> infringes some third party patent for which the Recipient is required to
> secure any rights that might be necessary. It seems odd that there could
> still be some loophole... some way that I could benefit from the third-party
> patent licensing - right?
>
>
> This has been a fairly painful process for me, thanks for any helpful
> feedback.
> -Rich
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
Communication is essential. So we need decent tools when communication
is lacking, when language capability is hard to acquire...

- http://esperanto.net  - http://esperanto-jongeren.nl

Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004

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

2010-02-01 Thread Timothy Pratley
> Am 31.01.2010 um 18:29 schrieb Daniel Werner:
>> If I understand this arity version of get-in correctly, won't the
>> default also be used if the value stored in the nested data structure
>> evaluates to something false-y?

Thanks for spotting that early!


On 1 February 2010 05:46, Meikel Brandmeyer  wrote:
> (if-let [l (reduce get m (pop ks))]
>  (get l (peek ks) not-found)
>  not-found))

Good idea, but peek and pop work differently on vectors and sequences,
seeing get-in is not constrained to use vectors this could lead to an
unexpected behavior:
user=> (def m  {:a 1, :b 2, :c {:d 3, :e 4}, :f nil})
#'user/m
user=> (get-in3 m '(:c :e) 2)   ;peek-pop keys applied in unexpected order
2
user=> (get-in2 m '(:c :e) 2)   ;expected result
4

I've replaced the patch on assembla with this:
   (reduce #(get %1 %2 not-found) m ks)))
And added test cases for the falsey returns and seq args



Regards,
Tim.

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

2010-02-01 Thread Timothy Pratley
On 1 February 2010 09:32, Wardrop  wrote:
> Could someone step me through the idea behind the -main function
> (which I've also seen written as just "main" without the hyphen).

Is "-main" special in any way, or is this just a convention that some
environments select? In the past I think I've used a manifest to
specify the main entry point... is that really necessary or does -main
map to the default main entry point regardless of build tool? Just
curious really!

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

2010-02-01 Thread Meikel Brandmeyer
Hi,

On Feb 1, 1:57 pm, Timothy Pratley  wrote:

> Good idea, but peek and pop work differently on vectors and sequences,
> seeing get-in is not constrained to use vectors this could lead to an
> unexpected behavior:
> user=> (def m  {:a 1, :b 2, :c {:d 3, :e 4}, :f nil})
> #'user/m
> user=> (get-in3 m '(:c :e) 2)   ;peek-pop keys applied in unexpected order
> 2
> user=> (get-in2 m '(:c :e) 2)   ;expected result
> 4

o.O Ok... 100% of my use-cases for get-in were with vectors up to now.
Didn't think about the allowing lists also.

> I've replaced the patch on assembla with this:
>    (reduce #(get %1 %2 not-found) m ks)))
> And added test cases for the falsey returns and seq args

Consider this (admittedly constructed) case:

(get-in {:a {:b 1}} [:x :c] {:c :uhoh})

I would not mind only allowing vectors in the interface. I would
expect the length of such a chain sufficiently short for easy
conversion if necessary. Or to use butlast/last instead of peek/pop.
Again the "damage" would be limited by the short keychain length.
(Of course it would have to be considered: is the usual keychain
really short?)

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: How to Initiate Clojure Application

2010-02-01 Thread Jarkko Oranen


On Feb 1, 3:16 pm, Timothy Pratley  wrote:
> On 1 February 2010 09:32, Wardrop  wrote:
>
> > Could someone step me through the idea behind the -main function
> > (which I've also seen written as just "main" without the hyphen).
>
> Is "-main" special in any way, or is this just a convention that some
> environments select? In the past I think I've used a manifest to
> specify the main entry point... is that really necessary or does -main
> map to the default main entry point regardless of build tool? Just
> curious really!

-main is only special in that it maps to the 'main' method which the
JVM considers the main entry point of a class

The dash is the default gen-class prefix for functions that should be
used as the implementation of a method. You can specify another prefix
in the :gen-class form using the :prefix option.

--
Jarkko

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

2010-02-01 Thread mac
> Is "-main" special in any way, or is this just a convention that some
> environments select? In the past I think I've used a manifest to
> specify the main entry point... is that really necessary or does -main
> map to the default main entry point regardless of build tool? Just
> curious really!

I think the gen-class generated class looks up and calls -main from
it's main, which is the regular java main.
The manifest file in a jar is not really related to that. All the
manifest does is tell which class' main method to use if someone tries
to run the jar with the -jar command line option (which I don't
recommend because it nukes your classpath, doing a -cp and specifying
your main class is often better).

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

2010-02-01 Thread Michał Marczyk
On 30 January 2010 02:35, Michał Marczyk  wrote:
> Well, with sources freshly pulled from github just now, I was able to
> build contrib with no trace of the problem... Doing a (require
> 'clojure.contrib.jmx) followed by run-tests at the REPL also works.
> Still no idea what it was about, hoping it's gone for good.

Oh bother, what a blunder... Please disregard the above, c.c.jmx is
still broken for me. The bit about me not having any idea as to what's
this about still holds, though.

I guess at some point I'll try to investigate this, but I don't expect
to be able to spare the time for the next week or two. Here's hoping
this will go away in the meantime.

Sincerely,
Michal

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

2010-02-01 Thread Stuart Halloway
The official JMX API is a programmer-usability disaster (IMO), and I  
wrote the contrib jmx wrapper by trial-and-error to get minimal  
functionality working. A few thoughts:


* I will take a look at this (but won't be able to get to it today).  
Feel free to make assembla guilt that points to me.
* My interest in having JMX support work is > my need to continue to  
own it. I will have no hurt feelings if somebody jumps in and owns  
this before I get to it.


Stu

On 30 January 2010 02:35, Michał Marczyk   
wrote:

Well, with sources freshly pulled from github just now, I was able to
build contrib with no trace of the problem... Doing a (require
'clojure.contrib.jmx) followed by run-tests at the REPL also works.
Still no idea what it was about, hoping it's gone for good.


Oh bother, what a blunder... Please disregard the above, c.c.jmx is
still broken for me. The bit about me not having any idea as to what's
this about still holds, though.

I guess at some point I'll try to investigate this, but I don't expect
to be able to spare the time for the next week or two. Here's hoping
this will go away in the meantime.

Sincerely,
Michal

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

To unsubscribe from 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: clojure.contrib compile fail

2010-02-01 Thread Jeff Schwab

Stuart Sierra wrote:

On Jan 30, 9:07 am, Jeff Schwab  wrote:



The clojure-contrib I just pulled from github fails to compile, with an
error that the ColumnWriter class extended by PrintWriter is not found.



This has been fixed now.


Thanks.  I see that you made an end-run around Maven.  I didn't know you 
could use gen-class that way.


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


file-seq and recursive directories

2010-02-01 Thread Jim Van Donsel
The simple:

 (file-seq (java.io.File. "."))

will loop forever if it hits a directory structure with recursive
links.

Short of writing ugly code myself to detect such loops, is there
already a Clojure thingamabob that does this safely?

-Jim





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


Re: making instances of a parameterised class...efficiently...

2010-02-01 Thread Jules
Guys,

Thanks for your answers.

I'll give both of these solutions a try out this week and get back to
the list with results and thoughts.

Thanks again for your help.

Jules

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

2010-02-01 Thread Sudish Joseph
Moss Prescott  writes:
> My guess is that the resulting ephemeral garbage would have only a
> small effect on performance

An interesting data point on ephemeral garbage that was quite
eye-opening: Somewhere in the talk below, Cliff Click says that the
problem with high-volume ephemeral garbage lies in the cache trashing
behavior of "streaming allocation" -- which itself results from the
JVM's neat pointer-bumping allocator being used to allocate lots of
highly ephemeral garbage.

http://www.infoq.com/presentations/click-fast-bytecodes-funny-languages

-- 
Sudish Joseph

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

2010-02-01 Thread Stuart Sierra
On Feb 1, 10:53 am, Jeff Schwab  wrote:
> Thanks.  I see that you made an end-run around Maven.  I didn't know you
> could use gen-class that way.

It's more an end-run around gen-class than around Maven.

gen-class is an ordinary macro; it can be used anywhere, not just in
ns declarations.

Putting all the gen-class directives in a separate file is a technique
I have used before to make sure that the classes get generated in the
right order.

-SS

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

2010-02-01 Thread Sean Devlin
Hmmm... to the best of my knowledge this has to be handled by the end
developer.

Could you post what you find out?

Sean

On Feb 1, 9:22 am, Jim Van Donsel  wrote:
> The simple:
>
>      (file-seq (java.io.File. "."))
>
> will loop forever if it hits a directory structure with recursive
> links.
>
> Short of writing ugly code myself to detect such loops, is there
> already a Clojure thingamabob that does this safely?
>
> -Jim

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


Re: return value of use, requires?

2010-02-01 Thread Raoul Duke
On Fri, Jan 29, 2010 at 9:29 PM, Timothy Pratley
 wrote:
> Would it be better to throw an exception if nothing was specified to
> load instead of returning true/false... Because :foo is a keyword,
> making it a valid argument to use and require, but no load target is
> specified. I've uploaded a patch to the ticket Raoul created:
> https://www.assembla.com/spaces/clojure/tickets/253-Improve-errors-for--use---require--in-REPL

sounds to me like a good change. (i think in an ideal world, the
system would have error messages that explain more verbosely what
happened. like that the given keyword isn't one that is supported, or
no load target given, etc., but that requires a little more serious
usability care and study to get right.)

sincerely.

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


Contrib library renames

2010-02-01 Thread Stuart Sierra
As the first stage in a much-needed code cleanup, the following
changes are now on the "master" branch of clojure-contrib:

* Rename c.c.str-utils3 => c.c.string
* Rename c.c.duck-streams => c.c.io
* Rename c.c.java-utils => c.c.java
* Rename c.c.seq-utils => c.c.seq
* Rename c.c.shell-out => c.c.shell

* Delete c.c.str-utils and c.c.str-utils2 (both replaced by c.c.string)
* Delete c.c.json.read and c.c.json.write (both replaced by c.c.json)

* Rename all test namespaces like clojure.contrib.test-**

All internal uses of these namespaces should be correct, and all tests
pass.  Please report any problems.

If you need the old names, please use the 1.1.0 release of
clojure-contrib, available via build.clojure.org and Google Code.

-SS

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

2010-02-01 Thread Daniel Werner
On Jan 30, 8:09 am, Timothy Pratley  wrote:
> Below I present 'submit-future' which is similar to the existing
> 'future' call in that it spawns a thread to execute a task, but
> differs in that it will block if n submitted futures are already
> running, where n is the number of available processors. I think this
> could be quite handy for the producer-consumer model which lazy-seq
> lends itself to, allowing one to write:

This looks like it could become really useful in the future (no pun
intended), thanks for sharing! Instead of enforcing its own thread
count limit, however, it might be worthwhile to interface with the
Agent thread pool. Otherwise, in the worst case a machine with N cores
could try to run N+2 agent threads and N+2 future-submit threads at
once. That said, I'm not sure about the consequences of the Agent
thread pool being saturated by copious use of future-submit.

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

2010-02-01 Thread Daniel Werner
On Jan 30, 7:07 am, free_variation  wrote:
> (defn init-features [stream]
> (let [feature-stream (ref stream)]
> (dosync (ref-set feature-stream stream))

The call to ref-set seems redundant here since you already initialize
the ref with stream as its value.

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

2010-02-01 Thread Barry Dahlberg
I wrote something like this last night:

(def user-metadata {:fields
  ((:name (required) (max-length 50))
   (:email (required) (max-length 250)))})

(defn create-user [name, email]
  (with-meta
{:name name :email email}
user-data))

I have a validate function which pulls the metadata from a given
instance and I can also access user-metadata directly for generating
UI forms and so on.  The required and max-length functions each
generate little validators which have a predicate, error message
formatter etc.

Is this sensible Clojure?

Cheers
Barry

Am

On Feb 2, 12:53 am, Erik Price  wrote:
> On Sun, Jan 31, 2010 at 10:33 PM, Barry Dahlberg
>
>
>
>  wrote:
> > Perhaps I'll write up my findings once the language stops intimidating
> > me.
>
> > At the moment I'm writing an account "object".  I have some standard
> > CRUD type functions which operate on a map behind the scenes.  I would
> > like to add some metadata to start specifying rules for validation, UI
> > generation and so on.  The trouble is I can't really figure out where
> > to attach this metadata as I don't have a type definition as such,
> > e.g. I would do this in C#:
>
> >    [Required, MaxLength(50)]
> >    public string Name { get; set; }
>
> > defstruct seems promising though I can't find an example with
> > metadata.
>
> > Any pointers of where to start looking?
>
> You can attach metadata to Clojure constructs using the with-meta function:
>
> user=> (def x {:name "Frank"})
> #'user/x
> user=> (def x-with-metadata (with-meta x {:RequiredParameter true,
> :MaxLength 50}))
> #'user/x-with-metadata
> user=> (:MaxLength (meta x-with-metadata))
> 50
>
> As for whether you want to define the metadata directly on your map,
> or on functions that construct/operate on your map, or somewhere else,
> that's your design decision.
>
> e

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

2010-02-01 Thread ataggart


On Feb 1, 6:22 am, Jim Van Donsel  wrote:
> The simple:
>
>      (file-seq (java.io.File. "."))
>
> will loop forever if it hits a directory structure with recursive
> links.
>
> Short of writing ugly code myself to detect such loops, is there
> already a Clojure thingamabob that does this safely?
>
> -Jim

It's not clear to me what a default solution should be when one seqs
over a cycle, other than continue on indefinitely.

As Sean says, the "solution" is whatever fits your particular
situation.  That said, you can use (.getCanonicalPath dir) to obtain a
unique string path for that directory.

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

2010-02-01 Thread Jim Van Donsel
Fair enough.

But I guess the moral is that a file-seq should not be used unless you
have a well-controlled filesystem.

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

2010-02-01 Thread ataggart


On Feb 1, 2:14 pm, Jim Van Donsel  wrote:
> Fair enough.
>
> But I guess the moral is that a file-seq should not be used unless you
> have a well-controlled filesystem.

Or more generally, all sequences may be infinite unless you know the
backing data has no cycles, or you have some terminating/filtering
conditions.

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

2010-02-01 Thread Wardrop
Ok, this seems to work...

(ns localhost.test)

(clojure.main/main (println "Hello!"))

I then assume I'd use the special form "do" to perform multiple
unrelated tasks, such as...

(clojure.main/main
  (do
(println "Hello!") (println "Cheeso!")))

At least I can now build and run a script.

On Feb 1, 6:40 pm, ataggart  wrote:
> You can generate a Java class with a main method (as you have done),
> or you can use clojure.main:
>
> http://clojure.org/repl_and_main
>
> On Jan 31, 2:32 pm, Wardrop  wrote:
>
> > I'm having trouble finding any resources on the net for telling me how
> > to initiate a Clojure application. I'm currently using Netbeans with a
> > Clojure plugin, and from what I gather from one of the examples, I
> > need to define a main function as the launching point for my app, but
> > there seems to be a little more to it.
>
> > The only example code I've found which works is this...
>
> > (ns localhost.test
> >     (:gen-class))
>
> > (defn -main
> >     ([greetee]
> >   (println (str "Hello " greetee "!")))
> >   ([] (-main "world")))
>
> > Could someone step me through the idea behind the -main function
> > (which I've also seen written as just "main" without the hyphen). I'm
> > new to the JVM so I'm basically learning both Clojure and the workings
> > of the JVM at the same time.

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


Newbie question - Functional programming & special cases

2010-02-01 Thread ka
Hi clojure folk,

I'm reading up on clojure from the book 'Programming clojure'.  In
chapter 2 there is a statement -

"The imperative indexOfAny must deal with several special cases:
null or empty strings, a null or empty set of search characters,
and the absence of a match. These special cases add branches
and exits to the method. With a functional approach, most of these
kinds of special cases just work without any explicit code."

I'm not quite sure if I understand this properly. How is it that with
a functional approach, most of these special cases like null checks or
empty checks get handled automatically?  I mean isn't that a property
of the language / api rather than the programming approach per se?
Please explain with some examples!

On a similar note, following is the definition of the function index-
filter given in the book :-

(defn index-filter [pred coll]
  (when pred
(for [[idx elt] (indexed coll) :when (pred elt)] idx)))

Why is the 'when pred' check necessary?

Thanks!

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


h4dev.com: Searchable database for clojure development topics

2010-02-01 Thread Gene Tani
http://h4dev.com/entries?search=multimethods

Using the major search engines for info on clojure language, tools and
dev practices is trying at best for beginning and intermediate devs,
so I've worked toward building a searchable database that I think will
yield more precision at the cost of less recall, i.e. more usable /
relevant hits per page but not up to the minute like google.  I've
used different heuristics to screen /sample the universe of URL's
talking about clojure (google group, IRC channel, blogs), build a
topic map, and extract text from those source docs to the topic map.

At present, i'm hitting the database against 2 fulltext indexers,
Sphinx and ferret.  These indexers have a rough time with words like
macro, i.e. you'll get different results with "debug macro" "debug
macros" and "debug macro's", so, uh, keep trying. I would get better
results with SOLR instead of ferret, just that my little $20/month VPS
won't run mysql, tomcat and rails very well.

So i'd like people to try it out, give me feedback (yah, the
stylesheet and UI need work).  For now i'm focused on the language and
implementation, less focused on IDE's/editors, web app frameworks,
ORM's, leiningen, incanter, stuff like that.

 I'm collecting the raw data for people that want it, it'll have the
Creative commons license when i figure that out, email me if you'd
like to have 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: more lazy "fun"

2010-02-01 Thread rzeze...@gmail.com


On Jan 28, 3:26 pm, Raoul Duke  wrote:
> [gmail is freaking out, apologies if this is sent twice]
>
> On Thu, Jan 28, 2010 at 12:23 PM, DanL  wrote:
> > When exactly would a lazy sequence evaluate to false?
>
> i thought it was happening with code like:
>
> (let [final-answer (and (map #(= "foo" %) ["foo" "bar"]))]
>  (if final-answer "yay" "humbug"))
>
> in a larger routine. it wasn't doing what i expected from my tests,
> and when i put in a println then it suddenly worked. which led me to
> figure it was something about laziness. changing the if to read
>
>  (if (vec final-answer) ...)
>
> fixed it.
>
> ?

Raoul, I think if you evaluate this code piece-by-piece the behavior
will become more clear.  From your example I feel like you are trying
to determine if all elements in a given collection/sequence are of the
value "foo?"

Start from the inside and work your way out.

user> (map #(= "foo" %) ["foo" "bar"])
(true false)

So here we returned a lazy seq of boolean values based on the
anonymous function being used as a predicate.

user> (and (map #(= "foo" %) ["foo" "bar"]))
(true false)

Now we pass the result to and, but yet the same result is returned.
>From what I can tell you expected and to make sure all values in this
sequence were true, but lets look at the doc string.

user> (doc and)
-
clojure.core/and
([] [x] [x & next])
Macro
  Evaluates exprs one at a time, from left to right. If a form
  returns logical false (nil or false), and returns that value and
  doesn't evaluate any of the other expressions, otherwise it returns
  the value of the last expr. (and) returns true.
nil


Notice that and is a macro and that it doesn't expect a sequence as
argument, but rather 0 to multiple expressions (also note that the doc
string appears to have a typo or some sort).  So the seq you passed
and is treated as one expression, and that expression is treated as
true, and it is the last expression so it is returned.  To summarize,
the and function simply returned the same exact sequence that it was
passed in the first place.

The reason "yay" is returned is because a seq will evaluate to true.

user> (if '(true false) "yay" "humbug")
"yay"
user> (if '() "yay" "humbug")
"yay"
user> (if '(nil) "yay" "humbug")
"yay"
user> (if nil "yay" "humbug")
"humbug"


I'm not sure how calling vec on final-answer "fixed" your problem
unless there is some code you are not showing.

user> (if (vec '(true false)) "yay" "humbug")
"yay"
user> (if (vec '()) "yay" "humbug")
"yay"
user> (if (vec nil) "yay" "humbug")
"yay"


However, the following will work.

user> (every? (partial = "foo") ["foo" "bar"])
false

I think the problem was more of a misunderstanding with the and
function and not lazy sequences.

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

2010-02-01 Thread Raoul Duke
On Mon, Feb 1, 2010 at 3:20 PM, rzeze...@gmail.com  wrote:
> I think the problem was more of a misunderstanding with the and
> function and not lazy sequences.

i agree (hence my previous note where i said i didn't know what the
hell i was doing) :-)

many thanks for taking the time to dismember it, it helps me to learn.

sincerely.

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

2010-02-01 Thread Timothy Pratley
On 2 February 2010 00:18, Meikel Brandmeyer  wrote:
> Consider this (admittedly constructed) case:
> (get-in {:a {:b 1}} [:x :c] {:c :uhoh})

Excellent point!


> Or to use butlast/last instead of peek/pop.

I think this is the best approach. butlast/last have linear time so
the overhead is small.

There are still some sharp edges I'm not sure about:
(A) user=> (get-in {:a 1} [])
{:a 1}
;; this is existing behavior, but I feel the result should be nil

(B) user=> (get-in {:a 1} nil)
{:a 1}
;; this is existing behavior, but I feel the result should be nil (nil
is a seq so not an exception)

(C) user=> (get-in {:a 1} 5)
java.lang.IllegalArgumentException: Don't know how to create ISeq
from: java.lang.Integer (NO_SOURCE_FILE:0)
;; existing behavior, seems sensible to throw an exception here rather
than return nil

(D) user=> (get-in {nil {:a 1}} [] 2)
{:a 1}
;; new behavior
;; using last/butlast only -> this is wrong... need to check the seq size
;; the solution depends upon what is correct for the preceding cases
so need to establish those first

Alternatively one could take the view that [] and nil are illegal key
sequences, in which case should get-in enforce that (via preconditions
or just a check) or should it just be added to the doc-string that
using those values is undefined, or both?

I've marked the ticket back to new in the meantime... will update once resolved.


For reference here is a version that behaves most like existing get-in:

(defn get-in
  "Returns the value in a nested associative structure,
  where ks is a sequence of keys. Returns nil if the key is not present,
  or the not-found value if supplied."
  ([m ks]
   (reduce get m ks))
  ([m ks not-found]
   (if (empty? ks)
 m
 (if-let [l (reduce get m (butlast ks))]
   (get l (last ks) not-found)
   not-found

I'm not convinced returning the map when given an empty key sequence
is the right thing to do, I'd prefer it to return nil or throw an
exception in both arity cases.


Regards,
Tim.

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

2010-02-01 Thread CuppoJava
Hi ka,
You're right. Eliminating special cases is more a factor of the design
of the API than of the programming language. Nevertheless, a well-
designed API (that has eliminating special cases in mind) in
combination with a functional programming language makes your code
extremely elegant. Thus many API's for functional languages put
considerable thought into this issue.

The (pred) issue you point out is a good one:
if pred is nil: then (pred elt) results in an error because nil cannot
be called as a function.
This (when pred...) is necessary.

You can surmise that Rich could have hypothetically designed Clojure
such that nil will return "nil" when called as a function, thus
eliminating the need for the special case check. But this opens up
more opportunity for shooting yourself in the foot later, thus the
current scheme is a nice balance between elegance and safety.

Enjoy Clojure!
  -Patrick

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

2010-02-01 Thread Richard Newman

My question is: why not have each conj! produce a new, lightweight
TransientVector instance pointing to the same shared data?


...


My guess is that the resulting ephemeral garbage would have only a
small effect on performance, retaining most of the advantage of
transients, but improving their safety. Would any of the Clojure
experts care to comment on whether this seems like a worthwhile
exercise?


(Not that I'd call myself a "Clojure expert", but...)

Transients are used all over the place, including in Clojure's own non- 
transient functions (such as merge).


If you're adding a new TransientVector instance on every call to  
conj!, you might as well just use conj.


Making transients slower -- even by a small amount -- strikes me as  
contrary to Rich's position. After all, transients are meant to be an  
optimization technique: write your code with persistent data  
structures, and if you find yourself banging on a chain of maps, say,  
add some !s, transients, and persistent!s, and you'll see a  
performance gain. They should never leave the scope of a particular  
function (or small group of functions), and by the time you're done  
writing you should make sure that you got it right.


Making them safer is analogous to asking for checks to be added to  
unchecked math operations.


You should *never* be shoving transients into vars, IMO.

That said, I agree with Stuart that a "debug" level of Clojure might  
be useful, making the "get it right" part easier. I don't favor a  
separate build, unless it's unavoidable: I think that Common Lisp's  
declarations are a reasonable starting point for discussion. Imagine  
if macros could see an environment with speed/space/safety attributes,  
and could generate appropriate code...


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

2010-02-01 Thread free_variation
Urp yes thanks!  Remainder of a previous version of the function.

jds

On Feb 1, 3:57 pm, Daniel Werner 
wrote:
> On Jan 30, 7:07 am, free_variation  wrote:
>
> > (defn init-features [stream]
> >         (let [feature-stream (ref stream)]
> >                 (dosync (ref-set feature-stream stream))
>
> The call to ref-set seems redundant here since you already initialize
> the ref with stream as its value.

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


Lazy (apply concat ...) ?

2010-02-01 Thread CuppoJava
Hi,
I'm wondering whether (apply concat ...) can be re-written to be
lazy.

---Expected behavior---

(def temp (for [i (range 20)]
(do (println i)
[i i i])))

(def temp2 (apply concat temp))

Should print nothing.

-Behavior in 1.1.0-RC-
Under Clojure-1.1.0-rc, the operation was "somewhat" lazy.

Prints:
0
1
2

-Behavior in 1.1.0--
The operation is eager.

Prints:
0
1
2
...
19

-

I'm hoping it's possible to do this as it would be very useful, but
I'm not sure whether the semantics of apply allow this to be done. It
sort of half-worked in 1.1.0-RC so I'm optimistic.


Thanks for your opinions
  -Patrick

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

2010-02-01 Thread Richard Newman

I'm wondering whether (apply concat ...) can be re-written to be
lazy.

...


-Behavior in 1.1.0--
The operation is eager.


It's not: it simply uses chunked sequences, so the first 32 elements  
are evaluated together.


user=> (def temp (for [i (range 50)]
   (do (println i)
   [i i i])))
#'user/temp
user=>
user=> (def temp2 (apply concat temp))
0
1
2
...
30
31

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

2010-02-01 Thread CuppoJava
Oh I see. Thanks for the explanation. I always assumed that chunked
sequences can be viewed as purely an optimization and transparent from
the user. Is there a way (short of writing a lazy version of apply
concat) that I can achieve my desired result?
  -Patrick

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

2010-02-01 Thread Richard Newman

Oh I see. Thanks for the explanation. I always assumed that chunked
sequences can be viewed as purely an optimization and transparent from
the user. Is there a way (short of writing a lazy version of apply
concat) that I can achieve my desired result?


I've heard talk about trying to provide some option for zero-lookahead  
lazy sequences. I don't think any API has been stabilized, though.


One workaround I've used is to use delay to avoid the execution of  
individual elements, but that doesn't really work in this case: you  
need to force them in order to apply concat.


Maybe something like:

(defn force-concat [& xs]
  (when xs
(lazy-seq
  (concat (force (first xs))
  (force-concat (rest xs))

(def temp (for [i (range 50)]
   (delay
 (do (println i)
   [i i i]

(def temp2 (apply force-concat temp))

(println (take 10 temp2))


It behaves oddly on my machine, but I think the principle is sound...

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


idiomatic question about reader macro

2010-02-01 Thread A.Rost
Hi,
I'm a clojure newbie, with a background in Common Lisp (and
functional
languages such as haskell and erlang).

For me Lisp is a very powerful tool that gives me flexibility that I
need. Sometimes coding with CL I define reader macros and they perfect
suit for those situations. After I take a look on Clojure. It's a very
expressive, elegant language, but user-defined reader macro are
prohibited.

I've read all discussions about this. I realize that using user-
defined reader macro can be evil, but I think there is no point to
restrict them. I suppose that using them in the right way can make my
code more expressive and easy to read, though it's not the tool for
every day use and you should think a lot before using it. But I think
that the programmer should choose tools to solve the task. So  I think
it's wrong not to allow user create reader macro.

This is my opinion. Am I wrong? Or there are another reasons not to
use user-defined reader 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


clojure.contrib.[duck-streams io]

2010-02-01 Thread OGINO Masanori
Hello.

I built master branch of clojure and clojure-contrib and then I found
that there is no duck-streams.  io exists.

Can I write a code on both 1.1 and master using duck-streams/io?

FYI, I want something like this Python code in Clojure:

try:
from clojure.contrib.io import reader, writer
except ImportError:
from clojure.contrib.duck-streams import reader, writer

Thanks.

-- 
Name:  OGINO Masanori (荻野 雅紀)
E-mail: masanori.og...@gmail.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: Newbie question - Functional programming & special cases

2010-02-01 Thread Jerome Baum
'when pred' just checks that you're not passing in garbage for the
predicate -- it's probably not really necessary and it might be better
to let Clojure throw an exception.

Totally agree on your point with the branching. That's not really FP-
related, it's only that most FP languages allow pattern matching and
prefer to be "lean" by handling special cases for you.

On Feb 1, 9:53 pm, ka  wrote:
> Hi clojure folk,
>
> I'm reading up on clojure from the book 'Programming clojure'.  In
> chapter 2 there is a statement -
>
> "The imperative indexOfAny must deal with several special cases:
> null or empty strings, a null or empty set of search characters,
> and the absence of a match. These special cases add branches
> and exits to the method. With a functional approach, most of these
> kinds of special cases just work without any explicit code."
>
> I'm not quite sure if I understand this properly. How is it that with
> a functional approach, most of these special cases like null checks or
> empty checks get handled automatically?  I mean isn't that a property
> of the language / api rather than the programming approach per se?
> Please explain with some examples!
>
> On a similar note, following is the definition of the function index-
> filter given in the book :-
>
> (defn index-filter [pred coll]
>   (when pred
>     (for [[idx elt] (indexed coll) :when (pred elt)] idx)))
>
> Why is the 'when pred' check necessary?
>
> Thanks!

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


How to get Clojure.Contrib in my Classpath?

2010-02-01 Thread Wardrop
I can't for the life of me get Clojure.Contrib to work. No matter what
I do, I seem to have it available within clojure. Here's just an
example of what I've been trying when calling the repl from the
command line...

java -classpath "C:\Program Files\Clojure\clojure.jar";"C:\Program
Files\Clojure\clojure-contrib-1.1.0.jar" clojure.main

This starts the repl without a problem, but still, any attempt to use
a class or function from the contrib library fails, for example,
running this at the repl...

(use '[clojure.contrib.duck-streams])

Produces this...

java.io.FileNotFoundException: Could not locate clojure/contrib/
duck_streams__init.class or clojure/contrib/duck_streams.clj on
classpath:  (NO_SOURCE_FILE:0)

Can anyone help?

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


Re: How to get Clojure.Contrib in my Classpath?

2010-02-01 Thread tsuraan
> java -classpath "C:\Program Files\Clojure\clojure.jar";"C:\Program
> Files\Clojure\clojure-contrib-1.1.0.jar" clojure.main
>
> This starts the repl without a problem, but still, any attempt to use
> a class or function from the contrib library fails, for example,
> running this at the repl...

I'm not sure about windows, but under *NIX the classpath is colon
separated.  Maybe using a colon between the two jars instead of a
semicolon would help.

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


Re: h4dev.com: Searchable database for clojure development topics

2010-02-01 Thread Alex Osborne

Gene Tani wrote:

http://h4dev.com/entries?search=multimethods

So i'd like people to try it out, give me feedback (yah, the
stylesheet and UI need work).  For now i'm focused on the language and
implementation, less focused on IDE's/editors, web app frameworks,
ORM's, leiningen, incanter, stuff like that.


Interesting, though I'm having trouble making head or tail of the 
results.  What do all the underscores mean? eg "clojure, pt 2_ vs. 
ruby, python_ _"



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

2010-02-01 Thread CuppoJava
Thanks for the help Richard.

After playing around with 1.1.0 some more (I just upgraded). I'm
finding that the chunked sequences is destroying all my code that
relied on lazy sequences. Isn't the following a pretty standard thing
to do?

(for [i (range 20)]
(do (println i)
[i i i]))

With the addition of chunked sequences, any code that relied upon this
behavior is kaput. (Unless it only needed laziness in batches of 32).

Am I understanding this correctly? It seems laziness is only an option
in batches of 32 now.
  -Patrick

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


Re: How to get Clojure.Contrib in my Classpath?

2010-02-01 Thread Wardrop
I had already tried using a colon as the separator, but it gave an
error. I've also noticed that if neither path resolves to a file, it
also errors, so it's finding clojure-contrib-1.1.0.jar.

On Feb 2, 2:07 pm, tsuraan  wrote:
> > java -classpath "C:\Program Files\Clojure\clojure.jar";"C:\Program
> > Files\Clojure\clojure-contrib-1.1.0.jar" clojure.main
>
> > This starts the repl without a problem, but still, any attempt to use
> > a class or function from the contrib library fails, for example,
> > running this at the repl...
>
> I'm not sure about windows, but under *NIX the classpath is colon
> separated.  Maybe using a colon between the two jars instead of a
> semicolon would help.

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


Re: Lazy (apply concat ...) ?

2010-02-01 Thread Richard Newman

Am I understanding this correctly? It seems laziness is only an option
in batches of 32 now.


Indeed. *Processing* *chunked* lazy sequences can only be done in  
batches of 32.


Custom lazy sequences (using (lazy-seq ...)) don't suffer from this.

You might be interested in this blog post:

http://blog.fogus.me/2010/01/22/de-chunkifying-sequences-in-clojure/

and

http://clojure-log.n01se.net/date/2010-01-22.html#15:01

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


Deadline Extended to Feb. 15: IEEE Software Multi-Paradigm Programming Special Issue - Sep/Oct 2010

2010-02-01 Thread Dean Wampler
Hi,

Sorry for the repeat emails. We have extended the deadline for submissions
for this special issue. It is now February 15th. If you thought about
submitting a paper, but didn't think you could make the original deadline,
we hope you will reconsider.

http://www.computer.org/portal/web/computingnow/swcfp5

Yours,
dean

Dean Wampler, Ph.D.
d...@polyglotprogramming.com

co-author: "Programming Scala", O'Reilly:
 - http://programmingscala.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: How to get Clojure.Contrib in my Classpath?

2010-02-01 Thread tsuraan
> I had already tried using a colon as the separator, but it gave an
> error. I've also noticed that if neither path resolves to a file, it
> also errors, so it's finding clojure-contrib-1.1.0.jar.

Can you use it with

(use 'clojure.contrib.duck-streams) ?

Both ways work for me, but it's the only other thought I have.

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


Re: How to get Clojure.Contrib in my Classpath?

2010-02-01 Thread Wardrop
Ok, I found the problem. If quotes need to be used, the all paths
including semi-colons need to be within a single pair of double
quotes. For example...

java -cp "C:\Program Files\Clojure\clojure.jar;C:\Program Files\Clojure
\clojure-contrib-1.1.0.jar" clojure.main

How subtitle is that. If only the "java" commnd prompt provided a
little more help.

On Feb 2, 2:25 pm, Wardrop  wrote:
> I had already tried using a colon as the separator, but it gave an
> error. I've also noticed that if neither path resolves to a file, it
> also errors, so it's finding clojure-contrib-1.1.0.jar.
>
> On Feb 2, 2:07 pm, tsuraan  wrote:
>
> > > java -classpath "C:\Program Files\Clojure\clojure.jar";"C:\Program
> > > Files\Clojure\clojure-contrib-1.1.0.jar" clojure.main
>
> > > This starts the repl without a problem, but still, any attempt to use
> > > a class or function from the contrib library fails, for example,
> > > running this at the repl...
>
> > I'm not sure about windows, but under *NIX the classpath is colon
> > separated.  Maybe using a colon between the two jars instead of a
> > semicolon would help.

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


Re: How to get Clojure.Contrib in my Classpath?

2010-02-01 Thread Wardrop
I better provide credit to this page: 
http://forums.pragprog.com/forums/91/topics/1738

On Feb 2, 2:25 pm, Wardrop  wrote:
> I had already tried using a colon as the separator, but it gave an
> error. I've also noticed that if neither path resolves to a file, it
> also errors, so it's finding clojure-contrib-1.1.0.jar.
>
> On Feb 2, 2:07 pm, tsuraan  wrote:
>
> > > java -classpath "C:\Program Files\Clojure\clojure.jar";"C:\Program
> > > Files\Clojure\clojure-contrib-1.1.0.jar" clojure.main
>
> > > This starts the repl without a problem, but still, any attempt to use
> > > a class or function from the contrib library fails, for example,
> > > running this at the repl...
>
> > I'm not sure about windows, but under *NIX the classpath is colon
> > separated.  Maybe using a colon between the two jars instead of a
> > semicolon would help.

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


Re: Lazy (apply concat ...) ?

2010-02-01 Thread CuppoJava
Thanks for helping me through this Richard. I think I got the gist of
the argument now from the blog post you linked to. Now that I think
about it, *most* code doesn't break with chunked sequences, so that
seems to be alright.

Though generally I prefer following the principle of least-surprise...
I can only imagine trying to teach newcomers about using Clojure
sequences now...

Thanks again
  -Patrick

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

2010-02-01 Thread Meikel Brandmeyer
Hi Timothy,

On Feb 2, 1:19 am, Timothy Pratley  wrote:

> There are still some sharp edges I'm not sure about:
> (A) user=> (get-in {:a 1} [])
> {:a 1}
> ;; this is existing behavior, but I feel the result should be nil

+1 for nil

> (B) user=> (get-in {:a 1} nil)
> {:a 1}
> ;; this is existing behavior, but I feel the result should be nil (nil
> is a seq so not an exception)

+1 for nil

> (C) user=> (get-in {:a 1} 5)
> java.lang.IllegalArgumentException: Don't know how to create ISeq
> from: java.lang.Integer (NO_SOURCE_FILE:0)
> ;; existing behavior, seems sensible to throw an exception here rather
> than return nil

+1 for exception

> (D) user=> (get-in {nil {:a 1}} [] 2)
> {:a 1}
> ;; new behavior
> ;; using last/butlast only -> this is wrong... need to check the seq size
> ;; the solution depends upon what is correct for the preceding cases
> so need to establish those first
>
> Alternatively one could take the view that [] and nil are illegal key
> sequences, in which case should get-in enforce that (via preconditions
> or just a check) or should it just be added to the doc-string that
> using those values is undefined, or both?

I'm not sure about this too. I tend to an exception. (get m) will also
throw an exception...

> For reference here is a version that behaves most like existing get-in:
>
> (defn get-in
>   "Returns the value in a nested associative structure,
>   where ks is a sequence of keys. Returns nil if the key is not present,
>   or the not-found value if supplied."
>   ([m ks]
>    (reduce get m ks))
>   ([m ks not-found]
>    (if (empty? ks)
>      m
>      (if-let [l (reduce get m (butlast ks))]
>        (get l (last ks) not-found)
>        not-found

I would get rid of the if-let. Together with throwing an exception in
case of an empty key sequence we get:

(defn get-in
  "Returns the value in a nested associative structure,
  where ks is a sequence of keys. Returns nil if the key is not
present,
  or the not-found value if supplied."
  ([m ks] (get-in m ks nil))
  ([m ks not-found]
   (if-let [ks (seq ks)]
 (get (reduce get m (butlast ks)) (last ks) not-found)
 (throw (Exception. "key sequence must not be empty")

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: update-in and get-in why no default?

2010-02-01 Thread Richard Newman

There are still some sharp edges I'm not sure about:
(A) user=> (get-in {:a 1} [])
{:a 1}
;; this is existing behavior, but I feel the result should be nil


+1 for nil


I think I disagree.

If you view 'get-in' as an unwrapping operation, unwrapping by zero  
steps should return the existing collection, no?


{:foo {:bar {:baz 1}}}

[] => {:foo ...
[:foo] => {:bar ...
[:foo :bar]=> {:baz ...

This maps trivially to a sophisticated user's recursive mental model  
of get-in:


(defn get-in [m ks]
  (loop [looking-at m
 first-key  (first ks)
 remaining-keys (rest ks)]
(if-not first-key
  looking-at
  (recur (get looking-at first-key)
 (first remaining-keys)
 (rest  remaining-keys)

... if there are no keys, it returns m. That's intuitive to me, at  
least.


Can you explain why you think the result should be nil?


(B) user=> (get-in {:a 1} nil)
{:a 1}
;; this is existing behavior, but I feel the result should be nil  
(nil

is a seq so not an exception)


+1 for nil


As above: I equate nil with the empty sequence.

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

2010-02-01 Thread Meikel Brandmeyer
Hi,

On Feb 2, 7:55 am, Richard Newman  wrote:

> I think I disagree. Can you explain why you think the result should be nil?

Woops. I got confused. I didn't mean nil for empty key sequences. I
meant throwing an exception as does get.

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: How to Initiate Clojure Application

2010-02-01 Thread ataggart


On Feb 1, 2:54 pm, Wardrop  wrote:
> Ok, this seems to work...
>
> (ns localhost.test)
>
> (clojure.main/main (println "Hello!"))
>
> I then assume I'd use the special form "do" to perform multiple
> unrelated tasks, such as...
>
> (clojure.main/main
>   (do
>     (println "Hello!") (println "Cheeso!")))
>
> At least I can now build and run a script.

Why are you including clojure.main stuff in your code?  So far as I'm
aware, one uses clojure.main as a means to start a repl, run a clojure
file, etc.  For example, I have the following bash script in a file
named "clj":

CLOJURE_JAR="/usr/local/clojure/clojure.jar"
CONTRIB_JAR="/usr/local/clojure/clojure-contrib.jar"
JLINE_JAR="/usr/local/jline/jline.jar"
CP=".:$CLOJURE_JAR:$CONTRIB_JAR:$JLINE_JAR"
if [ -z "$1" ]; then
java -cp $CP jline.ConsoleRunner clojure.main
else
scriptname=$1
shift
java -cp $CLOJURE_JAR clojure.main $scriptname $*
fi


With that in place, I can just run 'clj' from the command line to open
a repl, or execute a program, e.g.:
$ cat test.clj
(println *command-line-args*)
$ clj test.clj foo bar
(foo bar)

Then I can throw "#! /usr/bin/env clj" at the top of a clj file I want
to have it be executable.

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

2010-02-01 Thread ataggart

De gustibus non est disputandum.

That said, I'd be interested in seeing a clojure example which
benefits from a currently-non-existant reader 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: clojure.contrib.[duck-streams io]

2010-02-01 Thread ataggart


On Feb 1, 6:23 pm, OGINO Masanori  wrote:
> Hello.
>
> I built master branch of clojure and clojure-contrib and then I found
> that there is no duck-streams.  io exists.
>
> Can I write a code on both 1.1 and master using duck-streams/io?
>
> FYI, I want something like this Python code in Clojure:
>
> try:
> from clojure.contrib.io import reader, writer
> except ImportError:
> from clojure.contrib.duck-streams import reader, writer
>
> Thanks.
>
> --
> Name:  OGINO Masanori (荻野 雅紀)
> E-mail: masanori.og...@gmail.com


(try
  (require '(clojure.contrib [io :only [reader writer]]))
  (catch Exception e
(require '(clojure.contrib [duck-streams :only [reader
writer]]

And yes, I had to go through a few iterations 'til I got a version
that worked.

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

2010-02-01 Thread ataggart

On a related note, it is my sincere hope that we get a version of
require and use which no longer require (ha!) the use of quoted
parens.  Thankfully the ns macro will work with solely nested vectors.

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

2010-02-01 Thread Alex Osborne
Tom Hicks  writes:

> I can't seem to do this with the 'inc' function:
>
> user=> (binding [inc (fn [y] (+ 2 y))] (inc 44))
> 45
>
> Why doesn't this work?

See this thread:

http://groups.google.com/group/clojure/browse_thread/thread/d772e114e50aace6

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