Re: loneclojurian at ICFP programming contest

2009-07-02 Thread Daniel Lyons


On Jul 2, 2009, at 12:58 AM, fft1976 wrote:
> On Jun 30, 3:02 pm, igorrumiha  wrote:
>
>> Some people claim
>> that the JVM can give you C-like performance, but I would be more  
>> than
>> happy if I got my VM to be 10x slower than the C ones :)
>
> I like your honesty! You can come to my house and * my sister!

I wish you wouldn't talk like that.

—
Daniel Lyons


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

2009-07-02 Thread Daniel Lyons

Mark,

On Jul 1, 2009, at 3:16 PM, Mark Engelberg wrote:
> But each language encourages a certain style of design and algorithm,
> so it IS fair to compare the way that the language encourages a
> certain approach.  For example, Clojure encourages you to use a more
> functional approach and persistent data structures.  If this ends up
> being way slower than the mutable approach that Python encourages,
> that is worth knowing.
>
> I remember one year, my ICFP VM in Python ran ridiculously slow in
> part because Python doesn't have a switch statement, whereas other
> languages do.   So it is useful to look at what a language does and
> does not allow you to do, and how that impacts speed.
>
> My point is: no comparison is going to be exactly apples to apples,
> but the comparison can still be useful.

I think I may have conflated some ideas in my previous message. Let me  
explain.

Firstly, I don't think there's any question that Clojure's performance  
isn't up to that of C. The JVM can always get better but it's probably  
going to be a while on that one. And I think the JVM establishes a  
reasonable ceiling on performance. To wit, if you don't think your  
program would run fast enough on the JVM, it's probably not going to  
run fast enough under Clojure either. Unless you can make up for it  
with cheap parallelism. I think everyone ought to know this coming in,  
but if C-level performance is really necessary, only a few languages  
will suffice and the decision of what to use to implement the code  
will necessarily flow from that.

As for FP techniques themselves, there is ample proof that they are  
not a performance inhibition in the form of other FP languages that do  
not compromise on methodology but still achieve high performance. I'm  
talking about OCaml, Haskell, Common Lisp (not as FPy, but it can be  
done) and Scheme and sometimes Erlang. The language shootout has  
plenty of evidence for that.

Please forgive my derision towards benchmarking languages. I guess you  
could say I am channelling Dijkstra here, but I think the algorithm  
dominates the debate. Quicksort in Ruby will beat bubble sort in C if  
your data is large enough. This is one reason I am not a big fan of  
comparing the speed of languages; another is that it often changes out  
from under you. Java itself is a great example of this: by the time  
everyone had gotten the message that it was slow, it had already  
become reasonably fast. The code that was to take the most advantage  
of the improvements was that which was written plainly and clearly  
rather than doing a lot of legwork to circumvent performance issues,  
and this is always the case. Clojure's young.

I appreciate the novelty of the ICFP and I think it's being examined  
because it's on our minds rather than due to any qualities it has as  
an experiment, so I won't harp on it much, but I think to compare  
between different teams implementations would be to assume that each  
team was more-or-less equal in terms of skill but for the language.  
The whole point of the contest is to discover just how untrue that is.  
I remember in 2006 my team made a very small VM in C and we were  
extremely proud of it because we had wasted so much time on a VM in  
Ruby and again in Python, hoping it would be a substantial  
improvement. Another team had written a VM with a just-in-time  
compiler which defeated our braindead C implementation handily. It was  
written in Haskell, of course:

http://comonad.com/reader/wiki;mode=category&item=Perl

All the best,

—
Daniel Lyons

PS: you can emulate a switch in Python by storing functions in a hash  
with the key being the dispatch value. But I don't think it will save  
your performance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



print-base / print-radix?

2009-07-02 Thread Parth Malwankar

I frequently deal with hex and binary numbers.
As of now when I need to view a list of numbers
I just map a little hex function to it to translate it
into a list of hex strings at the repl.


Having something like *print-base* / *print-radix* [1] may be
valuable in such a scenario

Or maybe an enhanced pprint? Not sure if pprint already provides
such an option or if its planned.

I would appreciate any comments or ideas if someone
is doing something similar.

Thanks.
Parth
[1] http://www.lispworks.com/documentation/lw50/CLHS/Body/v_pr_bas.htm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Displaying Clojure code on a Website

2009-07-02 Thread Rick Moynihan

2009/6/26 Kai :
>
> Hi all,
>
> I'm new to this discussion group and Clojure. I'm sharing the first
> "bigger-than-REPL" script that I've written because I haven't seen
> anything else like it for Clojure. It's a script that takes Clojure
> code as input and generates a pretty HTML version. You can view it
> here (I ran the script through itself):
>
> http://kai.myownsiteonline.com/clojure/html.clj.html
>
> The style sheet is kept separate for cases with more than one Clojure
> script shown on a page. Also, it still formats just as well without
> the javascript; the javascript only contains code that highlights
> Clojure script as you mouse over it.
>
> I don't have any particular intention by creating this script, it was
> just a warmup into Clojure. Feel free to use it for whatever purpose.
> I'd appreciate comments on the coding style as well as how to make it
> faster - core.clj takes a good 10 minutes! It was a pain and a
> pleasure to code :)

Cute!

Though I've spent a lot of time over the last 6 months reading about
and toying with clojure, I've not yet found the time to write anything
even as substantial as this.  I did however take a quick look at the
code, and it seems reasonably easy for a noob such as myself to
follow.

That said, it did remind of something I was meaning to ask which
concerns large function definitions (here and elsewhere e.g.
clojure.core).

Your parse-code function definition seems quite long and it seems
counter to the way I think I would write this program; as I would be
inclined to write lots of smaller functions responsible for emitting
the different spans for comments, strings, etc; and then tie them up
into a larger function.  That way I could evaluate them all separately
and combine them later.

I have seen similar large functions elsewhere e.g. a few in
clojure.core, and my question is:

How do you go about writing a large function like this?  What is the
process involved?  I realise referential transparency means that
almost every s-exp is evaluatable separately (providing the necessary
bindings are in scope) but is it not a hassle to build such things?
How is it you compose a large function and get the benefits of the
REPL and lisps interactive development model?  Do you evaluate these
snippets in a let bind?  If so what tools support this?

I'm also curious as to what the pro's are in writing large functions
like this.  There are several in clojure.core, I think gen-class is
the one that springs to mind; why is this not defined as a series of
smaller functions?

Thanks again for the HTML pretty printer!

R.

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

2009-07-02 Thread Konrad Hinsen

On Jul 2, 2009, at 10:36, Daniel Lyons wrote:

> This is one reason I am not a big fan of
> comparing the speed of languages; another is that it often changes out
> from under you. Java itself is a great example of this: by the time
> everyone had gotten the message that it was slow, it had already
> become reasonably fast. The code that was to take the most advantage
> of the improvements was that which was written plainly and clearly
> rather than doing a lot of legwork to circumvent performance issues,
> and this is always the case. Clojure's young.

I agree. I don't think discussing Clojure's performance vs. language  
X is very productive in general, and certainlyl not at this moment.  
The implementation is young, and so is the community's experience  
with efficient coding style.

Two more interesting questions are
1) What are good strategies to get the best performance out of Clojure?
2) How can the current implementation (compiler + runtime library) be  
improved?

Konrad.


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

2009-07-02 Thread David Miller

There are a number of aspects of the CLR dissimilar to the JVM that
the current implementation of ClojureCLR does not properly account
for.  Some of these will require extensions to Clojure, e.g. in symbol
syntax if we are to allow CLR-specific type references.

A short and by no means complete list of these things:

Proper handling of generic types
Proper handling of value types (mostly okay because so much gets
boxed)
References to types that include assembly information (no classpath/
classloader fun)
True multidimensional arrays

--David

On Jul 2, 1:23 am, "Ted Neward"  wrote:
> Be careful with assumptions about the two platforms--extension methods, for
> example, are purely a fiction of the C# compiler. No CLR support was added
> to provide anything that shipped as part of C# 3.0--just compiler and
> libraries.
>
> Ditto (AFAICT) for .NET 4.0. The new "dynamic" keyword is just syntactic
> sugar.
>
> To do the comparisons justice, you should look solely at the JVM
> Specification and the ECMA CLI Specification documents (at least the first 3
> partitions).
>
> Ted Neward | Principal Consultant, ThoughtWorks
> Java, .NET, XML Services
> Consulting, Teaching, Speaking, 
> Writinghttp://www.thoughtworks.com|http://www.tedneward.com
>
> > -Original Message-
> > From: clojure@googlegroups.com [mailto:cloj...@googlegroups.com] On
> > Behalf Of mmwaikar
> > Sent: Wednesday, July 01, 2009 6:01 PM
> > To: Clojure
> > Subject: Re: Problem with clojure code on .net.
>
> > Thanks a lot Daniel for your suggestions. As per my understanding
> > Clojure for Java and .Net are two implementations of the same
> > language, but they have to support different things because the
> > underlying platforms support different things - e.g. extension methods
> > (are in C# but most likely not in Java).
>
> > I realized the naming convention of methods. Similarly, what should be
> > the convention for naming method parameters? Is it pascalCase?
>
> > Also, I'll have to check when-let and re-find, I am still not familiar
> > with it.
>
> > As for the program, I had to write a simple cmd line tool a few days
> > back at my work, which converts images from one format to other (by
> > using an external tool) and copies the converted images to specific
> > folders (based on the file names), hence the subfolder name fn.
>
> > On Jul 1, 1:58 am, Daniel Lyons  wrote:
> > > Manoj,
>
> > > In case this helps, I've had a bit longer to dwell on this problem
> > and
> > > I have a couple of ideas. I do think this raises the general question
>
> > > of, are Clojure .NET and Clojure Java two different languages or two
>
> > > implementations of the same language? Normally in a situation like
> > > this (say, Jython and Python) I would say that they should be two
> > > implementations of the same language but the situation is complicated
>
> > > by the fact that Clojure code relies heavily on Java objects since
> > the
> > > policy is not to wrap everything. I'm not sure how the subject of
> > > Clojure .NET / Java portability has been approached but my naïve
> > guess
> > > is that it would revolve around separating Java dependencies and .NET
>
> > > dependencies from pure Clojure code. Is anyone else addressing these
>
> > > issues in their own code at this time?
>
> > > Back to your code. First of all, to simplify things, it's probably a
>
> > > good idea to decouple your I/O from your parsing, since the parsing
> > > can be functional. First I rewrote starts-with-hmorx into this:
>
> > > (defn starts-with-hm-or-x [name]
> > >    (#{\H \M \X} (.charAt name 0)))
>
> > > Which I think is simpler, building on the fact that sets can be used
>
> > > as functions, but then I thought it would probably be better to
> > > rewrite the functions into one that gets the information from the
> > > filesystem and another one that gets the information you want out:
>
> > > (defn parse-subfolder-name
> > >    [name]
> > >    (or
> > >     (when-let [[_ digit] (re-find #"(\d).*" name)]
> > >       (Integer/parseInt digit))
> > >     (when-let [[_ hmx] (re-find #"([hHmMxX]).*" name)]
> > >       (.toLowerCase hmx))
> > >     "other"))
>
> > > Unfortunately I'm still dependent on some Java API stuff in there,
> > but
> > > I think you can probably translate to the .NET equivalents. This is
> > > easier to test at the REPL:
>
> > > user> (parse-subfolder-name "0stuf")
> > > 0
> > > user> (parse-subfolder-name "Hstuf")
> > > "h"
> > > user> (parse-subfolder-name "stuf")
> > > "other"
>
> > > Then I'd set about handling the loading of the filename and
> > > dispatching it:
>
> > > (defn get-subfolder-name
> > >    [filename]
> > >    (parse-subfolder-name
> > >     (.ToString (Path/GetFileNameWithoutExtensions filename
>
> > > Now it should be easier to determine where the problem is, either in
>
> > > the I/O code or in the functional code which is easier to test at the
>
> > > REPL.
>
> > > As an aside, I'd recommend that you follow the naming conven

Re: Emacs clojure-mode home?

2009-07-02 Thread Ram Krishnan

Hi Phil,

I'd sent this to jochu earlier, but perhaps you can help commit this
minor patch to clojure-mode.

I found a small bug in the regexp used in `swank-clojure-find-
package'. The head version incorrectly parses `ns' forms of the
following kind:

(ns compojure.server.jetty
 "Clojure interface to start an embedded Jetty server."
 (:use compojure.control)
 (:use compojure.server.common)
 (:import org.mortbay.jetty.Server)
 (:import org.mortbay.jetty.servlet.Context)
 (:import org.mortbay.jetty.servlet.ServletHolder)
 (:import org.mortbay.jetty.security.SslSocketConnector))

and returns the package name as:

compojure.server.jetty
 "Clojure interface to start an embedded Jetty server."

The following patch modifies the regexp in `swank-clojure-find-
package' to fix this:

diff --git a/swank-clojure.el b/swank-clojure.el
index 96dc91e..9e4174b 100644
--- a/swank-clojure.el
+++ b/swank-clojure.el
@@ -80,7 +80,7 @@ swank-clojure-java-path) if non-nil."
file (format "%s" encoding

 (defun swank-clojure-find-package ()
-  (let ((regexp "^(\\(clojure.core/\\)?\\(in-\\)?ns\\s-+[:']?\\([^()]+
\\>\\)"))
+  (let ((regexp "^(\\(clojure.core/\\)?\\(in-\\)?ns\\s-+[:']?\\([^()
\" \t\n]+\\>\\)"))
 (save-excursion
   (when (or (re-search-backward regexp nil t)
 (re-search-forward regexp nil t))

Thanks.

-ram

--
http://cynojure.posterous.com


On Jul 1, 3:47 pm, Phil Hagelberg  wrote:
> Chris Dean  writes:
> > Where's the current home for the Emacs clojure-mode source? I have a one
> > line patch I'd like to make, but don't know where to send it!
>
> > Is ithttp://github.com/technomancy/clojure-mode/tree/master ?
>
> That's my repository. Technically the canonical one is 
> athttp://github.com/jochu/clojure-mode/but I have commit access there, so
> I can take care of it. Patches here on the mailing list are welcome.
>
> > Anyway I'll include the patch to add a local-abbrev-table here since it
> > is so small.
>
> It looks like your patch might be incomplete; I get a void-variable:
> clojure-mode-abbrev-table when I run that.
>
> -Phil
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: ClojureQL - 0.9 approaching 1.0

2009-07-02 Thread Ozzi Lee

I get an error when compiling from head with ant. It dies with:

java.lang.ClassNotFoundException: org.mysql.jdbc.Connection (mysql.clj:
18)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Displaying Clojure code on a Website

2009-07-02 Thread Kai

Hi all,

@Laurent

I haven't placed the code anywhere other than on my server. It was
just an experiment in Clojure but I'm glad it's useful to others. I'll
go ahead and make it open source and let you know when I do. It should
be relatively robust as it is -- I ran it through some of the src
Clojure libraries and they look as intended. The only change I
intended to make and never did was to apply the "defn" style to all
types of defs. I'll probably do that before releasing the code on a
repo.

@Rick

I experimented with many different versions of this before I came to
the "large function" format. At first I tried doing it completely
regex which failed miserably. One intention, which I felt would be
much more functional-like, was to split up the code into a list of
functions. For example, code that starts like this:

(defn plus-five [n] (+ 5 n))

Would end up something like this after my parsing:

(format-list "(" (format-def "defn") " " (format-func-name "plus-
five") " [" (format-param-list "n") "] " (format-list "(" (format-func-
name "+") " 5 n)" ) ")" )

It seems wieldy when I write it out but now that it's all parsed as a
list it would be trivial to implement each of those format- functions
and eval the entire thing to generate your desired HTML.

My code didn't start off large, of course. What I did was work
incrementally. First I figured out how to detect string starting and
ending since that seems the simplest. I knew that there had to be some
sort of "state" so that we know when we encounter a quote whether or
not it is the end of a string we've already begun reading. I realized
that in functional languages we already have a stack given to us --
the function stack. So, the next step for me was to see if I could
make this approach work by hopping back and forth between functions.

I got fairly far into this before I had problems with stack overflows.
I found out later than I needed knowledge of trampoline and mutual
recursion to solve the issue. I think the approach still has potential
but the setback forced me to consider other options. This lead me to
implement the stack local in the recursive definition of parse-code.

After I got strings working, it was mostly smooth sailing until I got
to the point where I wanted to highlight the names of variables after
"def" and "defn". Now my approach of reading a character at a time was
becoming quite unorganized. After some more thought experiments, I
decided to give the stack an upgrade and go with a struct to record
state instead of just a keyword. Now I could actually put values on
the stack and therefore keep track of, for example, the first element
of the list that an element is contained in. Continuing down this
path, along with incremental updates, led the code to where it is now.

I did use the REPL extensively to test each new feature. I don't use
an emacs-like editor at all, I coded it in Notepad++. I would simply
paste each snippet of code into the REPL as I write it to make sure
that it works in basic cases. I also used load-file quite often to run
the entire program against sample input and especially itself.

In summary, the "large function" approach wasn't an end goal, it was
just a result of incremental progress. I don't know if it's Clojure-
like which is a big reason that I asked for advice on my first post. I
haven't received any criticism about that yet so I assume it's not a
bad approach. Even though it seems lengthily, it reads linearly and
doesn't have logic scattered in pieces all around. In the end, I think
that's what functional programming is about anyway.

~ Kai

On Jul 2, 6:48 am, Rick Moynihan  wrote:
> 2009/6/26 Kai :
>
>
>
>
>
> > Hi all,
>
> > I'm new to this discussion group and Clojure. I'm sharing the first
> > "bigger-than-REPL" script that I've written because I haven't seen
> > anything else like it for Clojure. It's a script that takes Clojure
> > code as input and generates a pretty HTML version. You can view it
> > here (I ran the script through itself):
>
> >http://kai.myownsiteonline.com/clojure/html.clj.html
>
> > The style sheet is kept separate for cases with more than one Clojure
> > script shown on a page. Also, it still formats just as well without
> > the javascript; the javascript only contains code that highlights
> > Clojure script as you mouse over it.
>
> > I don't have any particular intention by creating this script, it was
> > just a warmup into Clojure. Feel free to use it for whatever purpose.
> > I'd appreciate comments on the coding style as well as how to make it
> > faster - core.clj takes a good 10 minutes! It was a pain and a
> > pleasure to code :)
>
> Cute!
>
> Though I've spent a lot of time over the last 6 months reading about
> and toying with clojure, I've not yet found the time to write anything
> even as substantial as this.  I did however take a quick look at the
> code, and it seems reasonably easy for a noob such as myself to
> follow.
>
> That said, it did remind of something

Re: ClojureQL - 0.9 approaching 1.0

2009-07-02 Thread Meikel Brandmeyer

Hi,

Am 02.07.2009 um 17:16 schrieb Ozzi Lee:


I get an error when compiling from head with ant. It dies with:

java.lang.ClassNotFoundException: org.mysql.jdbc.Connection  
(mysql.clj:

18)


You'll need the JDBC drivers for MySQL and Derby. Otherwise
the corresponding backends won't compile. If you use Ivy (just
don't put the "clojure.jar = .." line into local.properties), it will
download the dependencies for you.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: Emacs clojure-mode home?

2009-07-02 Thread Phil Hagelberg

Ram  Krishnan  writes:

> I'd sent this to jochu earlier, but perhaps you can help commit this
> minor patch to clojure-mode.
>
> I found a small bug in the regexp used in `swank-clojure-find-
> package'. The head version incorrectly parses `ns' forms of the
> following kind:

Thanks; I've pushed this to my fork. I don't have commit rights to the
main swank-clojure, just for clojure-mode. But I've sent a pull request.

-Phil

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

2009-07-02 Thread Stuart Sierra

Hi Ben,
Clojure assumes UTF-8 when loading code.  If you want to load source
code in a different encoding, you can open a java.io.Reader with the
appropriate encoding; the easiest way to do that is probably to use
clojure.contrib.duck-streams and bind *default-encoding*.

-SS


On Jul 2, 2:20 am, B Smith-Mannschott  wrote:
> When clojure loads a source file, how does it know what encoding to
> use? Does it just assume Latin-1? Does it just use platform encoding
> (not the same on all platforms!)? Is there a way to tell it the source
> is UTF-8 encoded? If not, perhaps following the Python/Emacs
> convention might be sensible:
>
>   ; -*- coding: utf-8 -*-
>
> on the first or second line of the file.
>
> How about at the REPL?
>
> // Ben
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



And so it begins...

2009-07-02 Thread dysinger

We need to hire some more devs full time to work on a clojure project
(distributed backend hardcore clojure - not web dev).

I would prefer to have someone in Seattle to work with Philip
Hagelberg (technomancy on IRC).  This would be work from home salary
employment w/ mac laptop provided (or if you prefer - your own
laptop).

If you feel you have clojure under your belt, please drop a resume w/
a note on why you are awesome to j...@sonian.net  If you are involved
in any open source code, please include links.

( Even if you don't live in Seattle but are still a clojure stud/ette
don't hesitate to wave your arms. )

:)

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

2009-07-02 Thread Tom Faulhaber

Hi Parth,

It is on the agenda to support this for pprint, but I don't know
exactly when.

In the meantime, arbitrary bases *are* supported in the common lisp
compatible format function (cl-format) which is also part of
clojure.contrib.pprint.

The interesting directives are ~X, ~B, and ~bR, where b is the base of
interest. For example,

(cl-format nil "~X" 256) => "100"

(cl-format nil "~12r" 256) => "194"

(cl-format true "~{~X ~}~%" [2 4 8 16 32 64 128 256])

prints to *out*:

2 4 8 10 20 40 80 100

For all the dirt on using radix, look at the Common Lisp Hyperspec:
http://www.lispworks.com/documentation/HyperSpec/Body/22_cb.htm

More info about the clojure implementation of format here:
http://code.google.com/p/clojure-contrib/wiki/CommonLispFormat (a
little out of date and about to be moved).

HTH,

Tom
On Jul 2, 1:51 am, Parth Malwankar  wrote:
> I frequently deal with hex and binary numbers.
> As of now when I need to view a list of numbers
> I just map a little hex function to it to translate it
> into a list of hex strings at the repl.
>
> Having something like *print-base* / *print-radix* [1] may be
> valuable in such a scenario
>
> Or maybe an enhanced pprint? Not sure if pprint already provides
> such an option or if its planned.
>
> I would appreciate any comments or ideas if someone
> is doing something similar.
>
> Thanks.
> Parth
> [1]http://www.lispworks.com/documentation/lw50/CLHS/Body/v_pr_bas.htm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Contrib branch compatible with Clojure 1.0

2009-07-02 Thread Stuart Sierra

Hi folks,
I have created a branch of clojure-contrib that should be fully
compatible with Clojure 1.0:
http://github.com/richhickey/clojure-contrib/tree/clojure-1.0-compatible

This includes c.c.test-is with the older syntax for "are".  Maybe this
should be updated to use the newer syntax.

Contrib authors -- if you're making a change that is compatible with
Clojure 1.0, please add it to both the master and clojure-1.0-
compatible branches.

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



Re: loneclojurian at ICFP programming contest

2009-07-02 Thread Nicolas Oury
Hello,
I just have a look at your code. I was wondering why reflect.Array/getDouble
was faster than aget?
And I realized than you create arrays of objects and not array of doubles.

Have you tried to replace make-array by double-array?
I am not a Java specialist but if I understand well the API ot should create
an array of unboxed doubles, making acces really faster. (No creation of
Object when you write, nor indirection when you read).

For access, I would use (double (aget ...)). But I am not sure.

Can a clojure expert tell whether there is something like aget-double or
another way to do it?

You can also try to replace the arithmetic by unchecked arithmetic. (Is it
correct from the point of view of the semantic of the VM you are
implementing?).

Can you try to check in your profiling whether the function you generate get
compiled or not?

What function are you running at the top level? Is that a loop where you run
multiple times the same program?

Best regards,

Nicolas.

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

2009-07-02 Thread fft1976



On Jul 2, 1:01 am, Daniel Lyons  wrote:
> On Jul 2, 2009, at 12:58 AM, fft1976 wrote:
>
> > On Jun 30, 3:02 pm, igorrumiha  wrote:
>
> >> Some people claim
> >> that the JVM can give you C-like performance, but I would be more  
> >> than
> >> happy if I got my VM to be 10x slower than the C ones :)
>
> > I like your honesty! You can come to my house and * my sister!
>
> I wish you wouldn't talk like that.
>

Sorry, it seemed funny when I wrote it:

http://www.youtube.com/watch?v=t8Nf1MK7lts


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

2009-07-02 Thread Takeshi Banse

Signed-off-by: Takeshi Banse 
---

Hi all,
I Takeshi Banse live in Japan, have been teaching myself Clojure and in the
process have a patch to the swank-clojure I'd like to make.

With this patch, I can happily `M-x slime-apropos' within Emacs/SLIME.

Hope this helps. Thanks.

 swank/commands/basic.clj |   61 ++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/swank/commands/basic.clj b/swank/commands/basic.clj
index 47555a4..d668d2d 100644
--- a/swank/commands/basic.clj
+++ b/swank/commands/basic.clj
@@ -161,6 +161,67 @@ (defslimefn documentation-symbol
   ([symbol-name default] (documentation-symbol symbol-name))
   ([symbol-name] (describe-symbol* symbol-name)))
 
+ Documentation
+
+(defn- briefly-describe-symbol-for-emacs [var]
+  (let [lines (fn [s] (seq (.split s (System/getProperty "line.separator"
+[_ symbol-name arglists d1 d2 & __] (lines (describe-to-string var))
+macro? (= d1 "Macro")]
+(list :designator symbol-name
+  (cond
+macro? :macro
+(:arglists ^var) :function
+:else :variable)
+  (apply str (concat arglists (if macro? d2 d1))
+
+(defn- make-apropos-matcher [pattern case-sensitive?]
+  (let [pattern (java.util.regex.Pattern/quote pattern)
+pat (re-pattern (if case-sensitive?
+  pattern
+  (format "(?i:%s)" pattern)))]
+(fn [var] (re-find pat (pr-str var)
+
+(defn- apropos-symbols [string external-only? case-sensitive? package]
+  (let [packages (or (when package [package]) (all-ns))
+matcher (make-apropos-matcher string case-sensitive?)
+lister (if external-only? ns-publics ns-interns)]
+(filter matcher
+(apply concat (map (comp (partial map second) lister)
+   packages)
+
+(defn- present-symbol-before
+  "Comparator such that x belongs before y in a printed summary of symbols.
+Sorted alphabetically by namespace name and then symbol name, except
+that symbols accessible in the current namespace go first."
+  [x y]
+  (let [accessible?
+(fn [var] (= (ns-resolve (maybe-ns *current-package*) (:name ^var))
+ var))
+ax (accessible? x) ay (accessible? y)]
+(cond
+  (and ax ay) (compare (:name ^x) (:name ^y))
+  ax -1
+  ay 1
+  :else (let [nx (str (:ns ^x)) ny (str (:ns ^y))]
+  (if (= nx ny)
+(compare (:name ^x) (:name ^y))
+(compare nx ny))
+
+(defslimefn apropos-list-for-emacs
+  ([name]
+ (apropos-list-for-emacs name nil))
+  ([name external-only?]
+ (apropos-list-for-emacs name external-only? nil))
+  ([name external-only? case-sensitive?]
+ (apropos-list-for-emacs name external-only? case-sensitive? nil))
+  ([name external-only? case-sensitive? package]
+ (let [package (when package
+ (or (find-ns (symbol package))
+ 'user))]
+   (map briefly-describe-symbol-for-emacs
+(sort present-symbol-before
+  (apropos-symbols name external-only? case-sensitive?
+   package))
 
  Operator messages
 (defslimefn operator-arglist [name package]
-- 
1.6.3.3.386.gfe2a5


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



Return nil/null or empty object

2009-07-02 Thread BerlinBrown

I posted a thread about side-effects.  Some one replied that your
clojure functions should return a value.  This is good advice, but I
have code that sometimes return nil.  Is it better to return 'nil' or
an object with no data.  I guess a simple example, if you have a
function that returns a string. Should you return a valid string or a
zero length string for all of your functions.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



unexpected return value

2009-07-02 Thread Mark Volkmann

The following short code snippet compares character literals.
The match function is suppose to return true when given the characters
( and ) or [ and ]. It should return false for everything else.
Why is the output of this code "(" instead of "true"?

(defn match [prev-char next-char]
  (cond = prev-char
\( (= next-char \))
\[ (= next-char \])
true false))

(println (match \( \)))

-- 
R. Mark Volkmann
Object Computing, Inc.

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

2009-07-02 Thread Meikel Brandmeyer

Hi,

Am 02.07.2009 um 19:48 schrieb Mark Volkmann:


(defn match [prev-char next-char]
 (cond = prev-char


Typo: you mean cond*p* instead of cond.


   \( (= next-char \))
   \[ (= next-char \])
   true false))


Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: print-base / print-radix?

2009-07-02 Thread Chouser

On Thu, Jul 2, 2009 at 4:51 AM, Parth
Malwankar wrote:
>
> I frequently deal with hex and binary numbers.
> As of now when I need to view a list of numbers
> I just map a little hex function to it to translate it
> into a list of hex strings at the repl.
>
>
> Having something like *print-base* / *print-radix* [1] may be
> valuable in such a scenario

I don't think Java's built-in formatter is nearly as
flexible as those, but getting hex or octal strings is easy
enough:

user=> (format "%d" 255)
"255"
user=> (format "%o" 255)
"377"
user=> (format "%x" 255)
"ff"
user=> (format "%X" 255)
"FF"

--Chouser

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



Re: Return nil/null or empty object

2009-07-02 Thread Raoul Duke

> clojure functions should return a value.  This is good advice, but I
> have code that sometimes return nil.  Is it better to return 'nil' or
> an object with no data.  I guess a simple example, if you have a

imho, null/nil/etc. are more often than not pretty evil.

random related links:
http://lukeplant.me.uk/blog.php?id=1107301659
http://weblogs.asp.net/fmarguerie/archive/2009/02/12/null-object-design-pattern.aspx

sincerely.

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



*command-line-args*

2009-07-02 Thread Mark Volkmann

I'm confused about *command-line-args*.

I have a file demo.clj containing only this:

(println (class *command-line-args*))
(println (count *command-line-args*))

I run it with "clj demo.clj foo bar baz" and get this output:

clojure.lang.ArraySeq
2

I get the same output with "clj demo.clj -- foo bar baz".

Why doesn't it output 3?

-- 
R. Mark Volkmann
Object Computing, Inc.

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

2009-07-02 Thread Meikel Brandmeyer

Hi again,

Am 02.07.2009 um 19:52 schrieb Meikel Brandmeyer:


(defn match [prev-char next-char]
(cond = prev-char


Typo: you mean cond*p* instead of cond.


  \( (= next-char \))
  \[ (= next-char \])
  true false))


And BTW: the true shouldn't be there. If there
is an odd number of clauses, the last one is
returned of the match is found.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: Return nil/null or empty object

2009-07-02 Thread Daniel Lyons


On Jul 2, 2009, at 11:48 AM, BerlinBrown wrote:

>
> I posted a thread about side-effects.  Some one replied that your
> clojure functions should return a value.  This is good advice, but I
> have code that sometimes return nil.  Is it better to return 'nil' or
> an object with no data.  I guess a simple example, if you have a
> function that returns a string. Should you return a valid string or a
> zero length string for all of your functions.


I don't really understand your example. A zero length string is a  
valid string. Could you elaborate?

If your function is called simply for its side effect, the return  
value isn't very important. But if it's guaranteed to work and takes a  
single parameter I usually just return the argument. That way you can  
stack your function calls. In general it's a good idea to separate the  
logic from the side effects. It makes testing easier and pure  
functions are more composable and reusable.

—
Daniel Lyons


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

2009-07-02 Thread Stephen C. Gilardi


On Jul 2, 2009, at 2:00 PM, Mark Volkmann wrote:


I run it with "clj demo.clj foo bar baz" and get this output:

clojure.lang.ArraySeq
2

I get the same output with "clj demo.clj -- foo bar baz".

Why doesn't it output 3?


That depends on your definition of clj.

Here's what I get without using a launcher script:

 % java -cp /sq/ext/clojure/clojure.jar clojure.main demo.clj foo bar  
baz

 clojure.lang.ArraySeq
 3
 (foo bar baz)

(I added (println *command-line-args*) to my demo.clj. You might get  
some good info by adding it yours as well.)


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Contrib branch compatible with Clojure 1.0

2009-07-02 Thread Chouser

On Thu, Jul 2, 2009 at 12:58 PM, Stuart
Sierra wrote:
>
> Hi folks,
> I have created a branch of clojure-contrib that should be fully
> compatible with Clojure 1.0:
> http://github.com/richhickey/clojure-contrib/tree/clojure-1.0-compatible
>
> This includes c.c.test-is with the older syntax for "are".  Maybe this
> should be updated to use the newer syntax.
>
> Contrib authors -- if you're making a change that is compatible with
> Clojure 1.0, please add it to both the master and clojure-1.0-
> compatible branches.

Stuart -- thanks for doing this!  Any plans for making a .jar or .zip available
somewhere?

Also, is there any reason not to call this contrib-1.0?  It seems to me that it
would be most useful to have major contrib versions simply map to major clojure
versions:  contrib-1.a.x for clojure-1.a.y


Anyway, regardless of what it's called, I'm grateful someone has done
it.  Thanks again, Stuart!
--Chouser

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

2009-07-02 Thread Stephen C. Gilardi


On Jul 2, 2009, at 1:48 PM, Mark Volkmann wrote:


(defn match [prev-char next-char]
 (cond = prev-char
   \( (= next-char \))
   \[ (= next-char \])
   true false))


It looks like you intended condp here instead of cond.

Your test works as expected if you make that change. However, there's  
another correction required to allow match to work in the general  
case. The last clause should be "false" instead of "true false". If  
it's not, then any prev-chars except \(, \[, and true will throw an  
exception.


--
volkmann.clj (on classpath):
--

(ns volkmann)

(defn match [prev-char next-char]
 (condp = prev-char
   \( (= next-char \))
   \[ (= next-char \])
   false))

(defn main
  []
  (prn
   (match \( \))
   (match \r \

--
using clojure.contrib.repl-utils/run
--

user=> (run volkmann)
true false
nil
user=>

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Displaying Clojure code on a Website

2009-07-02 Thread Laurent PETIT

Hi Kai,

2009/7/2 Kai :
>
> Hi all,
>
> @Laurent
>
> I haven't placed the code anywhere other than on my server. It was
> just an experiment in Clojure but I'm glad it's useful to others. I'll
> go ahead and make it open source and let you know when I do. It should
> be relatively robust as it is -- I ran it through some of the src
> Clojure libraries and they look as intended. The only change I
> intended to make and never did was to apply the "defn" style to all
> types of defs. I'll probably do that before releasing the code on a
> repo.

Ok, I'll wait then, thanks.

BTW, I don't really understand how you could have StackOverflows. I
would expect that the solving algorithm would make the size of the
call stack proportional to the depth of the datastructure graph ? If
so, I guess that even the most evil human created code would not reach
the StackOverflow limit ?

Regards,

-- 
Laurent

>
> @Rick
>
> I experimented with many different versions of this before I came to
> the "large function" format. At first I tried doing it completely
> regex which failed miserably. One intention, which I felt would be
> much more functional-like, was to split up the code into a list of
> functions. For example, code that starts like this:
>
> (defn plus-five [n] (+ 5 n))
>
> Would end up something like this after my parsing:
>
> (format-list "(" (format-def "defn") " " (format-func-name "plus-
> five") " [" (format-param-list "n") "] " (format-list "(" (format-func-
> name "+") " 5 n)" ) ")" )
>
> It seems wieldy when I write it out but now that it's all parsed as a
> list it would be trivial to implement each of those format- functions
> and eval the entire thing to generate your desired HTML.
>
> My code didn't start off large, of course. What I did was work
> incrementally. First I figured out how to detect string starting and
> ending since that seems the simplest. I knew that there had to be some
> sort of "state" so that we know when we encounter a quote whether or
> not it is the end of a string we've already begun reading. I realized
> that in functional languages we already have a stack given to us --
> the function stack. So, the next step for me was to see if I could
> make this approach work by hopping back and forth between functions.
>
> I got fairly far into this before I had problems with stack overflows.
> I found out later than I needed knowledge of trampoline and mutual
> recursion to solve the issue. I think the approach still has potential
> but the setback forced me to consider other options. This lead me to
> implement the stack local in the recursive definition of parse-code.
>
> After I got strings working, it was mostly smooth sailing until I got
> to the point where I wanted to highlight the names of variables after
> "def" and "defn". Now my approach of reading a character at a time was
> becoming quite unorganized. After some more thought experiments, I
> decided to give the stack an upgrade and go with a struct to record
> state instead of just a keyword. Now I could actually put values on
> the stack and therefore keep track of, for example, the first element
> of the list that an element is contained in. Continuing down this
> path, along with incremental updates, led the code to where it is now.
>
> I did use the REPL extensively to test each new feature. I don't use
> an emacs-like editor at all, I coded it in Notepad++. I would simply
> paste each snippet of code into the REPL as I write it to make sure
> that it works in basic cases. I also used load-file quite often to run
> the entire program against sample input and especially itself.
>
> In summary, the "large function" approach wasn't an end goal, it was
> just a result of incremental progress. I don't know if it's Clojure-
> like which is a big reason that I asked for advice on my first post. I
> haven't received any criticism about that yet so I assume it's not a
> bad approach. Even though it seems lengthily, it reads linearly and
> doesn't have logic scattered in pieces all around. In the end, I think
> that's what functional programming is about anyway.
>
> ~ Kai
>
> On Jul 2, 6:48 am, Rick Moynihan  wrote:
>> 2009/6/26 Kai :
>>
>>
>>
>>
>>
>> > Hi all,
>>
>> > I'm new to this discussion group and Clojure. I'm sharing the first
>> > "bigger-than-REPL" script that I've written because I haven't seen
>> > anything else like it for Clojure. It's a script that takes Clojure
>> > code as input and generates a pretty HTML version. You can view it
>> > here (I ran the script through itself):
>>
>> >http://kai.myownsiteonline.com/clojure/html.clj.html
>>
>> > The style sheet is kept separate for cases with more than one Clojure
>> > script shown on a page. Also, it still formats just as well without
>> > the javascript; the javascript only contains code that highlights
>> > Clojure script as you mouse over it.
>>
>> > I don't have any particular intention by creating this script, it was
>> > just a warmup into Clojure. Feel free to

parsing program for nested parens and square brackets

2009-07-02 Thread Mark Volkmann

There is a challenge on the blog of Tony Morris at
http://dibblego.wordpress.com/2008/09/05/haskell-scala-java-7-functional-java-java/#comment-2460.
It's a parsing problem for which he compares solutions in Haskell,
Scala and Java. I added a Clojure solution. I don't know if this is
the "best" way to solve this with Clojure, but it certainly works.
Here's my code, including unit tests.

(use 'clojure.test)

(defn- match [prev-char next-char]
  (condp = prev-char
\( (= next-char \))
\[ (= next-char \])
false))

; Need a better name for this function.
(defn- helper [s stack]
  (if (empty? s)
(empty? stack)
(let [c (first s)
  top (first stack)
  stack (if (match top c) (next stack) (cons c stack))]
  (helper (next s) stack

(defn balanced? [s] (helper s '()))

(doseq [arg *command-line-args*]
  (println (balanced? arg)))

(deftest match-test
  (is (match \( \)))
  (is (match \[ \]))
  (is (not (match \( \{

(deftest balanced-test
  (is (balanced? "()"))
  (is (balanced? "[]"))
  (is (balanced? "([])"))
  (is (balanced? "[()]"))
  (is (balanced? "[]()"))
  (is (balanced? "[][[([])]]"))
  (is (not (balanced? "(")))
  (is (not (balanced? ")")))
  (is (not (balanced? "[")))
  (is (not (balanced? "]")))
  (is (not (balanced? "][")))
  (is (not (balanced? ")(")))
  (is (not (balanced? "( )")))
  (is (not (balanced? "([)")))
  (is (not (balanced? "[)]")))
  (is (not (balanced? "([)]")))
  (is (not (balanced? "({})")))
  (is (not (balanced? "[())]"

(run-tests)

-- 
R. Mark Volkmann
Object Computing, Inc.

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

2009-07-02 Thread Ozzi Lee

It looks like ant is using ivy to get these dependencies, unless I'm
reading it wrong.

Is this what I need?
http://dev.mysql.com/downloads/connector/j/3.1.html

$ ant

Buildfile: build.xml

init:

download-ivy:
  [get] Getting: 
http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.1.0-rc1/ivy-2.1.0-rc1.jar
  [get] To: /home/nroling/repos/clojureql/lib/ivy.jar
  [get] Not modified - so not downloaded

install-ivy:

resolve:
No ivy:settings found for the default reference 'ivy.instance'.  A
default instance will be used
[ivy:resolve] :: Ivy 2.1.0-rc1 - 20090319213629 :: http://ant.apache.org/ivy/
::
:: loading settings :: file = /home/nroling/repos/clojureql/
ivysettings.xml
[ivy:resolve] :: resolving dependencies ::
dk.bestinclass#clojureql;work...@nroling-desktop
[ivy:resolve]   confs: [source, compiled, derby, mysql, default]
[ivy:resolve]   found org.clojure#clojure;1.0.0 in KotkaRepo
[ivy:resolve]   found org.apache.derby#derby;10.4.2.0 in public
[ivy:resolve]   found mysql#mysql-connector-java;5.1.6 in public
[ivy:resolve] :: resolution report :: resolve 155ms :: artifacts dl
8ms
-
|  |modules||   artifacts   |
|   conf   | number| search|dwnlded|evicted|| number|dwnlded|
-
|  source  |   1   |   0   |   0   |   0   ||   1   |   0   |
| compiled |   1   |   0   |   0   |   0   ||   1   |   0   |
|   derby  |   1   |   0   |   0   |   0   ||   1   |   0   |
|   mysql  |   1   |   0   |   0   |   0   ||   1   |   0   |
|  default |   1   |   0   |   0   |   0   ||   2   |   0   |
-
[ivy:retrieve] :: retrieving :: dk.bestinclass#clojureql
[ivy:retrieve]  confs: [source, compiled, derby, mysql, default]
[ivy:retrieve]  0 artifacts copied, 6 already retrieved (0kB/15ms)

aot:
 [java] Compiling dk.bestinclass.clojureql.util to /home/nroling/
repos/clojureql/classes
 [java] Compiling dk.bestinclass.clojureql to /home/nroling/repos/
clojureql/classes
 [java] Compiling dk.bestinclass.clojureql.backend.derby to /home/
nroling/repos/clojureql/classes
 [java] Compiling dk.bestinclass.clojureql.backend.mysql to /home/
nroling/repos/clojureql/classes

BUILD FAILED
java.lang.ClassNotFoundException: org.mysql.jdbc.Connection (mysql.clj:
18)
at clojure.lang.Compiler.analyze(Compiler.java:4340)
at clojure.lang.Compiler.analyze(Compiler.java:4286)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:2771)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:4498)
at clojure.lang.Compiler.analyze(Compiler.java:4325)
at clojure.lang.Compiler.analyze(Compiler.java:4286)
at clojure.lang.Compiler.compile(Compiler.java:4948)
at clojure.lang.RT.compile(RT.java:354)
at clojure.lang.RT.load(RT.java:393)
at clojure.lang.RT.load(RT.java:367)
at clojure.core$load__5058$fn__5061.invoke(core.clj:3734)
at clojure.core$load__5058.doInvoke(core.clj:3733)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.core$load_one__5010.invoke(core.clj:3578)
at clojure.core$compile__5065$fn__5067.invoke(core.clj:3744)
at clojure.core$compile__5065.invoke(core.clj:3743)
at clojure.lang.Var.invoke(Var.java:346)
at clojure.lang.Compile.main(Compile.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:
217)
at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:
152)
at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:
288)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute
(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.

Re: Contrib branch compatible with Clojure 1.0

2009-07-02 Thread Stuart Sierra

On Jul 2, 2:17 pm, Chouser  wrote:
> Also, is there any reason not to call this contrib-1.0?  It seems to me that 
> it
> would be most useful to have major contrib versions simply map to major 
> clojure
> versions:  contrib-1.a.x for clojure-1.a.y

The consensus on the dev list seemed to be that "Contrib 1.0" would
imply a degree of coherence and stability that many contrib libraries
have not yet achieved.

I'm happy to leave contrib as-is and let different parts evolve at
their own pace.  Libraries that experience heavy use and minimal
changes can be nominated for inclusion with Clojure itself, as
recently happened to c.c.test-is.

But a JAR to include with the Clojure 1.0 distribution would be good.
Let people find out if anything is missing/broken in the contrib
branch, and then we can make one.

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



Re: parsing program for nested parens and square brackets

2009-07-02 Thread Stuart Halloway

Hi Mark,

The balanced-test would be a great place to use "are" instead of "is".

Cheers,
Stu

>
> There is a challenge on the blog of Tony Morris at
> http://dibblego.wordpress.com/2008/09/05/haskell-scala-java-7-functional-java-java/#comment-2460
>  
> .
> It's a parsing problem for which he compares solutions in Haskell,
> Scala and Java. I added a Clojure solution. I don't know if this is
> the "best" way to solve this with Clojure, but it certainly works.
> Here's my code, including unit tests.
>
> (use 'clojure.test)
>
> (defn- match [prev-char next-char]
>  (condp = prev-char
>\( (= next-char \))
>\[ (= next-char \])
>false))
>
> ; Need a better name for this function.
> (defn- helper [s stack]
>  (if (empty? s)
>(empty? stack)
>(let [c (first s)
>  top (first stack)
>  stack (if (match top c) (next stack) (cons c stack))]
>  (helper (next s) stack
>
> (defn balanced? [s] (helper s '()))
>
> (doseq [arg *command-line-args*]
>  (println (balanced? arg)))
>
> (deftest match-test
>  (is (match \( \)))
>  (is (match \[ \]))
>  (is (not (match \( \{
>
> (deftest balanced-test
>  (is (balanced? "()"))
>  (is (balanced? "[]"))
>  (is (balanced? "([])"))
>  (is (balanced? "[()]"))
>  (is (balanced? "[]()"))
>  (is (balanced? "[][[([])]]"))
>  (is (not (balanced? "(")))
>  (is (not (balanced? ")")))
>  (is (not (balanced? "[")))
>  (is (not (balanced? "]")))
>  (is (not (balanced? "][")))
>  (is (not (balanced? ")(")))
>  (is (not (balanced? "( )")))
>  (is (not (balanced? "([)")))
>  (is (not (balanced? "[)]")))
>  (is (not (balanced? "([)]")))
>  (is (not (balanced? "({})")))
>  (is (not (balanced? "[())]"
>
> (run-tests)
>
> -- 
> R. Mark Volkmann
> Object Computing, Inc.
>
> >


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

2009-07-02 Thread B Smith-Mannschott

On Thu, Jul 2, 2009 at 18:39, Stuart Sierra wrote:
>
> Hi Ben,
> Clojure assumes UTF-8 when loading code.  If you want to load source
> code in a different encoding, you can open a java.io.Reader with the
> appropriate encoding; the easiest way to do that is probably to use
> clojure.contrib.duck-streams and bind *default-encoding*.
>

Thanks, that's great. Defaulting to UTF-8 is the Right Thing to do,
IMHO. I tried it out and found that I can, for example, name variables
with greek letters. Neat.

What was confusing me is that slime/swank seem to be using
iso-latin-1-unix and so trip over greek letters. I've not yet found
the knobs to twiddle in emacs to get it to use UTF-8 here, but at
least the problem is not Clojure.

// Ben

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



Re: parsing program for nested parens and square brackets

2009-07-02 Thread Laurent PETIT

Hi,

I think you could use recur instead of the direct recursive call,

Regards,

-- 
Laurent

2009/7/2 Mark Volkmann :
>
> There is a challenge on the blog of Tony Morris at
> http://dibblego.wordpress.com/2008/09/05/haskell-scala-java-7-functional-java-java/#comment-2460.
> It's a parsing problem for which he compares solutions in Haskell,
> Scala and Java. I added a Clojure solution. I don't know if this is
> the "best" way to solve this with Clojure, but it certainly works.
> Here's my code, including unit tests.
>
> (use 'clojure.test)
>
> (defn- match [prev-char next-char]
>  (condp = prev-char
>    \( (= next-char \))
>    \[ (= next-char \])
>    false))
>
> ; Need a better name for this function.
> (defn- helper [s stack]
>  (if (empty? s)
>    (empty? stack)
>    (let [c (first s)
>          top (first stack)
>          stack (if (match top c) (next stack) (cons c stack))]
>      (helper (next s) stack
>
> (defn balanced? [s] (helper s '()))
>
> (doseq [arg *command-line-args*]
>  (println (balanced? arg)))
>
> (deftest match-test
>  (is (match \( \)))
>  (is (match \[ \]))
>  (is (not (match \( \{
>
> (deftest balanced-test
>  (is (balanced? "()"))
>  (is (balanced? "[]"))
>  (is (balanced? "([])"))
>  (is (balanced? "[()]"))
>  (is (balanced? "[]()"))
>  (is (balanced? "[][[([])]]"))
>  (is (not (balanced? "(")))
>  (is (not (balanced? ")")))
>  (is (not (balanced? "[")))
>  (is (not (balanced? "]")))
>  (is (not (balanced? "][")))
>  (is (not (balanced? ")(")))
>  (is (not (balanced? "( )")))
>  (is (not (balanced? "([)")))
>  (is (not (balanced? "[)]")))
>  (is (not (balanced? "([)]")))
>  (is (not (balanced? "({})")))
>  (is (not (balanced? "[())]"
>
> (run-tests)
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
> >
>

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

2009-07-02 Thread Mark Volkmann

On Thu, Jul 2, 2009 at 1:59 PM, Stuart
Halloway wrote:
>
> Hi Mark,
>
> The balanced-test would be a great place to use "are" instead of "is".

Excellent suggestion!  The new version of that function follows:

(deftest balanced-test
  (are [text result]
(= (balanced? text) result)
"()" true
"[]" true
"([])" true
"[()]" true
"[]()" true
"[][[([])]]" true
"(" false
")" false
"[" false
"]" false
"][" false
")(" false
"( )" false
"([)" false
"[)]" false
"([)]" false
"({})" false
"[())]") false)

>> There is a challenge on the blog of Tony Morris at
>> http://dibblego.wordpress.com/2008/09/05/haskell-scala-java-7-functional-java-java/#comment-2460
>> .
>> It's a parsing problem for which he compares solutions in Haskell,
>> Scala and Java. I added a Clojure solution. I don't know if this is
>> the "best" way to solve this with Clojure, but it certainly works.
>> Here's my code, including unit tests.
>>
>> (use 'clojure.test)
>>
>> (defn- match [prev-char next-char]
>>  (condp = prev-char
>>    \( (= next-char \))
>>    \[ (= next-char \])
>>    false))
>>
>> ; Need a better name for this function.
>> (defn- helper [s stack]
>>  (if (empty? s)
>>    (empty? stack)
>>    (let [c (first s)
>>          top (first stack)
>>          stack (if (match top c) (next stack) (cons c stack))]
>>      (helper (next s) stack
>>
>> (defn balanced? [s] (helper s '()))
>>
>> (doseq [arg *command-line-args*]
>>  (println (balanced? arg)))
>>
>> (deftest match-test
>>  (is (match \( \)))
>>  (is (match \[ \]))
>>  (is (not (match \( \{
>>
>> (deftest balanced-test
>>  (is (balanced? "()"))
>>  (is (balanced? "[]"))
>>  (is (balanced? "([])"))
>>  (is (balanced? "[()]"))
>>  (is (balanced? "[]()"))
>>  (is (balanced? "[][[([])]]"))
>>  (is (not (balanced? "(")))
>>  (is (not (balanced? ")")))
>>  (is (not (balanced? "[")))
>>  (is (not (balanced? "]")))
>>  (is (not (balanced? "][")))
>>  (is (not (balanced? ")(")))
>>  (is (not (balanced? "( )")))
>>  (is (not (balanced? "([)")))
>>  (is (not (balanced? "[)]")))
>>  (is (not (balanced? "([)]")))
>>  (is (not (balanced? "({})")))
>>  (is (not (balanced? "[())]"
>>
>> (run-tests)
>>
>> --
>> R. Mark Volkmann
>> Object Computing, Inc.
>>
>> >
>
>
> >
>



-- 
R. Mark Volkmann
Object Computing, Inc.

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

2009-07-02 Thread Mark Volkmann

On Thu, Jul 2, 2009 at 2:04 PM, Laurent PETIT wrote:
>
> Hi,
>
> I think you could use recur instead of the direct recursive call,

Great idea! Simply changing "helper" to "recur" works.

> 2009/7/2 Mark Volkmann :
>>
>> There is a challenge on the blog of Tony Morris at
>> http://dibblego.wordpress.com/2008/09/05/haskell-scala-java-7-functional-java-java/#comment-2460.
>> It's a parsing problem for which he compares solutions in Haskell,
>> Scala and Java. I added a Clojure solution. I don't know if this is
>> the "best" way to solve this with Clojure, but it certainly works.
>> Here's my code, including unit tests.
>>
>> (use 'clojure.test)
>>
>> (defn- match [prev-char next-char]
>>  (condp = prev-char
>>    \( (= next-char \))
>>    \[ (= next-char \])
>>    false))
>>
>> ; Need a better name for this function.
>> (defn- helper [s stack]
>>  (if (empty? s)
>>    (empty? stack)
>>    (let [c (first s)
>>          top (first stack)
>>          stack (if (match top c) (next stack) (cons c stack))]
>>      (helper (next s) stack
>>
>> (defn balanced? [s] (helper s '()))
>>
>> (doseq [arg *command-line-args*]
>>  (println (balanced? arg)))
>>
>> (deftest match-test
>>  (is (match \( \)))
>>  (is (match \[ \]))
>>  (is (not (match \( \{
>>
>> (deftest balanced-test
>>  (is (balanced? "()"))
>>  (is (balanced? "[]"))
>>  (is (balanced? "([])"))
>>  (is (balanced? "[()]"))
>>  (is (balanced? "[]()"))
>>  (is (balanced? "[][[([])]]"))
>>  (is (not (balanced? "(")))
>>  (is (not (balanced? ")")))
>>  (is (not (balanced? "[")))
>>  (is (not (balanced? "]")))
>>  (is (not (balanced? "][")))
>>  (is (not (balanced? ")(")))
>>  (is (not (balanced? "( )")))
>>  (is (not (balanced? "([)")))
>>  (is (not (balanced? "[)]")))
>>  (is (not (balanced? "([)]")))
>>  (is (not (balanced? "({})")))
>>  (is (not (balanced? "[())]"
>>
>> (run-tests)

-- 
R. Mark Volkmann
Object Computing, Inc.

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



Re: Return nil/null or empty object

2009-07-02 Thread Chouser

On Thu, Jul 2, 2009 at 1:59 PM, Raoul Duke wrote:
>
>> clojure functions should return a value.  This is good advice, but I
>> have code that sometimes return nil.  Is it better to return 'nil' or
>> an object with no data.  I guess a simple example, if you have a
>
> imho, null/nil/etc. are more often than not pretty evil.
>
> random related links:
> http://lukeplant.me.uk/blog.php?id=1107301659
> http://weblogs.asp.net/fmarguerie/archive/2009/02/12/null-object-design-pattern.aspx

That may be somewhat less relevant:

(map int "foo")  ==> (102 111 111)
(map int "")  ==> ()
(map int nil)  ==> ()

In general, almost anything that can handle an empty
collection will behave the same when given nil.

So when designing your API you may want to consider:

1. Do you need to differentiate between an empty collection
   an nil?

   For example, perhaps an empty string means the user left
   a field blank, but nil means they've not yet been given
   the opportunity to fill it out.  Or some other more useful
   example. :-P

2. Will your user want to conj onto the thing you return?

   In some cases it's convenient to take, say, a vector
   returned by some function and just 'conj' onto it.
   Returning nil would cause such user code to build an list
   instead of a vector, and this may not be what you want.

3. Do you want to make plain truth tests useless?

   On the other hand, returning an empty collection forces
   the user to use 'empty?' like this:

   (when-not (empty? (my-things x))
 (do something with my-things))

   ...obscuring the main point of the test in layers of
   'not' and 'empty?'.  While returning nil allows
   nil-punning like:

   (when (my-things x)
 (do something with my-things))

   It gets worse if the user was hoping to use when-let...

4. Is laziness a factor?

   If a collection is empty 'rest' returns an empty seq, but
   'next' returns nil.  In fact, this is a defining
   difference between the two functions.

   The reason in this case is that in order to return nil for
   an empty collection, you first need to find out if the
   collection is empty which forces the realization of more
   of a lazy seq than you sometimes want, so 'rest' refuses
   and simply returns the un-realized rest of the seq.

   Conversely, you often don't care about that extra laziness
   and want the convenience of nil-punning in which case
   'next' is perfect.

So these are all things to keep in mind, and there are
probably others as well.  However in practice it often turns
out that what's easiest to write in your API code is also
what will be most convenient for your users.  For example,
for cases where point 2 resonates with you, it's also likely
you're getting that empty vector by doing something like
'pop', which will itself return an empty vector rather than
nil.  Conversely, if 3 seem more important in your case,
it's like you're could you 'when' in your API code, which
returns nil (not an empty collection) in false cases.

--Chouser

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

2009-07-02 Thread Daniel Lyons


On Jul 2, 2009, at 1:00 PM, B Smith-Mannschott wrote:

>
> On Thu, Jul 2, 2009 at 18:39, Stuart Sierra > wrote:
>>
>> Hi Ben,
>> Clojure assumes UTF-8 when loading code.  If you want to load source
>> code in a different encoding, you can open a java.io.Reader with the
>> appropriate encoding; the easiest way to do that is probably to use
>> clojure.contrib.duck-streams and bind *default-encoding*.
>>
>
> Thanks, that's great. Defaulting to UTF-8 is the Right Thing to do,
> IMHO. I tried it out and found that I can, for example, name variables
> with greek letters. Neat.
>
> What was confusing me is that slime/swank seem to be using
> iso-latin-1-unix and so trip over greek letters. I've not yet found
> the knobs to twiddle in emacs to get it to use UTF-8 here, but at
> least the problem is not Clojure.


(setq slime-net-coding-system 'utf-8-unix)

:)

user> (def שלם 'peace)
#'user/שלם
user> שלם
peace

Interestingly, Emacs doesn't seem to change the writing direction, but  
when I pasted it into my mail client it did the right (-to-left)  
thing. This stuff is tricky.

—
Daniel Lyons


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

2009-07-02 Thread Tayssir John Gabbour

Hi Ben,

This is sitting in my .emacs file:

  (set-language-environment "UTF-8")
  (setq slime-net-coding-system 'utf-8-unix)

(I don't know whether it'll work for you, just as I don't know whether
all the things sitting in my fridge are edible... Good luck. ;)


Tayssir


On Jul 2, 9:00 pm, B Smith-Mannschott  wrote:
> On Thu, Jul 2, 2009 at 18:39, Stuart Sierra 
> wrote:
>
> > Hi Ben,
> > Clojure assumes UTF-8 when loading code.  If you want to load source
> > code in a different encoding, you can open a java.io.Reader with the
> > appropriate encoding; the easiest way to do that is probably to use
> > clojure.contrib.duck-streams and bind *default-encoding*.
>
> Thanks, that's great. Defaulting to UTF-8 is the Right Thing to do,
> IMHO. I tried it out and found that I can, for example, name variables
> with greek letters. Neat.
>
> What was confusing me is that slime/swank seem to be using
> iso-latin-1-unix and so trip over greek letters. I've not yet found
> the knobs to twiddle in emacs to get it to use UTF-8 here, but at
> least the problem is not Clojure.
>
> // Ben
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: parsing program for nested parens and square brackets

2009-07-02 Thread Laurent PETIT

There are also peek and pop functions in core that you could you to
convey the semantics of using the cons list as a stack.

As far as performance is on the table, I'm not sure whether of
cons'ing over lists or conj'ing over vectors would have the better
performance (maybe it's just comparable ! :-)

2009/7/2 Mark Volkmann :
>
> On Thu, Jul 2, 2009 at 2:04 PM, Laurent PETIT wrote:
>>
>> Hi,
>>
>> I think you could use recur instead of the direct recursive call,
>
> Great idea! Simply changing "helper" to "recur" works.
>
>> 2009/7/2 Mark Volkmann :
>>>
>>> There is a challenge on the blog of Tony Morris at
>>> http://dibblego.wordpress.com/2008/09/05/haskell-scala-java-7-functional-java-java/#comment-2460.
>>> It's a parsing problem for which he compares solutions in Haskell,
>>> Scala and Java. I added a Clojure solution. I don't know if this is
>>> the "best" way to solve this with Clojure, but it certainly works.
>>> Here's my code, including unit tests.
>>>
>>> (use 'clojure.test)
>>>
>>> (defn- match [prev-char next-char]
>>>  (condp = prev-char
>>>    \( (= next-char \))
>>>    \[ (= next-char \])
>>>    false))
>>>
>>> ; Need a better name for this function.
>>> (defn- helper [s stack]
>>>  (if (empty? s)
>>>    (empty? stack)
>>>    (let [c (first s)
>>>          top (first stack)
>>>          stack (if (match top c) (next stack) (cons c stack))]
>>>      (helper (next s) stack
>>>
>>> (defn balanced? [s] (helper s '()))
>>>
>>> (doseq [arg *command-line-args*]
>>>  (println (balanced? arg)))
>>>
>>> (deftest match-test
>>>  (is (match \( \)))
>>>  (is (match \[ \]))
>>>  (is (not (match \( \{
>>>
>>> (deftest balanced-test
>>>  (is (balanced? "()"))
>>>  (is (balanced? "[]"))
>>>  (is (balanced? "([])"))
>>>  (is (balanced? "[()]"))
>>>  (is (balanced? "[]()"))
>>>  (is (balanced? "[][[([])]]"))
>>>  (is (not (balanced? "(")))
>>>  (is (not (balanced? ")")))
>>>  (is (not (balanced? "[")))
>>>  (is (not (balanced? "]")))
>>>  (is (not (balanced? "][")))
>>>  (is (not (balanced? ")(")))
>>>  (is (not (balanced? "( )")))
>>>  (is (not (balanced? "([)")))
>>>  (is (not (balanced? "[)]")))
>>>  (is (not (balanced? "([)]")))
>>>  (is (not (balanced? "({})")))
>>>  (is (not (balanced? "[())]"
>>>
>>> (run-tests)
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
> >
>

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

2009-07-02 Thread Mark Volkmann

On Thu, Jul 2, 2009 at 2:13 PM, Laurent PETIT wrote:
>
> There are also peek and pop functions in core that you could you to
> convey the semantics of using the cons list as a stack.

Yes, that's a nice improvement!  Here's the new code without the tests
which didn't change. Now it is using a vector instead of a list. Too
bad there is no push function in core. I'm using conj.

(defn- match [prev-char next-char]
  (condp = prev-char
\( (= next-char \))
\[ (= next-char \])
false))

(defn- balanced-helper [s stack]
  (if (empty? s)
(empty? stack)
(let [c (first s)
  top (peek stack)
  stack (if (match top c) (pop stack) (conj stack c))]
  (recur (next s) stack

(defn balanced? [s] (balanced-helper s []))

(doseq [arg *command-line-args*]
  (println (balanced? arg)))

> As far as performance is on the table, I'm not sure whether of
> cons'ing over lists or conj'ing over vectors would have the better
> performance (maybe it's just comparable ! :-)

-- 
R. Mark Volkmann
Object Computing, Inc.

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

2009-07-02 Thread Marek Kubica

On Thu, 2 Jul 2009 08:15:32 -0700 (PDT)
Kai  wrote:

> I haven't placed the code anywhere other than on my server. It was
> just an experiment in Clojure but I'm glad it's useful to others. I'll
> go ahead and make it open source and let you know when I do. It should
> be relatively robust as it is -- I ran it through some of the src
> Clojure libraries and they look as intended.

Btw, Pygments  supports Clojure too. Though it is
not written in Clojure ;)

regards,
Marek

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

2009-07-02 Thread Stephen C. Gilardi


On Jul 2, 2009, at 3:21 PM, Mark Volkmann wrote:


Now it is using a vector instead of a list. Too
bad there is no push function in core. I'm using conj.


conj is the correct thing to use for the push operation.

Here's my take on it based on yours. This bails early as soon as there  
is a mismatch or an illegal character:


(ns challenge
  (:use clojure.test))

(def lefts #{\( \[})
(def matches {\( \) \[ \]})

(defn balanced? [s]
  (loop [s s stack ()]
(if (seq s)
  (let [[c & s] s]
(if (lefts c)
  (recur s (conj stack c))
  (if (= (matches (peek stack)) c)
(recur s (pop stack))
false)))
  (empty? stack

(deftest balanced-test
 (are [text result]
   (= (balanced? text) result)
   "()" true
   "[]" true
   "([])" true
   "[()]" true
   "[]()" true
   "[][[([])]]" true
   "(" false
   ")" false
   "[" false
   "]" false
   "][" false
   ")(" false
   "( )" false
   "([)" false
   "[)]" false
   "([)]" false
   "({})" false
   "[())]") false)

(defn main []
  (run-tests 'challenge))

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Blog on the history of C++

2009-07-02 Thread Sean Devlin

Hey all,
I found this blog entry on how C++ replaced C, and it made me think of
how Clojure interacts with Java.  Not a direct comparison, but I
figure I'm not the only on who'll like it.

http://ejohnson.blogs.com/software/2004/11/i_find_c_intere.html

Hope someone enjoys 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: parsing program for nested parens and square brackets

2009-07-02 Thread Mark Volkmann

On Thu, Jul 2, 2009 at 2:46 PM, Stephen C. Gilardi wrote:
>
> On Jul 2, 2009, at 3:21 PM, Mark Volkmann wrote:
>
>> Now it is using a vector instead of a list. Too
>> bad there is no push function in core. I'm using conj.
>
> conj is the correct thing to use for the push operation.

Right, but the point Laurent was making is that using peek and pop are
good because they convey the fact that I'm using a vector as a stack.
For that reason it would be nice if there was a push function to go
along with peek and pop.

> Here's my take on it based on yours. This bails early as soon as there is a
> mismatch or an illegal character:

Yeah, I realized mine wasn't doing that, but was happy that it gave
the correct result anyway since the illegal characters get added to
the stack and are never popped off. Your implementation is certainly
more efficient though.

> (ns challenge
>  (:use clojure.test))
>
> (def lefts #{\( \[})
> (def matches {\( \) \[ \]})

Cool use of a set and a map!

> (defn balanced? [s]
>  (loop [s s stack ()]
>    (if (seq s)

Interesting use of seq.
(empty? s) seems more clear to me though.

>      (let [[c & s] s]
>        (if (lefts c)
>          (recur s (conj stack c))
>          (if (= (matches (peek stack)) c)
>            (recur s (pop stack))
>            false)))
>      (empty? stack
>
> (defn main []
>  (run-tests 'challenge))

Very nice! Thanks for sharing!

-- 
R. Mark Volkmann
Object Computing, Inc.

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

2009-07-02 Thread B Smith-Mannschott

On Thu, Jul 2, 2009 at 21:11, Daniel Lyons wrote:
> On Jul 2, 2009, at 1:00 PM, B Smith-Mannschott wrote:
>> What was confusing me is that slime/swank seem to be using
>> iso-latin-1-unix and so trip over greek letters. I've not yet found
>> the knobs to twiddle in emacs to get it to use UTF-8 here, but at
>> least the problem is not Clojure.
>
>
> (setq slime-net-coding-system 'utf-8-unix)
>
> :)

On Thu, Jul 2, 2009 at 21:12, Tayssir John
Gabbour wrote:
>
> Hi Ben,
>
> This is sitting in my .emacs file:
>
>  (set-language-environment "UTF-8")
>  (setq slime-net-coding-system 'utf-8-unix)

Thanks to both of you, that did the trick. I had already been setting
current-language-environment, what was missing was
slime-net-coding-system. Very nice.

On Thu, Jul 2, 2009 at 21:11, Daniel Lyons wrote:
> user> (def שלם 'peace)
> #'user/שלם
> user> שלם
> peace
>
> Interestingly, Emacs doesn't seem to change the writing direction, but
> when I pasted it into my mail client it did the right (-to-left)
> thing. This stuff is tricky.

Yea. Unicode gives me nightmares. ;-) The NFD/NFC issue drives me up
the wall. Stuff like this:
http://subversion.tigris.org/issues/show_bug.cgi?id=2464

// Ben

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



Re: ClojureQL - 0.9 approaching 1.0

2009-07-02 Thread Meikel Brandmeyer

Hi,

geez. A Schrödingbug I know I compiled it before, but
after a clean it broke. :( I'll see how to fix it.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: ClojureQL - 0.9 approaching 1.0

2009-07-02 Thread Meikel Brandmeyer

Hi,

ok. Fixed it. Was a stupid typo in the classname. Obviously it was no  
Schrödingbug, since I didn't compile the changes


Fix is up on github.

Sincerely
Meikel

smime.p7s
Description: S/MIME cryptographic signature


Re: ClojureQL - 0.9 approaching 1.0

2009-07-02 Thread Ozzi Lee

BUILD SUCCESSFUL
Total time: 6 seconds

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

2009-07-02 Thread Kai

Hey Laurent,

I had stack overflows because I had functions set up like this:

(defn parse-code [original-code formatted-code main-loop?] ... )
(defn format-list [original-code formatted-code] ... )
(defn format-string [original-code formatted-code] ... )

Now, whenever parse-code sees an opening parenthesis, it will call
format-list. Easy enough.

The tricky part is in the formatting functions. In format-list, we
read characters until we get to a closing parenthesis. The logical
step would be to return the formatted code back to parse-code, along
with some information about how much of the original code was read.
The problem with this approach is when you have structures nested
within format-list. Let's say format-list reads a quote ("). How is
format-list supposed to know that a quote begins a string? That's the
job of parse-code.

In that case, what I did was call parse-code again. This time, parse-
code checks to see if a character is beginning another data structure.
If it is, then it uses recursion *again* to process that data
structure. This continues all the way until it finishes parsing and
returns that back to the original format-list call, which now has to
account for the data read by parse-code.

If you followed that so far then you might see a problem. Instead of
ever returning to parse-code, the functions are recur-ing between each
other. Instead of the desired:

parse-code
format-list
format-string
...

The stack will look something like:

parse-code
format-list
parse-code
format-string
parse-code
format-list
...

This is the domain of mutual recursion that drove me to find a
different solution.

~ Kai

On Jul 2, 2:37 pm, Laurent PETIT  wrote:
>
> Ok, I'll wait then, thanks.
>
> BTW, I don't really understand how you could have StackOverflows. I
> would expect that the solving algorithm would make the size of the
> call stack proportional to the depth of the datastructure graph ? If
> so, I guess that even the most evil human created code would not reach
> the StackOverflow limit ?
>
> Regards,
>
> --
> Laurent
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: parsing program for nested parens and square brackets

2009-07-02 Thread Laurent PETIT

Hi,

OK, so here's my attempt at doing this the most higher order but also
the most understandable I could do.

Hope you enjoy reading it as much as I enjoyed polishing it :-) :

;; from command line:
;; java -cp clojure.jar /path/to/challenge.clj "()" "((([[]])))" ... ...
(ns challenge)

(def push conj)
(def closing-counterpart { \( \), \[ \] })
(def opening-char? closing-counterpart)
(defn matching-pair? [left right] (= right (closing-counterpart left)))

(defn consume-one [stack c]
  (if (or (opening-char? c)
  (not (matching-pair? (peek stack) c)))
(push stack c)
(pop stack)))

(defn balanced? [s]
  (empty? (reduce consume-one [] s)))

(defn main []
  (apply print (map balanced? *command-line-args*)))

(when *command-line-args*
  (main))

It's the second time I wish I had a version of reduce that allows to
quit the reduction early.
This version of reduce would allow to quit early, just like the
solution provided by Steven.
But maybe it just there's something wrong with me ! :-)

Say I have this function, which takes a keyword option at the end of
the form :quick-exit 
then I could write (reduce consume-one [] s :quick-exit nil) instead
of (reduce consume-one [] s),
and consume-one could be shortened to (notice the use of cond
automatically returning nil if nothing matches, instead of having
explicitly to return (push stack c) to continue consuming the string
(as in Mark's solution) :
(defn consume-one [stack c]
  (cond
(opening-char? c) (push stack c)
(matching-pair? (peek stack) c) (pop stack)))

2009/7/2 Mark Volkmann :
>
> On Thu, Jul 2, 2009 at 2:46 PM, Stephen C. Gilardi wrote:
>>
>> On Jul 2, 2009, at 3:21 PM, Mark Volkmann wrote:
>>
>>> Now it is using a vector instead of a list. Too
>>> bad there is no push function in core. I'm using conj.
>>
>> conj is the correct thing to use for the push operation.
>
> Right, but the point Laurent was making is that using peek and pop are
> good because they convey the fact that I'm using a vector as a stack.
> For that reason it would be nice if there was a push function to go
> along with peek and pop.
>
>> Here's my take on it based on yours. This bails early as soon as there is a
>> mismatch or an illegal character:
>
> Yeah, I realized mine wasn't doing that, but was happy that it gave
> the correct result anyway since the illegal characters get added to
> the stack and are never popped off. Your implementation is certainly
> more efficient though.
>
>> (ns challenge
>>  (:use clojure.test))
>>
>> (def lefts #{\( \[})
>> (def matches {\( \) \[ \]})
>
> Cool use of a set and a map!
>
>> (defn balanced? [s]
>>  (loop [s s stack ()]
>>    (if (seq s)
>
> Interesting use of seq.
> (empty? s) seems more clear to me though.
>
>>      (let [[c & s] s]
>>        (if (lefts c)
>>          (recur s (conj stack c))
>>          (if (= (matches (peek stack)) c)
>>            (recur s (pop stack))
>>            false)))
>>      (empty? stack
>>
>> (defn main []
>>  (run-tests 'challenge))
>
> Very nice! Thanks for sharing!
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
> >
>

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

2009-07-02 Thread Laurent PETIT

OK I understand now. I didn't have something like that in mind.

Regards,

-- 
Laurent

2009/7/2 Kai :
>
> Hey Laurent,
>
> I had stack overflows because I had functions set up like this:
>
> (defn parse-code [original-code formatted-code main-loop?] ... )
> (defn format-list [original-code formatted-code] ... )
> (defn format-string [original-code formatted-code] ... )
>
> Now, whenever parse-code sees an opening parenthesis, it will call
> format-list. Easy enough.
>
> The tricky part is in the formatting functions. In format-list, we
> read characters until we get to a closing parenthesis. The logical
> step would be to return the formatted code back to parse-code, along
> with some information about how much of the original code was read.
> The problem with this approach is when you have structures nested
> within format-list. Let's say format-list reads a quote ("). How is
> format-list supposed to know that a quote begins a string? That's the
> job of parse-code.
>
> In that case, what I did was call parse-code again. This time, parse-
> code checks to see if a character is beginning another data structure.
> If it is, then it uses recursion *again* to process that data
> structure. This continues all the way until it finishes parsing and
> returns that back to the original format-list call, which now has to
> account for the data read by parse-code.
>
> If you followed that so far then you might see a problem. Instead of
> ever returning to parse-code, the functions are recur-ing between each
> other. Instead of the desired:
>
> parse-code
> format-list
> format-string
> ...
>
> The stack will look something like:
>
> parse-code
> format-list
> parse-code
> format-string
> parse-code
> format-list
> ...
>
> This is the domain of mutual recursion that drove me to find a
> different solution.
>
> ~ Kai
>
> On Jul 2, 2:37 pm, Laurent PETIT  wrote:
>>
>> Ok, I'll wait then, thanks.
>>
>> BTW, I don't really understand how you could have StackOverflows. I
>> would expect that the solving algorithm would make the size of the
>> call stack proportional to the depth of the datastructure graph ? If
>> so, I guess that even the most evil human created code would not reach
>> the StackOverflow limit ?
>>
>> Regards,
>>
>> --
>> Laurent
>>
> >
>

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

2009-07-02 Thread Laurent PETIT

Hi,

It's amusing, because I just though a few days ago that "Troy" (in
reference to the city and the story of the trojan horse) was a
candidate name I had in mind for the new name of clojuredev ! :-)

2009/7/2 Sean Devlin :
>
> Hey all,
> I found this blog entry on how C++ replaced C, and it made me think of
> how Clojure interacts with Java.  Not a direct comparison, but I
> figure I'm not the only on who'll like it.
>
> http://ejohnson.blogs.com/software/2004/11/i_find_c_intere.html
>
> Hope someone enjoys 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: Displaying Clojure code on a Website

2009-07-02 Thread Kai

Hey Laurent,

I went ahead and finished the modifications I wanted to make. The
source code will now correctly highlight any function that begins with
def and underline any code that follows that was defined by that
function. It looks much better :)

I looked into Google Code but it seems like too much for me to manage.
I'm not interested in maintaining the project, although I certainly
don't mind if others would like to continue it. Since that's the case,
I'm leaving the project on my web server. If anybody wants to then
feel free to copy over the source code into a repo and have it shared
publicly.

I also looked into EPL, and quite honestly, I don't see any
instructions on how to release a work as EPL. Is there something I
should be pasting at the top of the file? At any rate, let me say -
feel free to use it for your Eclipse project. I don't mind at all. I
think permission from the creator must supersede the license anyway.

~ Kai

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

2009-07-02 Thread Laurent PETIT

Thanks Kai.

FYI, concerning your question about EPL, generally a slightly modified
version of this (the modification being putting your own name) is put
on top of clojure source code files :

; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

Regards,

-- 
Laurent

2009/7/2 Kai :
>
> Hey Laurent,
>
> I went ahead and finished the modifications I wanted to make. The
> source code will now correctly highlight any function that begins with
> def and underline any code that follows that was defined by that
> function. It looks much better :)
>
> I looked into Google Code but it seems like too much for me to manage.
> I'm not interested in maintaining the project, although I certainly
> don't mind if others would like to continue it. Since that's the case,
> I'm leaving the project on my web server. If anybody wants to then
> feel free to copy over the source code into a repo and have it shared
> publicly.
>
> I also looked into EPL, and quite honestly, I don't see any
> instructions on how to release a work as EPL. Is there something I
> should be pasting at the top of the file? At any rate, let me say -
> feel free to use it for your Eclipse project. I don't mind at all. I
> think permission from the creator must supersede the license anyway.
>
> ~ Kai
>
> >
>

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

2009-07-02 Thread Mark Tarver

Here is a solution in Qi+Qi YACC.

(define test-brackets
  X -> (not (= (compile  (COERCE X LIST)) fail!)))

(defcc 
  #\[  #\] ;
  #\(  #\) ;
   ;
   := [];)

(defcc 
  -*- := (if (element? -*- [#\[ #\] #\( #\)]) #\Escape -*-);)

Mark

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



Re: parsing program for nested parens and square brackets

2009-07-02 Thread Mark Tarver

This is a solution in Qi+Qi-YACC

(define test-brackets
  X -> (not (= (compile  (COERCE X LIST)) fail!)))

(defcc 
  #\[  #\] ;
  #\(  #\) ;
   ;
   := [];)

(defcc 
  -*- := (if (element? -*- [#\[ #\] #\( #\)]) #\Escape -*-);)

Testing

(5-) (test-brackets "()")
true

(6-)  (test-brackets "())")
false

(7-)  (test-brackets "([))]")
false

(8-)  (test-brackets "([])")
true

(9-)  (test-brackets "([)]")
false

(10-) (test-brackets "[][[([])]]")
true

Mark

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



Re: parsing program for nested parens and square brackets

2009-07-02 Thread Laurent PETIT

Hey, how come we did not see this even more concise version sooner ? :-):

;; using just clojure 1.0.0 without any additional library :-)
;; from command line:
;; java -cp clojure.jar /path/to/challenge2.clj "()" "((([[]])))" ... ...
(ns challenge2)

(defn balanced? [s]
  (and
(every? #{ \( \) \[ \] } s)
(try (read-string s) true (catch java.lang.RuntimeException e false

(defn main [] (apply print (map balanced? *command-line-args*)))

(when *command-line-args* (main))

Hehe

-- 
laurent

2009/7/2 Mark Volkmann :
>
> There is a challenge on the blog of Tony Morris at
> http://dibblego.wordpress.com/2008/09/05/haskell-scala-java-7-functional-java-java/#comment-2460.
> It's a parsing problem for which he compares solutions in Haskell,
> Scala and Java. I added a Clojure solution. I don't know if this is
> the "best" way to solve this with Clojure, but it certainly works.
> Here's my code, including unit tests.
>
> (use 'clojure.test)
>
> (defn- match [prev-char next-char]
>  (condp = prev-char
>    \( (= next-char \))
>    \[ (= next-char \])
>    false))
>
> ; Need a better name for this function.
> (defn- helper [s stack]
>  (if (empty? s)
>    (empty? stack)
>    (let [c (first s)
>          top (first stack)
>          stack (if (match top c) (next stack) (cons c stack))]
>      (helper (next s) stack
>
> (defn balanced? [s] (helper s '()))
>
> (doseq [arg *command-line-args*]
>  (println (balanced? arg)))
>
> (deftest match-test
>  (is (match \( \)))
>  (is (match \[ \]))
>  (is (not (match \( \{
>
> (deftest balanced-test
>  (is (balanced? "()"))
>  (is (balanced? "[]"))
>  (is (balanced? "([])"))
>  (is (balanced? "[()]"))
>  (is (balanced? "[]()"))
>  (is (balanced? "[][[([])]]"))
>  (is (not (balanced? "(")))
>  (is (not (balanced? ")")))
>  (is (not (balanced? "[")))
>  (is (not (balanced? "]")))
>  (is (not (balanced? "][")))
>  (is (not (balanced? ")(")))
>  (is (not (balanced? "( )")))
>  (is (not (balanced? "([)")))
>  (is (not (balanced? "[)]")))
>  (is (not (balanced? "([)]")))
>  (is (not (balanced? "({})")))
>  (is (not (balanced? "[())]"
>
> (run-tests)
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
> >
>

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

2009-07-02 Thread Parth

Tom, Chouser, Thanks for your responses.

As of now I am doing the same thing as suggested.
However, this tends be become painful the moment structures
start to nest. For e.g. I am using Clojure to decode a bit
of assembly and below is what I end up doing to see the
values of interest in hex:

user=> (decode :b32 (nth test-ops 3))
{:inst {:prefix (), :code (199 69 248 10 0 0 0), :op :movl, :args
[{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} 10]}, :more ()}
user=> (def r (decode :b32 (nth test-ops 3)))
#'user/r
user=> (map hex (get-in r [:inst :code]))
("c7" "45" "f8" "a" "0" "0" "0")
user=> (hex (second (get-in r [:inst :args])))
"a"
user=>

Basically, I need to extract each number seq or value
individually and print it in hex for every instruction I
decode and view.

This isn't too much fun to do in the middle of  a debug session :)

Having something like *print-base* would be ideal IMHO
would make scenarios like this really easy as one could
simply do:

user=> (set! *print-base* 16)
user=> (decode :b32 (nth test-ops 3))
{:inst {:prefix (), :code (c7 47 f8 a 0 0 0), :op :movl, :args
[{:type :Ev-mem, :arg {:reg :ebp, :disp f8}} a]}, :more ()}

In the absence of this I thought of writing a function
that would take an arbitrary Clojure structure/coll and print
it out in the manner like above. But then it won't
be much different from pprint with radix support but without
the pretty part.

I suppose what I am hoping is that a feature request for
*print-base* sort of a mechanism get considered
for Clojure as it makes scenarios like the above very
easy to deal with. Any chance of this being somewhere
on the Clojue todo? :)

I will probably create a poor mans radix based print
in the mean time for the this scenario. That should
be an interesting exercise.

Thanks,
Parth


On Jul 2, 10:58 pm, Chouser  wrote:
> On Thu, Jul 2, 2009 at 4:51 AM, Parth
>
> Malwankar wrote:
>
> > I frequently deal with hex and binary numbers.
> > As of now when I need to view a list of numbers
> > I just map a little hex function to it to translate it
> > into a list of hex strings at the repl.
>
> > Having something like *print-base* / *print-radix* [1] may be
> > valuable in such a scenario
>
> I don't think Java's built-in formatter is nearly as
> flexible as those, but getting hex or octal strings is easy
> enough:
>
> user=> (format "%d" 255)
> "255"
> user=> (format "%o" 255)
> "377"
> user=> (format "%x" 255)
> "ff"
> user=> (format "%X" 255)
> "FF"
>
> --Chouser
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: print-base / print-radix?

2009-07-02 Thread Parth



On Jul 2, 9:44 pm, Tom Faulhaber  wrote:
> Hi Parth,
>
> It is on the agenda to support this for pprint, but I don't know
> exactly when.
>

Thanks Tom.

I look forward to this addition to the wonderful pprint function :)

Regards,
Parth

> In the meantime, arbitrary bases *are* supported in the common lisp
> compatible format function (cl-format) which is also part of
> clojure.contrib.pprint.
>
> The interesting directives are ~X, ~B, and ~bR, where b is the base of
> interest. For example,
>
> (cl-format nil "~X" 256) => "100"
>
> (cl-format nil "~12r" 256) => "194"
>
> (cl-format true "~{~X ~}~%" [2 4 8 16 32 64 128 256])
>
> prints to *out*:
>
> 2 4 8 10 20 40 80 100
>
> For all the dirt on using radix, look at the Common Lisp 
> Hyperspec:http://www.lispworks.com/documentation/HyperSpec/Body/22_cb.htm
>
> More info about the clojure implementation of format 
> here:http://code.google.com/p/clojure-contrib/wiki/CommonLispFormat(a
> little out of date and about to be moved).
>
> HTH,
>
> Tom
> On Jul 2, 1:51 am, Parth Malwankar  wrote:
>
> > I frequently deal with hex and binary numbers.
> > As of now when I need to view a list of numbers
> > I just map a little hex function to it to translate it
> > into a list of hex strings at the repl.
>
> > Having something like *print-base* / *print-radix* [1] may be
> > valuable in such a scenario
>
> > Or maybe an enhanced pprint? Not sure if pprint already provides
> > such an option or if its planned.
>
> > I would appreciate any comments or ideas if someone
> > is doing something similar.
>
> > Thanks.
> > Parth
> > [1]http://www.lispworks.com/documentation/lw50/CLHS/Body/v_pr_bas.htm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: print-base / print-radix?

2009-07-02 Thread Parth



On Jul 3, 6:15 am, Parth  wrote:
> Tom, Chouser, Thanks for your responses.
>
> As of now I am doing the same thing as suggested.
> However, this tends be become painful the moment structures
> start to nest. For e.g. I am using Clojure to decode a bit
> of assembly and below is what I end up doing to see the
> values of interest in hex:
>
> user=> (decode :b32 (nth test-ops 3))
> {:inst {:prefix (), :code (199 69 248 10 0 0 0), :op :movl, :args
> [{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} 10]}, :more ()}
> user=> (def r (decode :b32 (nth test-ops 3)))
> #'user/r
> user=> (map hex (get-in r [:inst :code]))
> ("c7" "45" "f8" "a" "0" "0" "0")
> user=> (hex (second (get-in r [:inst :args])))
> "a"
> user=>
>
> Basically, I need to extract each number seq or value
> individually and print it in hex for every instruction I
> decode and view.
>
> This isn't too much fun to do in the middle of  a debug session :)
>
> Having something like *print-base* would be ideal IMHO
> would make scenarios like this really easy as one could
> simply do:
>
> user=> (set! *print-base* 16)
> user=> (decode :b32 (nth test-ops 3))
> {:inst {:prefix (), :code (c7 47 f8 a 0 0 0), :op :movl, :args
> [{:type :Ev-mem, :arg {:reg :ebp, :disp f8}} a]}, :more ()}
>
> In the absence of this I thought of writing a function
> that would take an arbitrary Clojure structure/coll and print
> it out in the manner like above. But then it won't
> be much different from pprint with radix support but without
> the pretty part.
>


> I suppose what I am hoping is that a feature request for
> *print-base* sort of a mechanism get considered
> for Clojure as it makes scenarios like the above very
> easy to deal with. Any chance of this being somewhere
> on the Clojue todo? :)
>

Rich,

If this is something you think would be a good addition
to Clojure I could give a shot at creating a patch for
this (with a CA of course). Please let me know.

I think rather than a generic radix support, if
we have hex, bin and octal supported, most uses
cases should be covered.

Regards,
Parth



> I will probably create a poor mans radix based print
> in the mean time for the this scenario. That should
> be an interesting exercise.
>
> Thanks,
> Parth
>
> On Jul 2, 10:58 pm, Chouser  wrote:
>
> > On Thu, Jul 2, 2009 at 4:51 AM, Parth
>
> > Malwankar wrote:
>
> > > I frequently deal with hex and binary numbers.
> > > As of now when I need to view a list of numbers
> > > I just map a little hex function to it to translate it
> > > into a list of hex strings at the repl.
>
> > > Having something like *print-base* / *print-radix* [1] may be
> > > valuable in such a scenario
>
> > I don't think Java's built-in formatter is nearly as
> > flexible as those, but getting hex or octal strings is easy
> > enough:
>
> > user=> (format "%d" 255)
> > "255"
> > user=> (format "%o" 255)
> > "377"
> > user=> (format "%x" 255)
> > "ff"
> > user=> (format "%X" 255)
> > "FF"
>
> > --Chouser
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Problem with clojure code on .net.

2009-07-02 Thread Baishampayan Ghose
mmwaikar wrote:
> Thanks Michael, and you are spot on about your observation on
> parentheses :) but when I wasn't putting (def name-wo-extn
> "something") in another (), I was getting some error like - too many
> arguments to def, hence I put one more. I am still getting used to
> this syntax.

Use a parenthesis aware editor and let the editor manage those for you.
You will be in deep trouble if you are counting and managing the
parenthesis manually :)

Otherwise, Clojure (like all Lisps) has very minimal syntax.

Regards,
BG

-- 
Baishampayan Ghose 
oCricket.com



signature.asc
Description: OpenPGP digital signature


Re: print-base / print-radix?

2009-07-02 Thread Tom Faulhaber

Parth,

I was thinking about this a little more today and I came up with a way
to extend the pretty printer easily to support *print-radix* with a
little wrapper. I'll try to get a chance to write it up for you
tomorrow.

Tom

On Jul 2, 6:29 pm, Parth  wrote:
> On Jul 3, 6:15 am, Parth  wrote:
>
>
>
> > Tom, Chouser, Thanks for your responses.
>
> > As of now I am doing the same thing as suggested.
> > However, this tends be become painful the moment structures
> > start to nest. For e.g. I am using Clojure to decode a bit
> > of assembly and below is what I end up doing to see the
> > values of interest in hex:
>
> > user=> (decode :b32 (nth test-ops 3))
> > {:inst {:prefix (), :code (199 69 248 10 0 0 0), :op :movl, :args
> > [{:type :Ev-mem, :arg {:reg :ebp, :disp -8}} 10]}, :more ()}
> > user=> (def r (decode :b32 (nth test-ops 3)))
> > #'user/r
> > user=> (map hex (get-in r [:inst :code]))
> > ("c7" "45" "f8" "a" "0" "0" "0")
> > user=> (hex (second (get-in r [:inst :args])))
> > "a"
> > user=>
>
> > Basically, I need to extract each number seq or value
> > individually and print it in hex for every instruction I
> > decode and view.
>
> > This isn't too much fun to do in the middle of  a debug session :)
>
> > Having something like *print-base* would be ideal IMHO
> > would make scenarios like this really easy as one could
> > simply do:
>
> > user=> (set! *print-base* 16)
> > user=> (decode :b32 (nth test-ops 3))
> > {:inst {:prefix (), :code (c7 47 f8 a 0 0 0), :op :movl, :args
> > [{:type :Ev-mem, :arg {:reg :ebp, :disp f8}} a]}, :more ()}
>
> > In the absence of this I thought of writing a function
> > that would take an arbitrary Clojure structure/coll and print
> > it out in the manner like above. But then it won't
> > be much different from pprint with radix support but without
> > the pretty part.
>
> > I suppose what I am hoping is that a feature request for
> > *print-base* sort of a mechanism get considered
> > for Clojure as it makes scenarios like the above very
> > easy to deal with. Any chance of this being somewhere
> > on the Clojue todo? :)
>
> Rich,
>
> If this is something you think would be a good addition
> to Clojure I could give a shot at creating a patch for
> this (with a CA of course). Please let me know.
>
> I think rather than a generic radix support, if
> we have hex, bin and octal supported, most uses
> cases should be covered.
>
> Regards,
> Parth
>
> > I will probably create a poor mans radix based print
> > in the mean time for the this scenario. That should
> > be an interesting exercise.
>
> > Thanks,
> > Parth
>
> > On Jul 2, 10:58 pm, Chouser  wrote:
>
> > > On Thu, Jul 2, 2009 at 4:51 AM, Parth
>
> > > Malwankar wrote:
>
> > > > I frequently deal with hex and binary numbers.
> > > > As of now when I need to view a list of numbers
> > > > I just map a little hex function to it to translate it
> > > > into a list of hex strings at the repl.
>
> > > > Having something like *print-base* / *print-radix* [1] may be
> > > > valuable in such a scenario
>
> > > I don't think Java's built-in formatter is nearly as
> > > flexible as those, but getting hex or octal strings is easy
> > > enough:
>
> > > user=> (format "%d" 255)
> > > "255"
> > > user=> (format "%o" 255)
> > > "377"
> > > user=> (format "%x" 255)
> > > "ff"
> > > user=> (format "%X" 255)
> > > "FF"
>
> > > --Chouser
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---