Re: automatic concurrency

2009-01-04 Thread Konrad Hinsen

On 03.01.2009, at 21:20, Mark Volkmann wrote:

> One of the stated benefits of functional programming I've seen is that
> the compiler of a functional language can analyze code and determine
> statements within a function
> that can safely be run concurrently. As
> far as I know Clojure doesn't yet do this. Correct?

Yes.

> Which functional programming languages, if any, do this?

None of the well-known ones. Perhaps none at all.

While it is true that *pure* functional programs (Clojure programs  
are not guaranteed to be purely functional) can be analyzed by a  
compiler to detect what can safely be executed in parallel, that is  
only half the story. The other important step is figuring out what to  
execute in parallel in order to gain speed, and that problem is still  
unsolved.

Still, functional programming is a big help in manual  
parallelization, as you don't have to worry about breaking your code.  
You just have to work for gaining speed.

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
To unsubscribe from 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: detecting running as script

2009-01-04 Thread Mark Volkmann

On Sun, Jan 4, 2009 at 3:57 AM, Timothy Pratley
 wrote:
>
>> I suspect that *command-line-arguments* would have "myapp.clj" as the
>> 0th element in the
>> clj myapp.clj
>> Can't test right now though sorry.
>
> I tested this and it does work for me. If it does not work for you is
> most likely in your clj script or bat file. I noticed on the wiki the
> incorrect advice was given:
>java  -cp %CLOJURE_JAR%;%CONTRIB_JAR% clojure.lang.Script %1
>
> I've updated the wiki with the correct usage:
>java  -cp %CLOJURE_JAR%;%CONTRIB_JAR% clojure.lang.Script %1 -- %*
>
> Check your script for the -- between script name and arglist. Note
> that %* includes %1.
>
> script-test.clj:
> (if *command-line-args*
>  (println "SCRIPT")
>  (println "REPL"))
>
> C:\java>clj script-test.clj
> SCRIPT
>
> C:\java>clj
> Clojure
> user=> (load-file "script-test.clj")
> REPL
> nil

Thanks! I've got it working this way now. My script defines a "main"
function. At the bottom of the script I do this:

; Only run the application automatically if run as a script,
; not if loaded in a REPL with load-file.
(if *command-line-args* (main))

-- 
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
To unsubscribe from 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: calling Clojure from Java

2009-01-04 Thread Stuart Sierra

On Jan 3, 8:13 pm, "Mark Volkmann"  wrote:
> I'd like to learn how to invoke Clojure code from a Java application.
> I see at least two options.
>
> 1) From a Java application, read a text file containing Clojure code
> and invoke specific functions it defines from Java code.

Here's how I do it:

import clojure.lang.RT;
import clojure.lang.Var;
...
RT.loadResourceScript("source/file/on/classpath/here.clj");
Var myfunction = RT.var("my-namespace", "my-function");
myfunction.invoke("arg 1", "arg 2", ...);


> 2) Compile Clojure code to bytecode and use it from a Java application
> just like any other Java code.

A little trickier; but easy if your Clojure code is implementing an
existing Java interface.

(ns my.cool.library
  (:gen-class :implements [SomeJavaInterface]))

(defn -functionDefinedInInterface [this arg1 arg2 ...]
  ...)

Note: defn names for functions defined in the interface begin with
"-".  Remember every method takes an extra "this" argument.

To generate the .class file, use "(compile my.cool.library)" or
clojure.lang.Compile.

-Stuart Sierra
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: detecting running as script

2009-01-04 Thread Meikel Brandmeyer

Hi,

Am 04.01.2009 um 11:15 schrieb Timothy Pratley:


I can't seem to get this approach working:

http://clojure.org/compilation seems to imply that this approach can
only be taken using :gen-class and pre-compiling before calling in
this way (which makes sense as my.app is not a class yet).


Yes. I found this out after sending the mail. But still clojure.main
does this somehow

Sincerely
Meikel




smime.p7s
Description: S/MIME cryptographic signature


Re: detecting running as script

2009-01-04 Thread Timothy Pratley

> I suspect that *command-line-arguments* would have "myapp.clj" as the
> 0th element in the
> clj myapp.clj
> Can't test right now though sorry.

I tested this and it does work for me. If it does not work for you is
most likely in your clj script or bat file. I noticed on the wiki the
incorrect advice was given:
java  -cp %CLOJURE_JAR%;%CONTRIB_JAR% clojure.lang.Script %1

I've updated the wiki with the correct usage:
java  -cp %CLOJURE_JAR%;%CONTRIB_JAR% clojure.lang.Script %1 -- %*

Check your script for the -- between script name and arglist. Note
that %* includes %1.

script-test.clj:
(if *command-line-args*
  (println "SCRIPT")
  (println "REPL"))


C:\java>clj script-test.clj
SCRIPT

C:\java>clj
Clojure
user=> (load-file "script-test.clj")
REPL
nil


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: recur with many parameters

2009-01-04 Thread Emeka
Christian

I have not been able to get my head around destructuring binding. Please
explain it to me with examples


Venlig hilsen

Emeka


On Sat, Jan 3, 2009 at 11:04 PM, Christian Vest Hansen  wrote:

>
> Instead of throwing a1..aN around every time, you could use the result
> vector and use destructuring binding in your let clause to get a1..aN
> into that scope.
>
> Something like
>
> (let [[a1 a2 aN :as result] (your-func ...)]
>  ...)
>
> On Sat, Jan 3, 2009 at 11:57 PM, TPJ  wrote:
> >
> > Is there some better way to "call" recur than that:
> >
> > (loop [ arg1 value1
> >arg2 value2
> >...
> >argn valuen ]
> >  (...) ; some stuff here
> >  (let [ (...) ; some bindings here
> > result (my-func ...)
> > a1 (nth result 0)
> > a2 (nth result 1)
> > ...
> > an (nth result (- n 1)) ]
> >(recur a1 a2 ... an)))
> >
> > I'd like to get rid of this a1, a2, ..., an and "call" recur in some
> > more convenient way. I've tried (apply recur result), but without any
> > success (Unable to resolve symbol: recur in this context).
> > >
> >
>
>
>
> --
>  / Kind regards,
> Christian Vest Hansen.
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Math functions

2009-01-04 Thread vogelrn

sqrt(a/b) should always be equal to sqrt(a)/sqrt(b) since (a/b)^m =
a^m/b^m for b != 0.  However, I'm unsure of whether it's the best
option for ratios because unless both the numerator and the
denominator are perfect squares, you're going to end up with a float
anyway.  This is trading an extra sqrt for precision in the relatively
uncommon situation where both numbers are perfect squares.

As for taking square roots involving complex numbers, I've been
considering that as well, but I think it might be a bad idea to have
it as a part of the normal sqrt function.  In the majority of
situations, taking the square root of a negative number is a bad thing
and probably shouldn't be allowed.  An alternative sqrt associated
with complex numbers could be appropriate instead.

On Jan 3, 10:06 pm, "Mark H."  wrote:
> On Jan 3, 11:48 am, "Mark Engelberg"  wrote:
>
> > If you give it an exact number (i.e., not a floating point),
>
> Floating-point numbers are exact -- it's their operations that may not
> be.  *ducks*
>
> Seriously, handy code -- many thanks!  I should check with someone
> whether sqrt(a/b) -> sqrt(a)/sqrt(b) is a fair assumption.  Would you
> find a sqrt that returns complex numbers for negative inputs (it would
> be the appropriate branch of the sqrt function in order to make it
> single-valued) useful?
>
> mfh

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: meaning and pronunciation of Clojure

2009-01-04 Thread Ed

I have been wanting to know the same thing...I was guessing Clojure
was an acronym for: Common_Lisp_Object_Java_?something?_?something?_?
something?, or possibly Concurrency_Language_OnThe_JVM_?something?_?
something?_?something?...I am dying to know.  Or, like others have
cited, Closure en Francais 'Clojure'what does the name stand for
and mean?

Can somebody post the history of the language, what the name means,
how it was chosen, were there any working names for the language
before it was called Clojureetc.  Is the inventor a Seattle
Seahawks fan, the colors of the Clojure Icon suggest so.

Thanks...happy hackin'

-
ed

On Jan 3, 1:06 pm, "Mark Volkmann"  wrote:
> I assume that the name "Clojure" is taken from the word "closure",
> replacing the "s" with a "j" for Java. I've never seen that in writing
> though and my curiosity compels me to have this verified. Is that
> right?
>
> Also, is it pronounced it is spelled or is it pronounced the same as
> "closure"? I did find a post that said it's pronounced like "closure",
> but I've always pronounced it the way it is spelled.
>
> --
> 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
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Could not find the main class clojure.lang.Repel. Program will exit.

2009-01-04 Thread chris

I was wondering if anyone else had a problem with this. I am trying to
run clojure on Vista. I think that the problem might be with my
environmental variables but I am not sure which ones to changes or
where to point them too.

Thank you for your help.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Release of VimClojure 1.3.0

2009-01-04 Thread Timothy Pratley

Hi Meikel,

Firstly thanks for making VimClojure, it is really great! I especially
like the rainbow parenthesis, that's extremely useful.


Also just reporting a small syntax highlighting consideration
user=> (def f #(println @%1))
#'user/f
user=> (f (atom 5))
5
@%1 tricks it and %1 is not shown as blue (not that it really
matters!)


Installation instructions .vimrc settings available in text format, so
I don't have to watch the screencast to get them
ie:
set nocompatible
filetype plugin indent on
syntax on
let clj_highlight_builtins = 1
let clj_paren_rainbow =1



Regards,
Tim.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: clj-backtrace: more readable backtraces for Clojure

2009-01-04 Thread Konrad Hinsen

On 03.01.2009, at 18:58, Mark McGranaghan wrote:

> It prints the cleaned backtrace.  Could you provide REPL sessions like
> these that indicate the unexpected behavior?

Sorry for the false alarm: I had used different shell scripts for  
launching Clojure with and without your library, and I just  
discovered that they also use different Clojure versions, one of them  
being pretty old. That's the real cause for the differences I saw!

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
To unsubscribe from 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: Compiling Clojure code with Maven

2009-01-04 Thread ivant

On Dec 31 2008, 4:49 pm, "Mike DeLaurentis" 
wrote:
> I'm working on a project that has both Java and Clojure sources. We
> use Maven as our build system, and I'd like to use it to compile the
> Clojure sources. Has anyone done that before? I can think of a few
> ways to do it, such as using maven to run an ant task or writing a
> plugin, but I'm not sure what's best. Any advice?
>
> Thanks,
>
> Mike

There are 2 or 3 threads in this group regarding maven.

Generally, the official build system for Clojure is ant.  It would be
good if somebody can rewrite the pom.xml file to use ant for the
actual build.  I even started doing something about it, but gave up,
because I don't know maven well enough and I didn't have the time (and
incentive) to invest in such project.

Regards,
Ivan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Using java.ext.dirs to manage the Classpath for Clojure REPLs

2009-01-04 Thread Stephen C. Gilardi
The "java.ext.dirs" System property provides a very convenient way to  
set up and maintain a Classpath for Clojure REPLs. The property can be  
set from the command line used to launch Clojure (typically within a  
launcher script). Its value is a list of directories whose *contents*  
will be the Classpath roots for Clojure.


In my case, I set the value of java.ext.dirs to a list of just one  
directory. That directory contains (relative) symbolic links to all  
the Jar files and directories I want Clojure to use as its Classpath.


As a concrete example, here's what I have in that directory:

clojure-contrib.classes   -> ../../clojure-contrib/classes
clojure-contrib.src   -> ../../clojure-contrib/src
clojure.jar   -> ../../clojure/clojure.jar
derby.jar -> ../javadb/lib/derby.jar
etc   -> ../../../clj/etc
itext-2.0.6.jar   -> ../jfreechart/lib/itext-2.0.6.jar
jcommon-1.0.12.jar-> ../jfreechart/lib/jcommon-1.0.12.jar
jfreechart-1.0.9.jar  -> ../jfreechart/lib/jfreechart-1.0.9.jar
jsr166y.jar   -> ../jsr166y/jsr166y.jar
local -> ../../../clj/local
miglayout-3.6-sources.jar -> ../miglayout/miglayout-3.6-sources.jar
miglayout-3.6-swing.jar   -> ../miglayout/miglayout-3.6-swing.jar

I've enclosed the bash script I'm currently using the launch Clojure.  
The one required environment variable is CLOJURE_DIRS which I set to  
the directory containing the links above. I like how simple the script  
is and how easy it is to manage which jars and directories are  
available to Clojure REPLs using this method.


--Steve

(note: using this with clojure.contrib.repl-ln requires revision 337  
(of today) or later)


#!/bin/bash

# clj: Launches a Clojure REPL with command line arguments
#
# Environment variables:
#
# Required:
#
#  CLOJURE_DIRS A list of paths to directories containing (either  
directly
#   or via symbolic links) the jar files and directories  
that
#   Clojure will use as its Classpath. The paths are  
separated

#   by File.pathSeparatorChar (: on UNIX).
#
# Optional:
#
#  CLOJURE_MAIN The Java class to launch
#   default: clojure.main
#   example: clojure.contrib.repl_ln
#
#  CLOJURE_OPTS Java options for this REPL's JVM instance
#   default:
#   example:"-Xms32M -Xmx128M -server"
#
#  CLOJURE_INIT Path to an init file to run, an @ prefix specifies a
#   classpath-relative path.
#   default:
#   example:"@init.clj"

set -o errexit
set -o nounset
#set -o xtrace

JAVA=java
OPTS=${CLOJURE_OPTS:-}
DIRS="-Djava.ext.dirs=${CLOJURE_DIRS}"
MAIN=${CLOJURE_MAIN:-clojure.main}
INIT=${CLOJURE_INIT:+--init ${CLOJURE_INIT}}
REPL=--repl

exec $JAVA $OPTS $DIRS $MAIN $INIT $REPL $@



smime.p7s
Description: S/MIME cryptographic signature


mset

2009-01-04 Thread Timothy Pratley

A while ago I wrote a short MUD which had to keep track of a changing
group of players, and other data. Retrospectively I've developed a
helper which can update in place any mutable map, handles nested
access, and behaves like assoc on immutables.

It allows usage like so:
; set up a mutable map of mutable players - tongue twister
(def players (ref nil))
(mset players "tim" (ref {:str 5 :con 5}))
(mset players "tom" (ref {:str 7 :con 2}))

; change some attributes
(mset players "tim" :str 6)
(mset players "tim" :con 4)
(mset players "tim" :friend (@players "tom"))

; results in pretty much what you might expect
(println "tim:" @(@players "tim"))
(println "tom:" @(@players "tom"))
(println "tim's friend" @((@players "tim") :friend))
tim: {:str 6, :con 4}
tom: {:str 7, :con 2}
tim's friend {:str 7, :con 2}

http://groups.google.com/group/clojure/web/helper.clj

Working on the deletion side I ran into a bit of a block when trying
to nil refs that were being removed:

; dissoc versions
(defmulti mdel (fn [m & args] (class m)))
(defmethod mdel clojure.lang.Ref [v]
  (dosync (ref-set v nil)))
(defmethod mdel clojure.lang.Ref [m k & more]
  (if more
(apply mdel (@m k) more)
(dosync (mdel (@m k))
  (ref-set m (dissoc @m k
  m)

(mdel (ref 5))
-> arity exception

I'm not sure why... I suspect it is something obvious I'm overlooking.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Could not find the main class clojure.lang.Repel. Program will exit.

2009-01-04 Thread Emeka
Chris,
I run my Clojure on Vista and I have not experienced what you mentioned. I
would like to know what you have done. Your installation details. And did
you download your Clojure.jar or did you use ant to build yours?


Emeka

On Sun, Jan 4, 2009 at 12:57 AM, chris  wrote:

>
> I was wondering if anyone else had a problem with this. I am trying to
> run clojure on Vista. I think that the problem might be with my
> environmental variables but I am not sure which ones to changes or
> where to point them too.
>
> Thank you for your help.
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Could not find the main class clojure.lang.Repel. Program will exit.

2009-01-04 Thread Stephen C. Gilardi


On Jan 3, 2009, at 7:57 PM, chris wrote:


I was wondering if anyone else had a problem with this. I am trying to
run clojure on Vista. I think that the problem might be with my
environmental variables but I am not sure which ones to changes or
where to point them too.

Thank you for your help.


This command line does launch the repl on Windows XP:

java -cp clojure.jar clojure.lang.Repl

when issued from within a directory that contains clojure.jar

Your subject line mentions clojure.lang.Repel. If that's what you're  
actually typing, removing the extra "e" should get it going.


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Some code review for clj-record?

2009-01-04 Thread John D. Hume

Brian,
I incorporated your changes and then made changes to load and run all
clj_record/test/*-test.clj files. Thanks again.
-hume.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: detecting running as script

2009-01-04 Thread Timothy Pratley

Hi Meikel,

On Jan 3, 9:03 pm, Meikel Brandmeyer  wrote:
> java -cp  my.app

I can't seem to get this approach working:
I created a directory "my"
and a file "app.clj" containing:
(ns my.app)
(defn somefunc [])
  (println "somefunc!" args))
(defn main [& args]
  (somefunc))

C:\java>java -cp .;"c:/java/clojure/clojure.jar" my.app
Exception in thread "main" java.lang.NoClassDefFoundError: my/app
Caused by: java.lang.ClassNotFoundException: my.app

http://clojure.org/compilation seems to imply that this approach can
only be taken using :gen-class and pre-compiling before calling in
this way (which makes sense as my.app is not a class yet).



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.contrib.sql (connection) public?

2009-01-04 Thread Stephen C. Gilardi


On Dec 15, 2008, at 6:48 AM, black...@ipowerhouse.com wrote:


This may be a problem with the way I'm doing things but I think it
would be useful for the (connection) function of internal to not be
internal. For example, lets say i do a query on a db to see if a user
exists, if they don't I want to insert,  so I need a new statement for
that within the same transaction, i.e. i need to get hold of the
connection itself to create my new statement. Right now, I'm doing
(internal/connection) but I think it should be part of the public
interface as it's something that happens frequently.


connection is now (r340) part of the public API for  
clojure.contrib.sql. Thanks for the feedback!


--Steve



smime.p7s
Description: S/MIME cryptographic signature


broken link http://clojure.org/api#condp

2009-01-04 Thread Eric Lavigne

At http://clojure.org/macros, condp is listed as one of the branching
macros, but its link is broken.

-- 
Education is what survives when what has been learned has been forgotten.

- B. F. Skinner

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: clj-backtrace: more readable backtraces for Clojure

2009-01-04 Thread Paul Barry
This is very nice, any chance we could see this added to clojure contrib?

On Thu, Jan 1, 2009 at 9:30 PM, Mark McGranaghan  wrote:

>
> Hi all,
>
> I'm happy to announce an alpha release of clj-backtrace, a library for
> processing backtraces generated by Clojure programs. The library works
> by separating useful backtrace information from the noise generated by
> the Clojure compilation process, and also provides functions for
> pretty-printing these cleaned backtraces.
>
> You can see simple usage instructions and example backtrace output on
> the library's README page:
>
> http://github.com/mmcgrana/clj-backtrace/tree/master/README.textile
>
> If you've ever felt that backtraces in Clojure were difficult to read,
> I hope you'll give this library a try and let me know if it helps!
>
> - 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
To unsubscribe from 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: broken link http://clojure.org/api#condp

2009-01-04 Thread Chouser

On Sun, Jan 4, 2009 at 2:18 PM, Eric Lavigne  wrote:
>
> At http://clojure.org/macros, condp is listed as one of the branching
> macros, but its link is broken.

The API page doesn't have condp yet.  When it does, the link will
work.  In the meantime you'll have to get by with (doc condp)

--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
To unsubscribe from 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: Adding user-defined state to classes created with (proxy ...)

2009-01-04 Thread Chouser

On Sun, Jan 4, 2009 at 1:28 AM, Tom Faulhaber  wrote:
>
> 1) This use case may be obscure enough that I should just buckle down
> and give (ns (:gen-class ...)) some love.

It may be, but let me again mention the option of gen-interface plus
proxy.  Sometimes you need to produce a physical .class files of
concrete types (for servlet containers, for use with android, etc.).
But if that's not the case, you may prefer the simplicity of
gen-interface.  Then you can implement your interface in as many ways
as needed using 'proxy'.

> 2) It occurred to me after writing my previous message, that it would
> be pretty trivial to write a (proxy+ ...) extension outside the core.
> If it found enough use, it could be pulled in (a la condp) as a non-
> breaking change sometime in the future,

Excellent point.  gen-interface itself started in contrib.

> In another direction, your response gave me kind of a sick idea. It
> would be pretty easy (I think) to create a "proxy-map" function:
>
> (proxy-map [amap akey] ...)
>
> proxy-map would create a new object that wrapped the map it was passed
> and implemented IPersistantMap. It would also examine the the object
> (presumably some Java object) at (akey amap) and proxy all the methods
> it implements to it.

Yeah, that is kind of sick. :-D

--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
To unsubscribe from 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: literate snake

2009-01-04 Thread Timothy Pratley

>From a cursory examination of "literate programming" central tenants
appear to be:
(1) order by human logic
(2) use descriptive macros
(3) program is a web

(1) Is not possible in Clojure because it resolves symbols as it reads
them. However that is easy to work around with a trivial patch (see
http://groups.google.com/group/clojure/web/auto-def.patch). auto-def
as the name suggests just defs a symbol that it can't find. So this
allows you to declare functions out of order - top down - and hope
they get redefed before any evaluation occurs. If evaluation does
occur the error still has a stack showing where and what the var is
(which will be nil - similar to a null pointer exception in java).
Here is an example that will only work with auto-def:
http://groups.google.com/group/clojure/web/lit-wc.clj

(2) lisp is great for this with hyphenation as standard. (3) yikes!
need to contemplate this.

What are the arguments against *auto-def*?


On Jan 3, 9:38 am, Randall R Schulz  wrote:
> - 
> - 
> - 
> - 
> - 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Slow nested subvecs (+ fix)

2009-01-04 Thread Jason Wolfe

Nope, I have not sent in a CA yet.  I'll do it sometime this week.

Now that I think about it some more, though, this change doesn't
really address the whole problem.

; Time to queue up and dequeue a bunch of elements
user> (doseq [n '(10 100 1000 1 10)]
(do (prn n)
(time (loop [n n s [-1]]
 (if (zero? n)
  s
   (recur (dec n) (subvec (conj s n) 1)))

10
"Elapsed time: 0.082 msecs"
100
"Elapsed time: 0.402 msecs"
1000
"Elapsed time: 27.426 msecs"
1
"Elapsed time: 4167.749 msecs"
10
; Stack Overflow

In particular, sequences of conjs and subvecs will remain quadratic,
and eventually lead to a stack overflow as seen here.  (Are there
other operations I should be using here?).

It would be really great if vectors could detect their nesting level
and periodically flatten themselves so that sequences of add and
subvec operations have amortized O(1) time (and use constant memory).
I'm not sure if that's even possible though; Clojure has been my first
real experience with immutable data structures.  Thoughts?

Cheers,
Jason


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Slow nested subvecs (+ fix)

2009-01-04 Thread Chouser

On Sun, Jan 4, 2009 at 2:55 PM, Jason Wolfe  wrote:
>
> Now that I think about it some more, though, this change doesn't
> really address the whole problem.
>
> ; Time to queue up and dequeue a bunch of elements
> user> (doseq [n '(10 100 1000 1 10)]
>(do (prn n)
>(time (loop [n n s [-1]]
> (if (zero? n)
>  s
>   (recur (dec n) (subvec (conj s n) 1)))

Have you considered using clojure.lang.PersistentQueue instead of
vector and subvec?

--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
To unsubscribe from 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: Could not find the main class clojure.lang.Repel. Program will exit.

2009-01-04 Thread chris

SWEET! That did it. I knew that I had to be doing something stupid.
That won't be the first time I am sure. Thank you for the help.

On Jan 4, 12:13 pm, "Stephen C. Gilardi"  wrote:
> On Jan 3, 2009, at 7:57 PM, chris wrote:
>
> > I was wondering if anyone else had a problem with this. I am trying to
> > run clojure on Vista. I think that the problem might be with my
> > environmental variables but I am not sure which ones to changes or
> > where to point them too.
>
> > Thank you for your help.
>
> This command line does launch the repl on Windows XP:
>
>         java -cp clojure.jar clojure.lang.Repl
>
> when issued from within a directory that contains clojure.jar
>
> Your subject line mentions clojure.lang.Repel. If that's what you're  
> actually typing, removing the extra "e" should get it going.
>
> --Steve
>
>  smime.p7s
> 3KViewDownload
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Slow nested subvecs (+ fix)

2009-01-04 Thread Jason Wolfe

>
> Have you considered using clojure.lang.PersistentQueue instead of
> vector and subvec?

Indeed, I am using that, thanks.  (I happened to stumble across an  
earlier newsgroup post on this subject).  Maybe all of the useful conj/ 
subvec usage patterns for vectors can be served by PersistentQueues, I  
don't know.  Still, it seems like if vectors could be made more  
efficient, it couldn't hurt.

Thanks,
Jason



>
>
> --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
To unsubscribe from 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: Some code review for clj-record?

2009-01-04 Thread Brian Doyle
Looks good.  I didn't know about the *file* var.

On Sun, Jan 4, 2009 at 11:22 AM, John D. Hume wrote:

>
> Brian,
> I incorporated your changes and then made changes to load and run all
> clj_record/test/*-test.clj files. Thanks again.
> -hume.
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Namespace Level Docstrings

2009-01-04 Thread Mark McGranaghan

Clojure revision 1193 introduces metadata handling for namespaces and
other Reference types. I was thinking this could be used to add
support for ns-level docstrings such as we currently have for vars.
Such support would allow programatic access to namespace
documentation.

I was thinking of something like:

(ns clojure.zip
  (:refer-clojure :exclude (replace remove))
  (:doc "Functional hierarchical zipper, with navigation, editing and
enumeration. See Huet."))

Which would eventually allow:

(doc clojure.zip)

as well as access to these docstrings by programatic documentation
generators like clj-doc.

Is anyone else interested in namespace-level docstrings? Any thoughts
on what the interface might look like?

- 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
To unsubscribe from 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: literate snake

2009-01-04 Thread Tom Ayerst
I tidied up a couple of things:
Changed function name 'verify-direction' to 'new-direction' (it is more than
a simple verification)
Passed 'direction' and 'snake-head' to 'new-direction' to avoid accessing
global state from inside the function
Used destructuring to simplify let statement in new-head (just to see what
it looked like)
Extracted dy,dx calculation in 'move-snake' into a 'delta' function

I notice everything seems to happen in the assignment vector in the 'let' in
move-snake?  Is that good style?  I'm not sure.

What would be interesting would be to have a second randomly moving snake to
avoid, that would force out some issues with global state etc.

The new code at the end:
*  ; Only run the application automatically if run as a script,
  ; not if loaded in a REPL with load-file.
  (println "*command-line-args* =" *command-line-args*)
  (if *command-line-args* (main))*
Doesn't do what it says for me, it printlns and stops from clj, any idea
what I am doing wrong?

Cheers

Tom



2009/1/3 Brian Will 

>
> My way was a little verbose, but you could do:
>
> (defn verify-direction
>  "Gets the current snake direction or
>   a new one if a board edge was reached."
>  []
>  (let [direction (@snake :direction)
>head (snake-head)
>x (head :x)
>y (head :y)
> at-left (= x 0)
>at-right (= x (- *board-width* 1))
>at-top (= y 0)
>at-bottom (= y (- *board-height* 1))
> left-half (< x (/ *board-width* 2))
> top-half (< y (/ *board-height* 2))]
>(cond
>  (and (= direction :right) at-right) (if top-half :down :up)
>  (and (= direction :down) at-bottom) (if left-half :right :left)
>  (and (= direction :left) at-left) (if top-half :down :up)
>  (and (= direction :up) at-top) (if left-half :right :left)
>  true direction)))
>
> On Jan 3, 9:28 am, "Mark Volkmann"  wrote:
> > On Sat, Jan 3, 2009 at 3:03 AM, Brian Will 
> wrote:
> >
> > > The problem with the snake running off the edge simply is a flaw in
> > > your logic here:
> >
> > > (defn verify-direction
> > >  "Gets the current snake direction or
> > >   a new one if a board edge was reached."
> > >  []
> > >  (let [direction (@snake :direction)
> > >head (snake-head)
> > >x (head :x)
> > >y (head :y)]
> > >(cond
> > >  (and (= direction :right) (= x (- *board-width* 1))) :down
> > >  (and (= direction :down) (= y (- *board-height* 1))) :left
> > >  (and (= direction :left) (= x 0)) :up
> > >  (and (= direction :up) (= y 0)) :right
> > >  true direction)))
> >
> > > Each case of the cond here is flawed. For example, when the snake is
> > > heading right and already on the bottom, he's going to turn down,
> > > which is off the board.
> >
> > > I suggest splitting each direction case into two cases such that the
> > > snake goes in the direction where there's more room to travel:
> >
> > >  (defn verify-direction
> > >  "Gets the current snake direction or
> > >   a new one if a board edge was reached."
> > >  []
> > >  (let [direction (@snake :direction)
> > >head (snake-head)
> > >x (head :x)
> > >y (head :y)
> > >left (= x 0)
> > >right (= x (- *board-width* 1))
> > >top (= y 0)
> > >bottom (= y (- *board-height* 1))
> > >left-half (< x (/ *board-width* 2))
> > >right-half (>= x (/ *board-width* 2))
> > >top-half (< y (/ *board-height* 2))
> > >bottom-half (>= y (/ *board-height* 2))]
> > >(cond
> > >  (and (= direction :right) right top-half) :down
> > >  (and (= direction :right) right bottom-half) :up
> > >  (and (= direction :down) bottom left-half) :right
> > >  (and (= direction :down) bottom right-half) :left
> > >  (and (= direction :left) left top-half) :down
> > >  (and (= direction :left) left bottom-half) :up
> > >  (and (= direction :up) top left-half) :right
> > >  (and (= direction :up) top right-half) :left
> > >  true direction)))
> >
> > Thanks Brian! I ended up doing something similar that required a
> > little less code. Here's what I did.
> >
> >   (let [direction (@snake :direction)
> > head (snake-head)
> > x (head :x)
> > y (head :y)
> > at-left (= x 0)
> > at-right (= x (- *board-width* 1))
> > at-top (= y 0)
> > at-bottom (= y (- *board-height* 1))]
> > (cond
> >   (and (= direction :up) at-top) (if at-right :left :right)
> >   (and (= direction :right) at-right) (if at-bottom :up :down)
> >   (and (= direction :down) at-bottom) (if at-left :right :left)
> >   (and (= direction :left) at-left) (if at-top :down :up)
> >   true direction)))
> >
> > --
> > 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 clo

Re: literate snake

2009-01-04 Thread Mark Volkmann

On Sun, Jan 4, 2009 at 3:51 PM, Tom Ayerst  wrote:
> I tidied up a couple of things:
> Changed function name 'verify-direction' to 'new-direction' (it is more than
> a simple verification)

Sounds good. I made that change to mine.

> Passed 'direction' and 'snake-head' to 'new-direction' to avoid accessing
> global state from inside the function

I also made a change to avoid that, but I just passed the dereferenced
snake rather than the direction and head.

> Used destructuring to simplify let statement in new-head (just to see what
> it looked like)

I guess I could do that even though I'm passing the whole snake
struct, but going two levels deep in destructuring is probably
confusing for readers.

> Extracted dy,dx calculation in 'move-snake' into a 'delta' function

That's nice! I'll do that too.

> I notice everything seems to happen in the assignment vector in the 'let' in
> move-snake?  Is that good style?  I'm not sure.

I'm not either, but it seems pretty readable to me.

> What would be interesting would be to have a second randomly moving snake to
> avoid, that would force out some issues with global state etc.

Yeah, that would be interesting.

> The new code at the end:
>   ; Only run the application automatically if run as a script,
>   ; not if loaded in a REPL with load-file.
>   (println "*command-line-args* =" *command-line-args*)
>   (if *command-line-args* (main))
> Doesn't do what it says for me, it printlns and stops from clj, any idea
> what I am doing wrong?

I think it's related to details of your clj script. The relevant like
in mine is this:

java -cp $CP clojure.lang.Script $1 -- $*

I can send you my whole clj script if you'd like.

The latest version of my code that incorporates your changes is at
http://www.ociweb.com/mark/programming/ClojureSnake.html.

Thanks Tom!

-- 
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
To unsubscribe from 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: Questions & workaround regarding Clojure, true laziness, and nil-terminated sequences

2009-01-04 Thread Jason Wolfe

Thanks a lot for your very detailed response Chouser!  report-seq is a
very useful way to look at this stuff.

> ...
> Unless I've completely misunderstood your scenario, I think this
> demonstrates that the seq abstraction as it currently exists is
> sufficient for providing the kind of laziness you need.

That does satisfy my requirements as a lazy stack data structure.
However, it does so by adding an inner level of cons objects; this is
more or less equivalent to just calling (delay) on each level of the
seq and then having to explicitly (force) each time an element is
extracted.  With either workaround, the built-in seq functions are no
longer directly applicable.  I can't call filter directly on an mstk,
for example.

This isn't a big deal, I was mostly just curious why the seq
abstraction was set up this way.

Thanks, Jason
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



finding all vars starting with *

2009-01-04 Thread Brian Doyle
Today I found out about the var *file*.  I looked it up *file* on
clojure.com/api and couldn't find anything.
Is there some place where all of these vars are defined?   Is there some way
programatically I can find
them all?  Thanks.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Using java.ext.dirs to manage the Classpath for Clojure REPLs

2009-01-04 Thread lpetit

Note that since JDK 1.6, it is possible to use the * wildcard in
classpath items to embed all the jars in a directory at once.

So with proper use of links in a "root" directory containing a bunch
of jars, it's possible to shorten the classpath to DIR/*:classes:src

BTW, java.ext.dirs' semantics is to provide directories to the JVM for
JDK extensions implementing JDK's APIs. (http://java.sun.com/javase/6/
docs/technotes/guides/extensions/spec.html)

It does not seem appropriate to me to abuse java.ext.dirs to put in it
each an every jar or class directory one may want to use in its
application ?

HTH,

--
Laurent


On Jan 4, 6:59 pm, "Stephen C. Gilardi"  wrote:
> The "java.ext.dirs" System property provides a very convenient way to  
> set up and maintain a Classpath for Clojure REPLs. The property can be  
> set from the command line used to launch Clojure (typically within a  
> launcher script). Its value is a list of directories whose *contents*  
> will be the Classpath roots for Clojure.
>
> In my case, I set the value of java.ext.dirs to a list of just one  
> directory. That directory contains (relative) symbolic links to all  
> the Jar files and directories I want Clojure to use as its Classpath.
>
> As a concrete example, here's what I have in that directory:
>
> clojure-contrib.classes   -> ../../clojure-contrib/classes
> clojure-contrib.src       -> ../../clojure-contrib/src
> clojure.jar               -> ../../clojure/clojure.jar
> derby.jar                 -> ../javadb/lib/derby.jar
> etc                       -> ../../../clj/etc
> itext-2.0.6.jar           -> ../jfreechart/lib/itext-2.0.6.jar
> jcommon-1.0.12.jar        -> ../jfreechart/lib/jcommon-1.0.12.jar
> jfreechart-1.0.9.jar      -> ../jfreechart/lib/jfreechart-1.0.9.jar
> jsr166y.jar               -> ../jsr166y/jsr166y.jar
> local                     -> ../../../clj/local
> miglayout-3.6-sources.jar -> ../miglayout/miglayout-3.6-sources.jar
> miglayout-3.6-swing.jar   -> ../miglayout/miglayout-3.6-swing.jar
>
> I've enclosed the bash script I'm currently using the launch Clojure.  
> The one required environment variable is CLOJURE_DIRS which I set to  
> the directory containing the links above. I like how simple the script  
> is and how easy it is to manage which jars and directories are  
> available to Clojure REPLs using this method.
>
> --Steve
>
> (note: using this with clojure.contrib.repl-ln requires revision 337  
> (of today) or later)
>
> #!/bin/bash
>
> # clj: Launches a Clojure REPL with command line arguments
> #
> # Environment variables:
> #
> # Required:
> #
> #  CLOJURE_DIRS A list of paths to directories containing (either  
> directly
> #               or via symbolic links) the jar files and directories  
> that
> #               Clojure will use as its Classpath. The paths are  
> separated
> #               by File.pathSeparatorChar (: on UNIX).
> #
> # Optional:
> #
> #  CLOJURE_MAIN The Java class to launch
> #               default: clojure.main
> #               example: clojure.contrib.repl_ln
> #
> #  CLOJURE_OPTS Java options for this REPL's JVM instance
> #               default:
> #               example:"-Xms32M -Xmx128M -server"
> #
> #  CLOJURE_INIT Path to an init file to run, an @ prefix specifies a
> #               classpath-relative path.
> #               default:
> #               example:"@init.clj"
>
> set -o errexit
> set -o nounset
> #set -o xtrace
>
> JAVA=java
> OPTS=${CLOJURE_OPTS:-}
> DIRS="-Djava.ext.dirs=${CLOJURE_DIRS}"
> MAIN=${CLOJURE_MAIN:-clojure.main}
> INIT=${CLOJURE_INIT:+--init ${CLOJURE_INIT}}
> REPL=--repl
>
> exec $JAVA $OPTS $DIRS $MAIN $INIT $REPL $@
>
>  smime.p7s
> 3KViewDownload
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Namespace Level Docstrings

2009-01-04 Thread Meikel Brandmeyer

Hi,

Am 04.01.2009 um 22:01 schrieb Mark McGranaghan:


(ns clojure.zip
 (:refer-clojure :exclude (replace remove))
 (:doc "Functional hierarchical zipper, with navigation, editing and
   enumeration. See Huet."))

Is anyone else interested in namespace-level docstrings? Any thoughts
on what the interface might look like?


I think, thats a good idea. The interface might look
like your example above, following the :use and
:require methods.

Or it might go into direction of defn and defvar:

(ns clojure.zip
  "Functional hierarchical zipper, with navigation, editing
  and enumeration. See Huet."
  (:refer-clojure :exclude (replace remove)))

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: recur with many parameters

2009-01-04 Thread Meikel Brandmeyer

Hi,

Am 04.01.2009 um 18:23 schrieb Emeka:

I have not been able to get my head around destructuring binding.  
Please explain it to me with examples


http://clojure.org/special_forms#toc4 with examples...

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: finding all vars starting with *

2009-01-04 Thread Meikel Brandmeyer

Hi,

Am 05.01.2009 um 00:05 schrieb Brian Doyle:

Today I found out about the var *file*.  I looked it up *file* on  
clojure.com/api and couldn't find anything.
Is there some place where all of these vars are defined?   Is there  
some way programatically I can find

them all?  Thanks.


Be careful about non-documented "features". They may
be public for some reason, but may come, go or change
meaning without notification. You should not rely on them
in your code.

You can have a look at the ns-* functions. ns-publics
should probably return all public Vars, in particularly
those starting with *.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: Using java.ext.dirs to manage the Classpath for Clojure REPLs

2009-01-04 Thread rzeze...@gmail.com

I think this should be fine for 99% of situations, but I think it's
also fair to say this is an unorthodox use of java.ext.dirs.  I've
never really had a firm grip on the idiomatic use of Java's extension
mechanism, but I do know that they claim it is for well-established
extension/optional packages.  One example might be the bouncycastle
crypto provider.  The one thing I think you do have to be careful
about is that if you put something in the extensions path, it will be
loaded by the extensions classloader, and you will force everything
running on that JVM process to use that particular version (you can
get around this, but it's not always obvious).  For most applications
this shouldn't matter, but for an application that hosts other
applications (eg. an application server) this can be problematic.  I
know from experience after 3 years of dealing with IBM WebSphere.  You
will probably never run into any problems, but I couldn't help but
comment.

Another solution you might want to look at is Apache's Common
Launcher.  It's not the most elegant solution in the world, but it
makes it easy to add an entire directory of JARs to the classpath, and
it makes it easy to have a cross-platform execution script.


On Jan 4, 12:59 pm, "Stephen C. Gilardi"  wrote:
> The "java.ext.dirs" System property provides a very convenient way to  
> set up and maintain a Classpath for Clojure REPLs. The property can be  
> set from the command line used to launch Clojure (typically within a  
> launcher script). Its value is a list of directories whose *contents*  
> will be the Classpath roots for Clojure.
>
> In my case, I set the value of java.ext.dirs to a list of just one  
> directory. That directory contains (relative) symbolic links to all  
> the Jar files and directories I want Clojure to use as its Classpath.
>
> As a concrete example, here's what I have in that directory:
>
> clojure-contrib.classes   -> ../../clojure-contrib/classes
> clojure-contrib.src       -> ../../clojure-contrib/src
> clojure.jar               -> ../../clojure/clojure.jar
> derby.jar                 -> ../javadb/lib/derby.jar
> etc                       -> ../../../clj/etc
> itext-2.0.6.jar           -> ../jfreechart/lib/itext-2.0.6.jar
> jcommon-1.0.12.jar        -> ../jfreechart/lib/jcommon-1.0.12.jar
> jfreechart-1.0.9.jar      -> ../jfreechart/lib/jfreechart-1.0.9.jar
> jsr166y.jar               -> ../jsr166y/jsr166y.jar
> local                     -> ../../../clj/local
> miglayout-3.6-sources.jar -> ../miglayout/miglayout-3.6-sources.jar
> miglayout-3.6-swing.jar   -> ../miglayout/miglayout-3.6-swing.jar
>
> I've enclosed the bash script I'm currently using the launch Clojure.  
> The one required environment variable is CLOJURE_DIRS which I set to  
> the directory containing the links above. I like how simple the script  
> is and how easy it is to manage which jars and directories are  
> available to Clojure REPLs using this method.
>
> --Steve
>
> (note: using this with clojure.contrib.repl-ln requires revision 337  
> (of today) or later)
>
> #!/bin/bash
>
> # clj: Launches a Clojure REPL with command line arguments
> #
> # Environment variables:
> #
> # Required:
> #
> #  CLOJURE_DIRS A list of paths to directories containing (either  
> directly
> #               or via symbolic links) the jar files and directories  
> that
> #               Clojure will use as its Classpath. The paths are  
> separated
> #               by File.pathSeparatorChar (: on UNIX).
> #
> # Optional:
> #
> #  CLOJURE_MAIN The Java class to launch
> #               default: clojure.main
> #               example: clojure.contrib.repl_ln
> #
> #  CLOJURE_OPTS Java options for this REPL's JVM instance
> #               default:
> #               example:"-Xms32M -Xmx128M -server"
> #
> #  CLOJURE_INIT Path to an init file to run, an @ prefix specifies a
> #               classpath-relative path.
> #               default:
> #               example:"@init.clj"
>
> set -o errexit
> set -o nounset
> #set -o xtrace
>
> JAVA=java
> OPTS=${CLOJURE_OPTS:-}
> DIRS="-Djava.ext.dirs=${CLOJURE_DIRS}"
> MAIN=${CLOJURE_MAIN:-clojure.main}
> INIT=${CLOJURE_INIT:+--init ${CLOJURE_INIT}}
> REPL=--repl
>
> exec $JAVA $OPTS $DIRS $MAIN $INIT $REPL $@
>
>  smime.p7s
> 3KViewDownload
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Using java.ext.dirs to manage the Classpath for Clojure REPLs

2009-01-04 Thread rzeze...@gmail.com



On Jan 4, 6:06 pm, lpetit  wrote:
> Note that since JDK 1.6, it is possible to use the * wildcard in
> classpath items to embed all the jars in a directory at once.
>
> So with proper use of links in a "root" directory containing a bunch
> of jars, it's possible to shorten the classpath to DIR/*:classes:src
>

This is nice to know!  Ever since I started using Java (1.4), I
wondered why they didn't have this feature.  I have yet to read what's
new in Java 6; I'm so far behind!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Questions & workaround regarding Clojure, true laziness, and nil-terminated sequences

2009-01-04 Thread Chouser

On Sun, Jan 4, 2009 at 5:51 PM, Jason Wolfe  wrote:
>
> That does satisfy my requirements as a lazy stack data structure.
> However, it does so by adding an inner level of cons objects; this is
> more or less equivalent to just calling (delay) on each level of the
> seq and then having to explicitly (force) each time an element is
> extracted.

Except that I introduce no new object at all.  I don't create any seq
or delay object.  Every object I used was given to me from the user of
'push-seq' function, so I'm not quite sure what you mean.

> With either workaround, the built-in seq functions are no
> longer directly applicable.  I can't call filter directly on an mstk,
> for example.

This would be true of any compound data structure built out of clojure
collections.  'filter', 'map' etc. don't automatically traverse trees,
graphs, or other nested structures.  But a function that returns a
lazy seq over an mstk is pretty easy:

(defn mstk-seq [mstk]
  (lazy-cons (single-peek mstk) (single-pop mstk)))

I think you'll find this has the same laziness profile as the raw
calls to single-peek and single-pop I presented earlier.

--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
To unsubscribe from 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: Namespace Level Docstrings

2009-01-04 Thread Rich Hickey



On Jan 4, 6:27 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> Am 04.01.2009 um 22:01 schrieb Mark McGranaghan:
>
> > (ns clojure.zip
> >  (:refer-clojure :exclude (replace remove))
> >  (:doc "Functional hierarchical zipper, with navigation, editing and
> >enumeration. See Huet."))
>
> > Is anyone else interested in namespace-level docstrings? Any thoughts
> > on what the interface might look like?
>
> I think, thats a good idea. The interface might look
> like your example above, following the :use and
> :require methods.
>
> Or it might go into direction of defn and defvar:
>
> (ns clojure.zip
>"Functional hierarchical zipper, with navigation, editing
>and enumeration. See Huet."
>(:refer-clojure :exclude (replace remove)))
>

Patch for the latter welcome:

http://code.google.com/p/clojure/issues/detail?id=30

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Using java.ext.dirs to manage the Classpath for Clojure REPLs

2009-01-04 Thread Drew Raines

Stephen C. Gilardi wrote:

> The "java.ext.dirs" System property provides a very convenient way to
> set up and maintain a Classpath for Clojure REPLs.

[...]

> In my case, I set the value of java.ext.dirs to a list of just one
> directory. That directory contains (relative) symbolic links to all
> the Jar files and directories I want Clojure to use as its Classpath.
>
> As a concrete example, here's what I have in that directory:

java.ext.dirs has a default value that -Djava.ext.dirs overwrites, so
make sure you replace whatever your platform's Java expects (like
$JAVA_HOME/lib/ext).  I've been bitten before trying to speak HTTPS
while not having sunpkcs11.jar available.

-Drew


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Functional Shuffle

2009-01-04 Thread aria42

Hey all, I wanted to write a functional shuffle sequence (not lazy)
rather than call out to Java. If anyone is interested here it is. If
anyone thinks there is a better way to implement the rifle shuffle,
let me know. Not asserting it's the most efficient or anything.

http://clojure.googlegroups.com/web/shuffle.clj?gsc=ma8fHxYAAABESh7T9QW_5DrK_LhfBk4i-vghgYgES8zAzJdW7J9-8w

Cheers, Aria
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Using a directory full of symlinks to manage the Classpath for Clojure REPLs

2009-01-04 Thread Stephen C. Gilardi


On Jan 4, 2009, at 10:07 PM, Drew Raines wrote:


java.ext.dirs has a default value that -Djava.ext.dirs overwrites, so
make sure you replace whatever your platform's Java expects (like
$JAVA_HOME/lib/ext).  I've been bitten before trying to speak HTTPS
while not having sunpkcs11.jar available.


Thanks for the info, Drew, R, and Laurent.

I've come up with this alternative for Mac OS X and Linux that gives  
the same convenient management, but doesn't use java.ext.dirs.


--Steve

#!/bin/bash

# clj: Launches a Clojure REPL with command line arguments
#
# Environment variables:
#
# Required:
#
#  CLOJURE_EXT  The path to a directory containing symlinks to the jar
#   files and directories that Clojure will use as its
#   Classpath.
#
# Optional:
#
#  CLOJURE_MAIN The Java class to launch
#   default: clojure.main
#   example: clojure.contrib.repl_ln
#
#  CLOJURE_OPTS Java options for this REPL's JVM instance
#   default:
#   example:"-Xms32M -Xmx128M -server"
#
#  CLOJURE_INIT Path to an init file to run, an @ prefix specifies a
#   classpath-relative path.
#   default:
#   example:"@init.clj"

set -o errexit
set -o nounset
#set -o xtrace

EXT="$(find ${CLOJURE_EXT} -type l -print0 | tr "\0" ":")"
export CLASSPATH="${EXT}${CLASSPATH:-}"

JAVA=java
OPTS=${CLOJURE_OPTS:-}
MAIN=${CLOJURE_MAIN:-clojure.main}
INIT=${CLOJURE_INIT:+--init ${CLOJURE_INIT}}
REPL=--repl

exec $JAVA $OPTS $MAIN $INIT $REPL $@



smime.p7s
Description: S/MIME cryptographic signature


Re: Functional Shuffle

2009-01-04 Thread Chouser

On Sun, Jan 4, 2009 at 10:17 PM, aria42  wrote:
>
> Hey all, I wanted to write a functional shuffle sequence (not lazy)
> rather than call out to Java.

See also: 
http://groups.google.com/group/clojure/browse_thread/thread/180842eb58c58370

--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
To unsubscribe from 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: literate snake

2009-01-04 Thread Christian Vest Hansen

On Sun, Jan 4, 2009 at 11:48 AM, Timothy Pratley
 wrote:
>
> From a cursory examination of "literate programming" central tenants
> appear to be:
> (1) order by human logic
> (2) use descriptive macros
> (3) program is a web
>
> (1) Is not possible in Clojure because it resolves symbols as it reads
> them. However that is easy to work around with a trivial patch (see
> http://groups.google.com/group/clojure/web/auto-def.patch). auto-def
> as the name suggests just defs a symbol that it can't find. So this
> allows you to declare functions out of order - top down - and hope
> they get redefed before any evaluation occurs. If evaluation does
> occur the error still has a stack showing where and what the var is
> (which will be nil - similar to a null pointer exception in java).
> Here is an example that will only work with auto-def:
> http://groups.google.com/group/clojure/web/lit-wc.clj
>
> (2) lisp is great for this with hyphenation as standard. (3) yikes!
> need to contemplate this.
>
> What are the arguments against *auto-def*?

It's going off topic, but...

It makes you believe that symbols, like class members in Java, can be
defined in any order and that the existence of the correct symbols
will be properly checked at compile time. Yet this assumption would be
wrong, no?


-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Some code review for clj-record?

2009-01-04 Thread Brian Doyle
John,

I was looking at the validates method and I had a thought I'd bounce off
you.  Instead of
just returning a hash of errors what about returning the record with the
errors hash in
the metadata?   That way you just have the data and the errors in one
"object" similar
to an ActiveRecord model.

On Sun, Jan 4, 2009 at 2:22 PM, Brian Doyle  wrote:

> Looks good.  I didn't know about the *file* var.
>
> On Sun, Jan 4, 2009 at 11:22 AM, John D. Hume wrote:
>
>>
>> Brian,
>> I incorporated your changes and then made changes to load and run all
>> clj_record/test/*-test.clj files. Thanks again.
>> -hume.
>>
>> >>
>>
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---