Re: Faster application startup for rapid development

2012-05-15 Thread MarkSwanson
> reloading code at the REPL, because old background threads may still be
> running with old code. So I end up restarting the process many times per
> day.

I usually create a 'restart fn that closes down the background threads
and services and restarts them.
This might require you to add a 'shutdown' command to your services
but I've found this to be a small price to pay.

Also, it's some extra code to have threads loop/block on some
condition for 100ms (in debug mode) instead of forever, but this gives
the thread a chance to clean up and terminate every 100ms based on
some condition (set by your restart fn).

Every time you restart your repl you'll wish you had taken the time to
do something like this :-)

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


Re: ANN: Logos v0.6 - Pattern matching, Tabling, Disequality Constraints, and now on Clojars

2011-04-09 Thread MarkSwanson
Fascinating!

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

2011-03-06 Thread MarkSwanson
I use nailgun to solve the jvm startup time. It works very well.

When I'm editing a 'script' in vimclojure I just hit \ef and my 'nail'
is instantly compiled and available at the command line.

It's about as painless as possible.

I do create a small bash wrapper for each clojure script. The bash
script just calls nailgun with the clojure script class and $* to pass
in the 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: ANN: Clojure Cookbook

2010-09-27 Thread MarkSwanson
Nice!

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

2010-08-19 Thread MarkSwanson
Excellent news.

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

2010-07-14 Thread MarkSwanson
I didn't see mention of the new equals/equiv work.
Is this going into a later beta or is this work tentatively going into
a later release?

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

2010-06-25 Thread MarkSwanson
> @Mark S
> Logging is something I've been very interested in at various points in
> the past, usually when an application goes wrong in production and I
> have to figure out what went wrong!
>
> I think we need to discard the notion that logs should be timestamped

I still like timestamps even with per-user logging. Since each user
has its ownfile -mm-dd/userid the timestamp per line only needs to
contain HH:MM:SS.
Each day a new directory/file is created as needed. So log files don't
grow toolarge. Another thread removes dirs/files older than 30 days.

> strings outputted to a file. Instead, I think they should be hash-maps
> we send to a logging server, which then stores them in a database.

I prefer files. Using a DB prevents me from using existing powerful
tools to search and query the logs: vim and emacs.
The nice thing about per-user logging files is that they don't get
that big. They are quick to load/search/analyze.

> You could then visit the database and say "Show me all exceptions that
> occurred for user X". You could then select the field you wanted and
> say "Show me all log messages that occurred within the context of the
> same request as this exception". This is something that would have
> saved me a lot of pain in the past.

Wrt context: per-user logging data is written serially so it's easy to
figure out the context/progression of events that lead up to the
exception. You know where one request starts and ends.

FYI: we use the STM to queue up requests in a map and flush each
user's loggingdata to disk every few seconds.

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

2010-06-24 Thread MarkSwanson

>
> 1. Have you written, or are you writing, a web application that uses
> Clojure? What does it do?

I've created a commercial app that has the server side written start
to finish in Clojure. It leverages the existing calendaring and
scheduling functionality of ScheduleWorld - which was written in Java.
(It was trivial to do this using
Clojure)

http://www.ScheduleWorld.com/em
(It came out of beta last week.)

> 2. Which libraries or frameworks are you using? Which versions?

Compojure - patched from git now and then to work with Clojure 1.2.

> 3. What made you choose Clojure to develop web applications in? What
> are the strengths of Clojure web development?

It's difficult to answer this in a couple of sentences - all of
strengths of Clojure come into play here. Rich's videos that explain
the strengths of Clojure all turn out to be true.
I've been coding enterprise server-side services for ~20 years using C/
C++/Java.
Compared to C/C++/Java I've found the strengths of Clojure beget:

1. better designs
2. less bugs: immutable data, better designs, STM, atoms, ...
3. faster code given the same effort: lazy sequences, memoization,
clojure.[core,contrib],
4. better productivity: the REPL, the Clojure language, etc. it all
snowballs here.

> 4. What do you think are the current weaknesses of web development in
> Clojure? What could be improved?

weaknesses: none really. I sometimes miss the perfect command
completion (with auto import generation) provided by Eclipse/Java when
I do Java interop. But this is an editor issue. (And I'm really happy
with vimclojure.)

Improved: I think I'd be happy with Clojure and Compojure as they
stand for a long time. But since you asked:

LOGGING: The current logging capabilities are not useful to people
creating services with lots of users. The only way logging is useful
is to have one file peruser logging. We wrote our own logging system
that does this and it works great. At midnight the logging system
creates a new directory (based on the date) andstarts using that. So
if someone emails and says at this date/time operation X failed we can
easily analyze the logs around that time.
(A while back ScheduleWorld was signing up 800 people / day with 8000
simultaneous established http connections doing work. Imagine the
intertwined logging data...Per user logging is the best way.)


> 5. Anything else you want to comment on?

Thank you for creating Compojure.
1. defroutes = excellent way of defining our services.
2. decorate = fantastic fine-grained way for us to decorate our
services.
3. requests just have to return a map. Excellent.

Compojure is simple to use and never gets in the way. We have nginx
fronting a cluster of boxes. Our Compojure services respond to
requests, and sometimes theyalso dynamically create and manage static
responses (nginx returns a static file if the request has been seen
before and no other request invalidates the cached response).

(The other Clojure web frameworks might be as good. I don't meant to
take anything away from them. I have only used Compojure.)

Cheers.

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

2010-06-21 Thread MarkSwanson
> available athttp://github.com/ztellman/calx.

Nice!

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

2010-06-20 Thread MarkSwanson
> A flag like *warn-on-boxing* can help to identify these spots. These works 
> for all kind of things. Not only for contrived fact and fib exampls.

+1.
I think something like *warn-on-boxing* would be helpful. I'd use 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: Enhanced Primitive Support

2010-06-18 Thread MarkSwanson
> :s /non-prime/non-primitive/g

Oh, nvm. You were referring to '.

Cheers.

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

2010-06-18 Thread MarkSwanson

> I have to say I'm in the 'pay for what you use' camp - you need a box,  
> you ask for one. If I don't (and neither do any of those loops), why  
> should I have to do extra work to avoid it?

+1

Barely worth mentioning:
:s /non-prime/non-primitive/g

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

2010-05-20 Thread MarkSwanson


On May 20, 10:57 pm, Mibu  wrote:
> I tried to use Long keys from the java.io.File/length method in a hash-
> map and failed to retrieve values using them. sorted-map is fine. The
> doc says hash-maps require keys that support .equals and .hashCode.
> Doesn't Long support those or am I missing something else?

Perhaps you could post a code snippet that shows the problem.
Here's a snippet that shows it works:

Clojure=> (def ml {(long 1) "one"})
Clojure=> (ml (long 1))
"one"

To show you that a Long is really used:
Clojure=> (class (first (keys ml)))
java.lang.Long

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

2010-05-13 Thread MarkSwanson


On May 13, 4:32 pm, Brian Watkins  wrote:
> Okay, I can get that stack trace, but there's no line for clojure.core/
> divide in your trace.  How would I know which function threw the
> exception?  "eval" isn't very useful.  Ideally I'd like a line number,
> too.

Right. It's strange I've never even noticed this before. I guess I've
never needed it.
I can't help with getting 'eval stack trace line numbers, but perhaps
I could suggest a small change to your workflow:
1. Don't use the clojure.main repl to enter a lot of fns. Put
'process, 'some-function, 'higher-up in a file using vim (emacs surely
works very close to this).
2. Use the _editor_ REPL to call (higher-up 12)

This way if there are any errors you'll be able to get the full stack
trace with line numbers.

If there are problems, just switch buffers, edit, \ef, switch back to
the REPL and call (higher-up 12) again. rinse, repeat...

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

2010-05-13 Thread MarkSwanson


On May 13, 6:11 am, Brian Watkins  wrote:
> What is the method that gets line numbers and function names into
> stack traces?  I know I can't get them in the Repl (because there
> aren't any), but I tried loading my file with load-file and that
> doesn't help either.

It's there; Clojure binds the last Exception to *e

http://tech.puredanger.com/2010/02/17/clojure-stack-trace-repl/

user=> (use 'clojure.stacktrace)
nil
user=> (/ 5 0)
java.lang.ArithmeticException: Divide by zero (NO_SOURCE_FILE:0)
user=> (print-stack-trace *e)
clojure.lang.Compiler$CompilerException:
java.lang.ArithmeticException: Divide by zero (NO_SOURCE_FILE:0)
 at clojure.lang.Compiler.eval (Compiler.java:5365)
clojure.lang.Compiler.eval (Compiler.java:5317)
clojure.core/eval (core.clj:2132)
...

I use vimclojure and in its repl embedded inside vim all I have to do
is ,st or ,ct

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

2010-05-06 Thread MarkSwanson
> or as-str from c.c.java-utils (I think)

Good one. It's in string.clj in the latest git.

I've needed this before too. There is so much good stuff in contrib. I
think I have to allocate 30 minutes every day and just try to commit
c.c. to memory.

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


Re: History Question

2010-05-06 Thread MarkSwanson


On May 6, 2:44 pm, Sean Devlin  wrote:
> Okay, next guy to mention name gets shot.  Nothing personal.
>
Ok, but have you considered using name?

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


Re: seq-contains? in practice

2010-04-29 Thread MarkSwanson


On Apr 29, 9:57 am, Stuart Halloway  wrote:
> Agreed: Rich's explanation is the more important bit.
>
> My point is that we may be wasting time arguing about something that  
> nobody actually does. If idiomatic usage changes as the community  
> grows, we *could* add a collection-generic contains.

I think 'nobody' isn't valid here. The small handful of experts who
are crafting contrib is not representable of the Clojure community. I
think that's what Antony meant by 'you're sampling a very small
codebase'.

I humbly submit to you that perhaps you know Clojure too well. You'd
never get confused by this and can't see how anyone else would?

Cheers.

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

2010-04-29 Thread MarkSwanson


On Apr 29, 4:21 am, ataggart  wrote:
> I know it won't matter, but for posterity if nothing else...
>
> Functions named contains-key? and contains-val? would make a lot more
> sense to me than the current contains? and new seq-contains?.  Anyone
> looking at contains-val? should expect it to be O(n).  The only
> effective difference would be that the test value for contains-val? is
> consistently a single value rather than a [key value] tuple for maps.

+1. This is super clear. I find nothing existing or proposed comes
close to this level of clarity.


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

2010-04-24 Thread MarkSwanson
>> You can no
>> longer take a generic approach to information processing. This results
>> in an explosion of needless specificity, and a dearth of reuse."

> For this reason, I've always found appealing languages which let you
> optionally write getter/setter methods that "hook into" the standard
> field access syntax.  This lets you start out with your fields public,
> and let your clients use the standard field access "interface".
> Later, if you realize you need to do something special, you can easily
> add a custom getter without breaking your clients.

I'd argue that leaky abstractions like getter/setter methods are evil,
and a good article (from a Java/imperative perspective) describing why
can be found here:
http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html?page=1

I think that the quote above from Rich is another good description of
why getter/setter methods are bad from a functional perspective.

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

2010-04-22 Thread MarkSwanson
Minor errata barely worth mentioning:on the page: http://clojure.org/datatypes

employeee.getName()

employeee needs just 2 'e' characters.

Cheers.

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

2010-04-09 Thread MarkSwanson
On Apr 9, 9:31 am, Alen Ribic  wrote:
> I came across this 
> posthttp://www.baptiste-wicht.com/2010/04/java-7-more-dynamics/
> and though this would be a good place to share.

The article seems to say that using this API instead of reflection
will make dynamic calls "almost the same as a standard call.".
Fascinating!

I wonder how much work it would be to modify Clojure to use the new
API automatically if it was present in the current JVM.

* Primitive Return Values *

I wondered if this new API could be used to specify primitive return
types so Clojure could be extended to create IFns that return int. I
found a text form of JSR 292 and it contained this gem:
(source: http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/001131.html)

1.3 Any call to a method in Dynamic accepts an optional type
parameter
which specifies the return type of the call site's descriptor.  The
type parameter may any type whatever, including void or a primitive
type.

Lau's latest experiment with fluid dynamics showed a 9794x speed
improvement by using native types for all of his calculations (and by
getting rid of reflection overhead):
http://www.bestinclass.dk/index.php/2010/03/functional-fluid-dynamics-in-clojure/

It looks like we'll soon have the JVM features available to get ~ this
speedup without having to resort to macros or arrays.

The thought of this makes me smile. I wish I wasn't in crunch mode
right now because this would be my personal fun project.

Cheers.

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

To unsubscribe, reply using "remove me" as the subject.


Re: A syntax question: positional & keyword

2010-04-07 Thread MarkSwanson


On Apr 6, 6:23 pm, Stuart Halloway  wrote:
> Have you seen destructuring of rest args in the current master branch?
>
> (defn foo [& {:keys [a b c]}] [a b c])
>
> (foo :a 1 :c 3)
> => [1 nil 3]

... that's beautiful.

I hereby cast my vote into the void: release often; release 1.2
soon. :-)

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

To unsubscribe, reply using "remove me" as the subject.


RFC: Improvements in Clojure error message "No matching ctor for ..."

2010-03-30 Thread MarkSwanson
I think Clojure should provide more information when certain error
conditions occur. Example:

(when-not (= (Integer. (:userid json)) (Integer. (:userid a-user)))

NOTE: (:userid a-user) is always some sort of number.
(:userid json) is always a String.

After testing (Integer. (:userid a-user)) _sometimes_ fails with:
java.lang.IllegalArgumentException: No matching ctor found for class
java.lang.Integer

In this specific case you might argue that I don't know how to compare
two numbers in clojure. And that might be true:-)

In any case, I would find it _really_ helpful to have the (class) of
the arg that failed. I think that this is something that generally all
people using Clojure would be thankful for at one time or another.

In this case, having the (class) would tell me that the failed arg was
java.lang.Long. I'd then know immediately the reason for the problem
and the solution.

Any reason why this does _not_ make sense?


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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


doto doc fix

2010-03-03 Thread MarkSwanson
-  value of x supplied at the from of the given arguments.  The forms
+  value of x supplied at the front of the given arguments.  The forms

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


Re: bug: clojure.contrib.json should not default to use keywords.

2010-03-01 Thread MarkSwanson


On Mar 1, 7:00 am, James Reeves  wrote:
> On Mar 1, 2:19 am, MarkSwanson  wrote:
>
> > For an example outside of JSON: recently Compojure changed how it
> > works so the HTTP request properties are all converted to keywords by
> > default. I can see the appeal, but now anyone using Compojure has the
> > increased incidental complexity of possible keyword violations.
> > Imagine if you were integrating with PayPal or some system that had
> > HTTP parameters with characters that were not allowed by the Clojure
> > spec. I really don't want to worry about such things when creating
> > software with Clojure.
>
> Huh? Compojure has pretty much always used keywords in parameter maps.
> It's certainly not a recent change.

Hmm. I recently upgraded an old Clojure release and Compojure at the
same time and all code that used keywords to access the nice Compojure
data broke.
Regrettably I don't have the same setup available so I can't provide
more details.
It must have been a keyword handling change in Clojure. I find
keywords/map integration much less useful/powerful now with the recent
master branch, but that's a topic for another thread.

Compojure is wonderful btw.

Cheers.

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


Re: bug: clojure.contrib.json should not default to use keywords.

2010-03-01 Thread MarkSwanson
>    separators = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\" |  
> <"> | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HT
>
> As far as I can see, all valid HTTP headers are thus valid Clojure  
> keywords. You don't have to worry.

According to the Clojure reader page SP and HT are not allowed.

Also, I've re-read the reader page and fail to see why you would say
any of the other separators are allowed.

To be sure I'm looking at the correct place, I'm looking at:
http://clojure.org/reader  (Reader forms -> Symbols)

Cheers.

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


Re: bug: clojure.contrib.json should not default to use keywords.

2010-02-28 Thread MarkSwanson


On Feb 28, 10:34 am, joshua-choi  wrote:
> As a small note, according tohttp://clojure.org/reader, Clojure
> keywords and symbols are allowed to contain only alphanumeric
> characters, *, +, !, -, _, and ?. Spaces aren’t allowed, but the
> keyword function allows them anyway because it doesn’t do any checking
> for validity for performance. I’m told that it’s up to the programmer
> to make sure that only valid keywords are created.

Thanks for those details.

> I agree that clojure.contrib.json should default to string keys,
> because keywords are so limited. The thing is, when
> clojure.contrib.json *does* convert JSON keys into Clojure keywords,
> should it check for validity and fail when it cannot create a valid
> keyword?

I personally would really appreciate the check, and fail with a sane
message.

Ultimately, I believe that allowing keywords to be created that
violate the language spec is an error and a meaningful error should be
thrown.
I believe correctness should be more important than speed when core
language functionality is concerned.

The current situation is that I can legally create Clojure structs
that fail to serialize correctly. This is a fundamental component of
the language that simply must work correctly. If not, incidental
complexity is increased.

For an example outside of JSON: recently Compojure changed how it
works so the HTTP request properties are all converted to keywords by
default. I can see the appeal, but now anyone using Compojure has the
increased incidental complexity of possible keyword violations.
Imagine if you were integrating with PayPal or some system that had
HTTP parameters with characters that were not allowed by the Clojure
spec. I really don't want to worry about such things when creating
software with Clojure.

I'm starting to think that perhaps keywords should only be used in
Clojure source code as syntactic sugar to access maps - but the recent
changes to Clojure have made them less useful in this regard because
maps now have to actually contain keywords instead of the keyword name
string.

I think this is something that could be a constant source of
difficulty with Clojure. I'm curious what others think.

Cheers.

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


Re: bug: clojure.contrib.json should not default to use keywords.

2010-02-27 Thread MarkSwanson
Actually, I shouldn't have worded this as a json issue. It's really a
core problem that keywords with spaces can't be serialized/
deserialized.
A keyword is basically a String, and the language definition does not
preclude keywords from having spaces.
(keyword "a b c") works, and so does (get m (keyword "a b c")) - on an
appropriately created map

Cheers.


On Feb 27, 3:55 pm, MarkSwanson  wrote:
> Hello,
>
> Consider the following valid JSON:
>
> Clojure=> (def mq "{\"Question one\":\"test\"}")
> #'user/mq
> Clojure=> (read-json mq)
> {:Question one "test"}
>
> So the default behaviour fails to work correctly for a common case.
>
> The Clojure failure is not exactly obvious either:
>
>  (read-string (str mq))
>
> request failed java.lang.RuntimeException:
> java.lang.ArrayIndexOutOfBoundsException: 19
> at clojure.lang.RT.readString(RT.java:1220)
> at clojure.core$read_string__4163.invoke(core.clj:2517)
>
> I also tried with print-dup and it fails the same way:
> =>(def ms (new StringWriter))
> =>(print-dup mq ms)
> =>(. ms toString)
> "#=(clojure.lang.PersistentArrayMap/create {:Question one \"test\"})"
> =>(read-string (. ms toString))
> # java.lang.ArrayIndexOutOfBoundsException: 3 (REPL:65)>

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


bug: clojure.contrib.json should not default to use keywords.

2010-02-27 Thread MarkSwanson
Hello,

Consider the following valid JSON:

Clojure=> (def mq "{\"Question one\":\"test\"}")
#'user/mq
Clojure=> (read-json mq)
{:Question one "test"}

So the default behaviour fails to work correctly for a common case.

The Clojure failure is not exactly obvious either:

 (read-string (str mq))

request failed java.lang.RuntimeException:
java.lang.ArrayIndexOutOfBoundsException: 19
at clojure.lang.RT.readString(RT.java:1220)
at clojure.core$read_string__4163.invoke(core.clj:2517)

I also tried with print-dup and it fails the same way:
=>(def ms (new StringWriter))
=>(print-dup mq ms)
=>(. ms toString)
"#=(clojure.lang.PersistentArrayMap/create {:Question one \"test\"})"
=>(read-string (. ms toString))
#

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

2009-12-05 Thread MarkSwanson
I am unable to view the API docs reliably with firefox 3.0 (I can not
use my scroll wheel with the Clojure API page - it's the only page on
the net that I know of that behaves this way). So I use konqueror to
view the Clojure API docs. I thought it was just my Ubunut 9.04 box so
I wasn't going to mention it - but since someone opened a thread on
this I'm chiming in.

Cheers.

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

2009-12-05 Thread MarkSwanson
Just a thought: maybe this is a sign a clearer message should be
placed on the Clojure contributing page. In any case, it can't hurt to
be more clear can it?

FYI I've submitted a couple of small patches to this group and read
the contributors agreement and the SCA FAQ. After going through this
process I was still under the impression it was OK to just submit
patches into the public domain. Rich even 'applied' the tiny 'patch'.

F.E. Rich makes things perfectly clear:

I don't want code from someone unwilling to put their real name on
it.

and

The problems of open source projects that didn't do a good job of
provenance, and then wanted to switch or expand license options, are
well known.

I think 'someone' should seriously think about putting these on the
contributors page. There is no way to misinterpret these statements.
If these statements (or something similar) are on the contributors
page I suspect it's unlikely this issue will ever be revisited. I do
not think strong clear statements like this would dissuade anyone from
contributing.

Btw, I have been trying to track 'someone' down for several decades.
If 'anyone' knows who this specific person is please let me know. :)

Cheers.

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

2009-12-01 Thread MarkSwanson
http://mina.apache.org/

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


Missing unsigned-bit-shift-right?

2009-11-18 Thread MarkSwanson
I'm porting some Java code that uses >>>.
Is there a way to do this in Clojure?

FYI: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/opsummary.html

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

2009-11-12 Thread MarkSwanson
> >> See if this makes a difference:
> >> syntax sync fromstart

I think one of the primary objectives of vimclojure should be to
consistently render correctly - and it can only do that with 'syntax
sync fromstart'.

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

2009-11-11 Thread MarkSwanson
> Does anyone know why if the first character in my *.clj file is '#', then
> when I open it in VIM, ClojureVIM fails to recognise it as a Clojure file?

I don't know why, but I can provide this data point:
It does not do that for me.
Vim 7.2, vimclojure 2.1.2, java 6.0.14

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

2009-11-05 Thread MarkSwanson


> I wouldn't bother. The semantics are essentially what the present docs say;
> it's just that where calling seq on its argument would just call a method
> whose body is "return this;" it skips that no-op for efficiency. (At least,
> the body of ASeq.seq() is "return this;"; are there any ISeq implementations
> where it isn't?)

I think you're right.

I also think that I simply have a problem grokking some of the
documentation because it is too terse, and this was an attempt to make
things a little more clear - at least in my mind.

I think Rich would prefer to keep these docs terse because the more
terse the easier it is to maintain.

Perhaps what I'm really looking for is a website that has clojure core
and contrib docs that are greatly expanded with more verbose
descriptions and specific examples. If I had some free time to spare
I'd do this.

Cheers.

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

2009-11-05 Thread MarkSwanson



On Nov 5, 7:00 pm, MarkSwanson  wrote:
> (def
>  #^{:arglists '([coll])
>     :tag clojure.lang.ISeq
>     :doc "Returns a seq of the items after the first. Calls seq on its
>   argument.  If there are no more items, returns nil."}
>  next (fn next [x] (. clojure.lang.RT (next x
>
> PROBLEM: seq is not called on its argument.

Ok, I see RT.next(x) is called and the implementation is:

static public ISeq next(Object x){
if(x instanceof ISeq)
return ((ISeq) x).next();
ISeq seq = seq(x);
if(seq == null)
return null;
return seq.next();
}

1. if ISeq, return the next item in the sequence.
2. else, (seq coll)
I propose the docs should read something like this:

(next coll)
 :doc "If coll is not a seq, turn coll into a seq. Returns a seq
of the coll after the first item.
If coll has no more items, returns nil."}


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



Q: Are the docs for next incorrect?

2009-11-05 Thread MarkSwanson

(def
 #^{:arglists '([coll])
:tag clojure.lang.ISeq
:doc "Returns a seq of the items after the first. Calls seq on its
  argument.  If there are no more items, returns nil."}
 next (fn next [x] (. clojure.lang.RT (next x

PROBLEM: seq is not called on its argument.

I think the second sentence should be removed.

Would anyone disagree?

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

2009-11-04 Thread MarkSwanson

>
> but you can certainly send them the result of (quot 1257316459070 1000).

Wohoo!!! I just wanted a way to do it!
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
-~--~~~~--~~--~--~---



Language feature request: auto-promote int to long with unchecked-divide

2009-11-03 Thread MarkSwanson

Hello,

This should work (I think): (unchecked-divide 1257316459070 1000)
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Periodic tasks

2009-11-03 Thread MarkSwanson

> I'd love to hear success stories from people using nailgun to actually
> run frequent scripted tasks out of cron, as opposed to for
> development. It would make clojure more palatable for my work
> environment.

Nailgun has been a boon to me. I don't believe Nailgun has a problem
with dynamic classes - only that you have to remember to stop/start
Nailgun to ensure its ClassLoader gets the latest classes (I would be
genuinely interested in any details that show otherwise). F.E. I can:
1. (def q (vec (range 100)))
2. use jvisualvm to see q takes up ~20MB RAM; 20 bytes / Integer.
3. (def q "abc")
4. use jvisualvm and it will show the 20MB has been GC'd just fine.
(I'm not sure what sort of dynamic class / unload/ GC? issue you were
referring to).

Since it takes Spring a long time to instantiate all of the configured
objects using Nailgun really does save me time. I have a lot of nifty
command line tools that help me resolve support issues and waiting for
Spring (not the JVM really) to instantiate and wire everything up
really slowed me down. Nailgun solves the speed problem and I haven't
had any problems with 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: PATCH: AFn.java, RestFN.java (a better throwArity message)

2009-10-26 Thread MarkSwanson

Thanks for the link.

I read somewhere that Rich asked folks to vet stuff on this Google
Group first, so that's why I posted it here.
I previously posted a "patch" to Clojure here and Rich applied it. I
didn't have to do the CA, and if posting my patches into the public
domain works - then please consider my patch as public domain. If this
works I'd prefer to do the same for all future patches.

P.S. All of my legal and banking work over the past few years (which
includes getting VC and forming a startup) was all done with signed
PDFs - no snail mail required. I vote to allow a signed CA PDF in
addition to postal mail.


On Oct 26, 4:14 pm, John Harrop  wrote:
> On Mon, Oct 26, 2009 at 1:55 PM, Jason Wolfe  wrote:
> > Hi Mark,
>
> > Thanks for the patch!  Have you seen this page?
>
> >http://clojure.org/contributing
>
> > You should follow the instructions there to get your patch included.
> > In particular, that page tells you where to post it, and has other
> > details; for instance, you must send a CA to Rich before any code you
> > write can be incorporated into Clojure.
>
> What about code someone explicitly places into the public domain?
> Uncopyrighted code shouldn't need a CA I'd think.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: PATCH: AFn.java, RestFN.java (a better throwArity message)

2009-10-26 Thread MarkSwanson

This seems like an even better place to post it:

http://paste.lisp.org/display/89307


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

2009-10-25 Thread MarkSwanson

That's interesting.
I ran this against a quoted Clojure fn of mine and received 92.

I'm curious (general Clojure question) about your use of the quoted
form. The Clojure docs state that this results in an unevaluated form,
but I had trouble finding more details on this. F.E. I'd like to run
count-nodes against a compiled fn that I've previously defined, but I
could not get an existing fn into quoted form - and (count-nodes a-fn)
always returns 1. Is using a macro the only way to get an expression's
unevaluated form?

Do you (or anyone) believe some general guidelines could be gathered
from running count-nodes against all of the individual fns in a
project. F.E. a number > X(?) for a fn means you might be using an
imperative style and should be looking at breaking up the fn or
looking for ways to use map/reduce/other idiomatic Clojure fns to
simplify your code?

If yes, maybe the people working on Clojure/Maven (or other Clojure
build/package projects) would be interested in making this one of the
standard reports.

Every time I engage a company for contract work I wonder what I'm in
for ( the same goes when I dive in to another open source project). I
think it's possible that viewing this metric by fn and by file would
give some insight.




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

2009-10-25 Thread MarkSwanson

Ok, I see now I should not post patches here because it messes up the
formatting. I can't seem to find an option to paste  text.

I've placed the patch here:
http://www.scheduleworld.com/sw2/arity.patch.gz


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

2009-10-25 Thread MarkSwanson

Thanks Lauri. I was stuck on this too.

FYI this issue prompted me to submit a patch to improve the arity
error message:

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


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



PATCH: AFn.java, RestFN.java (a better throwArity message)

2009-10-25 Thread MarkSwanson

Hello,

Someone recently posed the question: (why doesn't this work)
(into {} (map #([% (* % %)]) [1 2 3 4]))

(reference: 
http://groups.google.com/group/clojure/browse_thread/thread/7d3ee57ee8041353)

The error message was:
Caused by: java.lang.IllegalArgumentException: Wrong number of args
passed to: PersistentVector

How many args were being passed anyway? The code looked fine (to me).
It would have been helpful to me to know the number of args being
passed was zero.

With the patch below the error message would look like this:

... java.lang.IllegalArgumentException: Wrong number of args (0)
passed to: PersistentVector ...

The patch will handle all cases of wrong arity and report the expected
number of args. In some cases (RestFN) the exception will now report
the required arity as well as the given arity.

There is one improvement that could still be made to the patch:
applyTo(ISeq args) -> should report the count of args:
-   return throwArity();
+   return throwArity(-1, reqArity); // TODO/BUG: -1 should be count
of args

I'm running out the door and don't have time to code this.

Please consider this patch - or something like it.



diff --git a/src/jvm/clojure/lang/AFn.java b/src/jvm/clojure/lang/
AFn.java
index e2646ad..56afa8f
100644
--- a/src/jvm/clojure/lang/
AFn.java
+++ b/src/jvm/clojure/lang/
AFn.java
@@ -45,110 +45,110 @@ public void run()
{


 public Object invoke() throws Exception
{
-   return throwArity
();
+   return throwArity
(0);
 }

 public Object invoke(Object arg1) throws Exception
{
-   return throwArity
();
+   return throwArity
(1);
 }

 public Object invoke(Object arg1, Object arg2) throws Exception
{
-   return throwArity
();
+   return throwArity
(2);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3) throws
Exception{
-   return throwArity
();
+   return throwArity
(3);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4) throws Exception
{
-   return throwArity
();
+   return throwArity
(4);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5) throws Exception
{
-   return throwArity
();
+   return throwArity
(5);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5, Object arg6) throws Exception
{
-   return throwArity
();
+   return throwArity
(6);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5, Object arg6, Object
arg7)
throws Exception
{
-   return throwArity
();
+   return throwArity
(7);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5, Object arg6, Object
arg7,
  Object arg8) throws Exception
{
-   return throwArity
();
+   return throwArity
(8);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5, Object arg6, Object
arg7,
  Object arg8, Object arg9) throws Exception
{
-   return throwArity
();
+   return throwArity
(9);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5, Object arg6, Object
arg7,
  Object arg8, Object arg9, Object arg10) throws
Exception{
-   return throwArity
();
+   return throwArity
(10);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5, Object arg6, Object
arg7,
  Object arg8, Object arg9, Object arg10, Object
arg11) throws Exception
{
-   return throwArity
();
+   return throwArity
(11);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5, Object arg6, Object
arg7,
  Object arg8, Object arg9, Object arg10, Object
arg11, Object arg12) throws Exception
{
-   return throwArity
();
+   return throwArity
(12);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5, Object arg6, Object
arg7,
  Object arg8, Object arg9, Object arg10, Object
arg11, Object arg12, Object
arg13)
throws Exception
{
-   return throwArity
();
+   return throwArity
(13);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5, Object arg6, Object
arg7,
  Object arg8, Object arg9, Object arg10, Object
arg11, Object arg12, Object arg13, Object
arg14)
throws Exception
{
-   return throwArity
();
+   return throwArity
(14);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg5, Object arg6, Object
arg7,
  Object arg8, Object arg9, Object arg10, Object
arg11, Object arg12, Object arg13, Object
arg14,
  Object arg15) throws Exception
{
-   return throwArity
();
+   return throwArity
(15);
 }

 public Object invoke(Object arg1, Object arg2, Object arg3, Object
arg4, Object arg

Re: STM talk

2009-10-24 Thread MarkSwanson

I'm confused about the slide on barging:

"txnB has a status of RUNNING and can be changed to KILLED".

Are you implying that simply having a status of RUNNING is all that is
required for the txn to be killed?
Or, are there other requirements to "can be changed"?

I'm having a hard time wrapping my head around the idea of the STM
just killing a fn.
Unless... the fn will be retried later. I couldn't find a good
description of what 'killing a fn' means.

Thanks for sharing the slides.


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

2009-10-16 Thread MarkSwanson

Grats. Clojure is amazing.


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



PATCH: RT.java seqFrom()

2009-10-14 Thread MarkSwanson


line: ~476
else {
Class c = coll.getClass();
Class sc = c.getSuperclass();
throw new IllegalArgumentException("Don't know how to create
ISeq from:" + c.getSimpleName() + " / " + c.getName());
}

Rationale: getSimpleName() doesn't provide anything useful when 3rd
party libs are involved. F.E. I recently received this:

Don't know how to create ISeq from:Input

There is no 'Input' in my code - and it's not in the source of any of
the 3rd party libs I'm using. It must be coming from one of the
compiled libs I'm using. It would be more helpful if I knew the type
that was failing to convert to a seq. If I knew this I could (likely)
easily resolve this issue.

Please _at least_ include c.getName().

Cheers.


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

2009-10-14 Thread MarkSwanson


> As far as the "sync fromstart" is concerned: I also use this setting
> normally and never had problems. But since there might be a
> performance hit, I didn't want to make it the default in VC. Did
> others experience any slowdown? Or should I assume that modern
> computers are fast enough and make it the default?

Just a FYI: I used "sync fromstart" on a >15000 line computer
generated (by javacc) java file. If I start from line 15000 and start
scrolling back it takes a little less than a second per scroll. If I
then jump to line 0 and back to line 15000 I can scroll full speed in
both directions through the entire file - and changes are full speed
too. vim seems to do a really good job at caching the syntax
formatting. Vim 7.2 takes 11MB RAM with this file and option.
2.4GHz Core2Duo / Ubuntu 9.04.

Now that vimclojure renders everything correctly (and consistently
gets tab spacing correctly while editing) I could never go back.
Maybe 'sync fromstart' could be the default and the docs could mention
that if vim rendering is slow you could change back to the default.

Cheers.

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

2009-10-13 Thread MarkSwanson

Edit: After using this it seems it didn't stick (or is not always
used?). More searching revealed that putting this in your ~/.vimrc
will work:
(and it seems to work for me - and I don't notice rendering slow down
at all)

autocmd BufEnter * :syntax sync fromstart

Found from here:
http://vim.wikia.com/wiki/Fix_syntax_highlighting

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



.vimrc settings for editing Clojure code with VIM

2009-10-13 Thread MarkSwanson


0. Perhaps it should go without saying: start with vimclojure and the
vim settings it recommends.

1. syntax sync minlines=200
This made a big difference for me. Without it I would always see
brackets marked as 'not paired' or code as a big red text string
because the syntax parser wouldn't look a few lines up beyond the top
of the current view.

2. Any other favorites?


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

2009-10-07 Thread MarkSwanson



On Oct 7, 2:59 am, ngocdaothanh  wrote:
> Mark,
> What tool did you use to see the CPU utilization, especially when the
> test run time is so short?
>
> Just curious.

I used the CPU utilization monitor in Linux.
I adjusted the loop so it took about 5-7 seconds.

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

2009-10-06 Thread MarkSwanson

Excellent job. It worked ootb for me once I updated my classpath / -
Djava.library.path. I'm running 64-bit Linux with (in this case) the
32-bit JVM as it seems more stable with jogl.
Q: I thought the blue and green pieces were supposed to be opposite.

Penumbra is such a fascinating library. Nice to see OpenCL in there
now too.

Hey, if you're looking for suggestions this might be fun.
It's the 256 byte puls demo in a single GLSL fragment shader.

http://wakaba.c3.cx/w/puls.html

A youtube video to show what it looks like (the 256 byte original. I
haven't seen the GLSL version):
http://www.youtube.com/watch?v=3vzcMdkvPPg

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

2009-10-06 Thread MarkSwanson

> (You wrote "atom" several times but I guess you meant "agent".)
Heh heh... yeah.

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

2009-10-06 Thread MarkSwanson

Good catch. I had forgotten that.

I did some more tests with 4 queues and found that there seemed to be
some contention going on that prevented all cores from being utilized
fully.
With the example provided 2 cores will pin at 100% (excellent). With 4
atoms and one test fn one core will stay around 20%, no other core >
70%.
When I used 4 separate worker fns along with 4 separate atoms things
improved and all 4 cores pinned at around 60%. It would be interesting
to know why having 4 separate fns makes a difference (STM?).

Wrt 60%: I simply think this was an artifact of my test. If I had
spawned another thread to feed another atom I'm sure I could have
easily pegged all CPUs to 100%.


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

2009-10-06 Thread MarkSwanson

Thanks John.
I was curious about the details so I took a dive in to the source to
see for myself.
In case anyone else stumbles upon this here's what I found:

In Agent.java, the number of worker threads for (send) are defined
like this:

final public static ExecutorService pooledExecutor =
Executors.newFixedThreadPool(2 + Runtime.getRuntime
().availableProcessors());

The clojure (send) calls Java Agent dispatch(), which winds up using
the pooledExecutor.

Clojure (send-off) follows the same path but winds up using the
soloExecutor - which can spawn (and temporarily cache) an unlimited
number of threads as required:

http://java.sun.com/javase/6/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool()

Random thought: Let's test (send) vs (send-off). New results using
(send):
(the -server jvm produces some wild results for a bit then I get
something crazy: 7.9ms):

Clojure=> (agent-speed-test)
"Elapsed time: 1164.702387 msecs"
20001
Clojure=> (agent-speed-test)
"Elapsed time: 1416.682837 msecs"
20001
Clojure=> (agent-speed-test)
"Elapsed time: 7.907515 msecs"   <-- **  LOL **

This happens infrequently, but it did happen more than once.

Also, I note that only 2 cores are used on my quad core2 duo. Weird.
It's as if
 Runtime.getRuntime().availableProcessors()  fails (returns zero?)




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

2009-10-05 Thread MarkSwanson

To expand on Meikel's nice explanation:
(to see if I understand correctly)

1. (defn baz ...)

2. (binding [foo bar] (baz [1 2 3]))  - dynamically binds foo and
creates a lazy-seq response to the baz fn. Because map is lazy the [1
2 3] sequence is actually not read by anything within the binding
dynamic scope. The binding value simply isn't used as there isn't any
code that takes any values out of the lazy map.

3. After (binding ...) is finished it will return the last expr
evaluated - which was (baz [1 2 3]) _and_ it puts foo back to 42.

4. The repl now wants to print (baz [1 2 3]) so it takes the values
out of the lazy map (while foo = 42).

I wonder if this concept will be thought of as a source of problems in
the future. Or, maybe this is just one of those fundamental Clojure
concepts you just have to learn and once you do you find you don't get
bit by 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: Agent send-off: ~20k/s

2009-10-05 Thread MarkSwanson

On Oct 5, 2:45 am, ngocdaothanh  wrote:
> I think it is not "spawn about 20K agents / second", it is 20K message
> passings / second. The number is about that of Erlang.

As Clojure uses a thread pool for agents I agree 'spawn' was the wrong
word. Thanks for the correction.

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



Agent send-off: ~20k/s

2009-10-04 Thread MarkSwanson

I recently integrated Clojure with two async messaging systems.
I wound up doing "send" operations through a Clojure agent.
I was curious how many agents I could spawn per second and found I
could spawn about 20K agents / second.

Code for testing:

(def t (agent true))

(defn tt [_ num]
 (try
   (let [x (inc num)])
   (catch Throwable t (println "error"

(defn agent-speed-test []
 (time (loop [b 1]
 (send-off t tt b)
 (if (> b 2)
   b
   (recur (inc b))

After a few iterations in the repl (started with -server) my best time
was:
"Elapsed time: 1021.700789 msecs" - which is pretty much exactly 20k/
s.

CPU: 2.4GHz Core2 Duo.
Java 1.6.0_14-ea-b03
Clojure from git/master around Sept/2009.



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

2009-09-25 Thread MarkSwanson

In case others wonder how do file a ticket on Assembla:
1. sign up for an Assembla account at www.assembla.com
2. Ack the signup email
3. go to : https://www.assembla.com/spaces/clojure-contrib/tickets
4. look for the 'create ticket' button.

Then tell me where it is so I can also file a ticket. Heh heh... :-)
(I'm guessing it's because I'm not part of the clojure-contrib team)

Cheers.

P.S. search for 'Clojure' using Assembla search and the only result
is:

Text Adventure Game in Clojure

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



Re: Bug in count for hash-maps with nil values

2009-09-24 Thread MarkSwanson

Confirmed. I'm using clojure from git:
$ git status
# On branch master
nothing to commit (working directory clean)

I also tried with the ':'

Clojure=> (count {:1 nil :2 nil :3 nil :4 nil :5 nil :6 nil :7 nil :8
nil :9 nil})
0


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



test.clj / test/tap.clj error

2009-09-23 Thread MarkSwanson

Hello,

I'm trying to use tst/tap.clj but the tap output does not contain the
'not ok' line.
I think this is a bug in tap.clj. Here is the small test:

(ns tc
  (:use [clojure.test]))

(deftest addition
 (is (= 4 (+ 2 2)))
 (is (= 8 (+ 3 4

>(use 'clojure.test)
>(use 'clojure.test.tap)
>(require 'tc)
>(with-tap-output
>  (run-tests 'tc))

# {:type :begin-test-ns, :ns #}
# {:type :begin-test-var, :var #'tc/addition}
ok (addition) (tc.clj:30)
# expected:(= 4 (+ 2 2))
#   actual:(# 4 4)
# {:actual (not (= 8 7)), :type :fail, :message nil, :expected (= 8 (+
3 4))}
# {:type :end-test-var, :var #'tc/addition}
# {:type :end-test-ns, :ns #}
1..1

test.clj seems to be working fine:
Testing tc

FAIL in (addition) (tc.clj:31)
expected: (= 8 (+ 3 4))
  actual: (not (= 8 7))

Ran 1 tests containing 2 assertions.
1 failures, 0 errors.

Unless I'm missing something to tell tap to generate 'not ok' lines?

Cheers.

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

2009-09-23 Thread MarkSwanson

Environment: vimclojure-2.1.2. clojure from git as of a few days ago.

Running the tests in a plain REPL from the command line worked
perfectly!
-=* THANKS GUYS !!! *=-

I wasn't expecting this at all. I thought the REPL in vimclojure
actually supported stdout because this works:
> (def a "abc")
#'user/a
> a
"abc"
> (println a)
abc
nil

I have noticed that mouse paste operations into the vimclojure repl
fail (the pasted text is truncated after a certain number of
characters).
These seem to be indications that stdin/stdout is not handled
perfectly by vimclojure...

Cheers.

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



trouble running clojure.test

2009-09-22 Thread MarkSwanson

Hello,
I'm having trouble unit testing clojure code. To be sure I'm just
testing clojure.test, I'm trying to test clojure.contrib.json.read.

test.clj states:

  ;; RUNNING TESTS
  ;;
  ;; Run tests with the function "(run-tests namespaces...)":

  (run-tests 'your.namespace 'some.other.namespace)

However, this doesn't work:
> (run-tests 'clojure.contrib.json.read)
nil

What does seem to work is this:
> (test-ns 'clojure.contrib.json.read)
{:test 17, :pass 27, :fail 0, :error 0}

However, I need MUCH more verbose output: which functions passed?
which ones failed (expected/actual)???
test.clj states this should work perfectly:
  ;; You can type an "is" expression directly at the REPL, which will
  ;; print a message if it fails.
  ;;
  ;; user> (is (= 5 (+ 2 2)))
  ;;
  ;; FAIL in  (:1)
  ;; expected: (= 5 (+ 2 2))
  ;;   actual: (not (= 5 4))
  ;; false

but it doesn't work this way at all:
> (is (= 5 (+ 2 2)))
false

Just false?
How do I enable the nice report?
NOTE: the code above doesn't have any failed functions, but a simple
test function I created only did this:
(test-ns 'test)
{:test 2, :pass 1, :fail 1, :error 0}
*missing == FAIL in ...

I've also tried test_is.clj but I only ever get 'nil' as a result. I
also tried with

I'm sure I've missed it. test.clj contains defmethod report ... that
has the FAIL println in it. I do not know why it is not getting
called.

All suggestions are warmly welcomed.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Q: How to convert a struct-map to xml and back (ignoring functions)?

2009-09-22 Thread MarkSwanson

Thanks for the note about read-string and the example.
If I only had to consider Clojure I'd probably use that.
The Clojure structures are going to be persisted to/from a DB, and
then also read back (and maybe updated) later using other languages.
The tools I prefer to use for this are based on XML, but I can also
use JSON. I have since found clojure.contrib.json.[read,write] and
that works fine.
Cheers.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Q: How to convert a struct-map to xml and back (ignoring functions)?

2009-09-22 Thread MarkSwanson

Thanks for the link. It's a good start and it has prodded me to start
analyzing clojure core and contrib code - which I'm finding are
incredibly good examples of how to do 'stuff'.

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

2009-09-20 Thread MarkSwanson

Personally, that's not what I want.

I want to download the clojure.org web page - one level deep so the
files api, special_forms, macros, etc. are all available on my laptop
offline.
I tried a couple of programs (wget and httrack) to get this but there
is some strange combobulation of redirects and cookie sessions going
on that prevented these from working (for me).

If anyone knows an easy way to get this documentation available
offline please contribute.

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



Q: How to convert a struct-map to xml and back (ignoring functions)?

2009-09-20 Thread MarkSwanson

I would like to encode/decode Clojure structures to/from a database.
Parsing XML is easy, but I can't seem to find a simple way to encode
Clojure structures to XML and back. Atm my structures are simple: just
simple key/value pairs where the key is always a string and the value
is always a string or a set of strings.

clojure.xml/emit and clojure.contrib.laxy_xml/emit both require
specially constructed structures which isn't useful to me. I was
hoping for a core or contrib function that was more generic that
dynamically and recursively determined the structure keys for element
names and strings for the element text data.

In my mind I was thinking something simple like what Sarissa provides
for JavaScript.
If nothing exists I'll take a stab at it. I just thought I'd ask
because the available Clojure libraries seem quite good and I feel
like I'm missing something obvious.

Cheers.

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

2009-09-10 Thread MarkSwanson

> Just thought you would like to know that Wolfram|Alpha agrees (in
> roughly the same time):
>
> http://www.wolframalpha.com/input/?i=factor+1234567890123456789012345...

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



Re: Clojure Golf – Episode 2: Largest Prime Factor

2009-09-09 Thread MarkSwanson

Just for fun I actually tried this:

Clojure=> (time (lpf6b 1234567890123456789012345678901234567890))
The prime factorization of 1234567890123456789012345678901234567890
is :5964848081
"Elapsed time: 5519.278432 msecs"

I can't confirm the answer is correct.
5.5 seconds sure beats 10 minutes. :-)

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

2009-09-09 Thread MarkSwanson

I took a stab at it. I used:
(set! *warn-on-reflection* true)
but it didn't tell me anything.

I found a Java class that did the same thing and created a Clojure
implementation from that. I thought that perhaps if I could force the
data types to be BigInteger Clojure would save time by not having to
use reflection.

However, this fails and I'm not sure why. The code:

(defn lpf3 [#^bigint arg]
  (print (str "The prime factorization of "  arg  " is :"))
  (println (loop [i (bigint 2) n (bigint arg) ]
;(println (str "i:" i "n:" n))
  (if (<= i (/ n i))
  (recur (inc i) (loop [n2 (bigint n)]
   ;(println (str "n2:" n2))
   (if (zero? (rem n2 i))
 (recur (/ n2 i) )
 n2 )))
n)))
  )

The error:
The prime factorization of 234 is :#
NOTE: Line 17 in this case looks like "n2 )))"

I tried to create a version using long to see if that would help. It
did as I received better compiler error messages. The end result:
(too many casts perhaps...)
(defn lpf6 [arg]
(print (str "The prime factorization of "  arg  " is :"))
(println (loop [i (long 2) n (long arg) ]
(if (<= i  (/ n i))
  (recur (long (inc i)) (long (loop [n2 (long n)]
(if (zero? (rem n2 i))
  (recur (long (/ n2 i)) )
  n2 
(long n
)

Clojure=> (time (lpf6 364362978))
The prime factorization of 364362978 is :8675309
"Elapsed time: 133.974784 msecs"

Your code on the same machine gives:
Clojure=> (time (lpf 364362978 2))
"Elapsed time: 1014.572527 msecs"
8675309

I suspect casting to long would speed things up a bit in your case.
However, long doesn't have enough precision to handle the number you
mentioned in your article:
1234567890123456789012345678901234567890

The correct solution would be to coerce the types to bigint. I've done
this and the results are interesting. Strangely bigint is over 10x
faster than long:

Clojure=> (time (lpf6b 364362978))
The prime factorization of 364362978 is :8675309
"Elapsed time: 8.874452 msecs"

The code:

(defn lpf6b [arg]
(print (str "The prime factorization of "  arg  " is :"))
(println (loop [i (bigint 2) n (bigint arg) ]
(if (<= i  (/ n i))
(recur (bigint (inc i)) (bigint (loop [n2 (bigint n)]
(if (zero? (rem n2 i))
(recur (bigint (/ n2 i)) )
n2 
(bigint n
)

I can only guess that bigint is faster here because I was not casting
long correctly in enough (or in the correct) places and was actually
causing the compiler more work. If this is obvious to anyone please
post. I'm intrigued.

My next stab would have been in GLSL with Clojure Penumbra. Purely for
fun :-) But I'm out of time.

Cheers.


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

2009-09-09 Thread MarkSwanson

This doesn't work for me. Here is what happens:
> > 0. Start ng-server
> > 1. Start a fresh vim.
> > 2. :setfiletype clojure (a colon command like :w or :q)
> > 3. \sr (should open a new window)
> > 4.  (to go back to first window) ( is Control+w,
> >  would be Alt+w)
> > 5. Type in some function: (defn greet [] (println "Hello, World!"))
> > 6. Make sure the cursor is in the function, eg. on the e of Hello.
> > 7. \et (to send the function to the Repl)
> > 8. A new window should open, containing #'user/greet. Type \p to close
> > the window.

It's all good up to this point.

> > 9. Go to the Repl window, eg. with .
> > 11. At the prompt type (gr and hit  to complete the function
> > name.
> > 10. Submit (greet) by hitting return. (the Repl should now print
> > "Hello, World!")

This doesn't work.
The new window opened up containing the right text. However, the REPL
can not use the function.
What's strange is that I can type (gr and CTRL-n and user/greet shows
up! This tells me the REPL has the function, but it gives this error:
#

I've also tried (user/greet) but that doesn't work either - same
error.

I'm using vimclojure-2.1.2 with the latest clojure from git, java 6 on
Ubuntu 9.04.

Note: I have been copying/pasting using a mouse but that has a bug
where comments get an 'x' character put in front of them on paste and
the function won't compile. So I'd really like this to work!

Thanks again for vimclojure!


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

2009-09-03 Thread MarkSwanson

On Sep 3, 12:09 pm, MarkSwanson  wrote:
> Hmm. I just spent some time writing about what I got stuck on and my
> solutions
> and suggestions but Google lost it all when I clicked submit.

Ok... I did wait a bit and refresh the page a couple of times. I guess
I just didn't wait long enough. Sorry for the double post.

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

2009-09-03 Thread MarkSwanson


Hmm. I just spent some time writing about what I got stuck on and my
solutions
and suggestions but Google lost it all when I clicked submit.
Here is an abbreviated post:

First, thanks for writing vimclojure! I think it's great!

1. README.txt contains incorrect information about what jar files are
required to get vimclojure working. The correct list is:
vimclojure.jar
clojure-1.0.0.jar
clojure-contrib-def-919.jar
clojure-contrib-pprint-919.jar
clojure-contrib-stacktrace-919.jar

2. I had a tilde (~) character in my classpath. This would not work
for me.
It might have something to do with symbolic links in my classpath.
Using full pathnames resolved this issue.

3. CLOJURE_EXT is confusing. I tried to grok this to understand what
jar
files were required to run vimclojure.

Ah, I see the -maxdepth 1 argument to find...
This means your CLOJURE_EXT definition is not correct. It should
read:

CLOJURE_EXT -> The path to a base directory that will be
recursively
searched (maxdepth 1) for jar files to put on the classpath.

F.E. $ CLOJURE_EXT=/src/vimclojure-2.1.2 ./bin/ng-server

4. There is no example of how to use vimclojure in the docs!
 is also confusing. I've been using vim for > 20
years
and I've never seen this. The docs on it are poor (Leader =
defines a
mapping ... ?) It would have helped a lot to see something like
this:

1. vi test.clj (file must end in .clj)
2. \sr (yes, start by typing the backslash. '\' is the
)
3. you should see the screen split into two with the top being the
REPL.
4. try some Clojure=> (def v [1 2 3])
5. To switch between the REPL and test.clj:
ESC (to get out of input mode)
CTRL-W CTRL-W

Again, thank you so much for vimclojure!

Cheers.

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

2009-09-03 Thread MarkSwanson

I had trouble installing it too. Here is exactly what my problems were
and my solutions:

NOTE: Meikel -> Thank you for writing vimclojure! I think it's great!
Please accept these issues from the perspective of someone who is
trying to help you make vimclojure better.

1. For some reason (and only with vimclojure) I used the tilde (~) in
my classpath. It simply didn't work. When I used full pathnames it
worked.Maybe the symbolic links in my path caused problems with this.

2. Nowhere is it documented what jar files must be in the classpath
for vimclojure to work. Actually, the README.txt file gives incorrect
information about this:

To run the Nailgun server you need the clojure.jar, clojure-
contrib.jar and
vimclojure.jar in your Classpath


As your post above shows you actually need:
vimclojure.jar
clojure-1.0.0.jar
clojure-contrib-pprint-919.jar
clojure-contrib-def-919.jar

Also, bin/ng-server is also confusing. I can see it's trying to set
jars automatically, but because it states:

The path to a directory containing (either directly or as
symbolic links) jar files and/or directories whose paths
should be in Clojure's classpath.

I thought it was a generic setting used to set _all_ jar files that
should be in Clojure's classpath. This didn't seem to have anything to
do with getting vim-clojure actually working.
I suggest something like: VIMCLOJURE_DIR -> contains build/vimclojure-
source.jar and lib/clojure*jar files.
and then CLOJURE_EXT would be for _Clojure-specific_ (vs vimclojure-
specific) jar files.

No vimclojure docs state how to create the vim help files. You
explained this clearly above. Please include that in the README:
The pipes are a marker for Vim's online help system. Run ':helptags
~/.vim/doc' after installing the Vim plugin of VC to regenerate the
tags file.

Actually, this did not work for me. Nothing happened, and I can't view
any help for |sr|.
I have ~/.vim/doc/clojure.txt
Hmm. After running :helptags ~/.vim/doc I actually have a tags file
there. Yet I can't get it to work.
Normally in VIM you should CTRL-] when your cursor is between the ||
symbols. Your instructions of CTRL-> do not work either. ???

Furthermore, your README and clojure.txt files do not give an example
on what to type to actually use vimclojure! I've been using vi/vim for
> 20 years and have never heard of . Also, maplocalleader
is badly documented IMHO as the vim docs don't even say what the
default value is or how one can even find out what the default value
is.
Please provide a small section that shows exactly what to type like
this:

1. vi test.clj (only files ending in .clj will work)
2. \sr (type the backslash once - the backslash is the )
3. That's it. You should see the screen split into two. At the top you
should see the REPL.
4. ESC (to get out of insert mode)  CTRL-W CTRL-W (switch between top/
bottom)

Again, I really like what you have done with vimclojure!

Cheers.


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