Re: let-else macro

2011-12-07 Thread Evan Gamble
Thanks for your comment, Sam.

Before you posted the comment, Peter Danenberg had asked if I would
modify let-else to include the behavior of your let? macro. Your
comment and his request have spurred me to action.

I've modified the macro to accept optional :when pred and :else
expr clauses after bindings. The :when clause acts just like
your :ensure clause.
It works with just :when or just :else or both, in either order.

I've also renamed my macro to be let?, because with the addition
of :when, the name let-else doesn't make sense.

The jar is still at https://clojars.org/org.clojars.egamble/let-else
The code is still at https://github.com/egamble/let-else

- Evan

On Dec 6, 7:13 pm, Sam Ritchie sritchi...@gmail.com wrote:
 I had a pattern that kept popping up in code of:

 (let [x (foo)
       y  (bar)]
     (when y
        (let [ ]
            )))

 that check jarred me, so I put this together:https://gist.github.com/1347312. 
 On reflection, discomfort with indentation
 levels probably isn't near the top of the to macro or not to macro?
 checklist.

 (defmacro let?
 [bindings  body]
  (let [[bind [kwd pred  more]] (split-with (complement #{:ensure})
 bindings)]
 `(let [~@bind]
  ~@(cond (and kwd more) [`(when ~pred (check-let [~@more] ~@body))]
 kwd [`(when ~pred ~@body)]
  :else body

 (let? [x 100
 y 300
  :ensure (pos? y)
 z (- y 250)]
  z)

 ;; expands to

 (let [x 100
 y 300]
  (when (pos? y)
 (let [z (- y 250)]
  z))) ;; = 50

 ;; and returns 50. The following returns nil:

 (let? [x 100

        y 300

        :ensure (neg? y)

        z (- y 250)]
       z) ;; = nil









 On Tue, Dec 6, 2011 at 11:51 AM, Evan Gamble solar.f...@gmail.com wrote:
  I noticed in my code that I often nest a let inside an if-let, or vice-
  versa, so I wrote a macro let-else that expands into nested lets,
  except where there's an :else expr after a binding, in which case
  that binding expands into an if-let.

  E.g.

  (let-else
   [foo (f1) :else (e)
    bar (f2)]
   (b1)
   (b2))

  expands into

  (if-let [foo (f1)]
   (let [bar (f2)]
     (b1)
     (b2))
   (e))

  The jar is athttps://clojars.org/org.clojars.egamble/let-else
  The code is athttps://github.com/egamble/let-else

  - Evan

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

 --
 Sam Ritchie, Twitter Inc
 703.662.1337
 @sritchie09

 (Too brief? Here's why!http://emailcharter.org)

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


Re: Building Clojure applications w/ Maven

2011-12-07 Thread Riccardo
The error shown in Ubuntu, when I try to execute the jar file, is:
Failed to load Main-Class manifest attribute from '...demo.jar' 

I suppose I am missing something in the main structure...

This is the pom:

project xmlns=http://maven.apache.org/POM/4.0.0; xmlns:xsi=http://
www.w3.org/2001/XMLSchema-instance
 xsi:schemaLocation=http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd;
modelVersion4.0.0/modelVersion
groupIdcom.snowtide/groupId
artifactIdeasy-maven/artifactId
packagingjar/packaging
version1.0-demo/version
nameClojure004/name
dependencies
dependency
groupIdorg.clojure/groupId
artifactIdclojure/artifactId
version1.1.0/version
/dependency
dependency
groupIdorg.clojure/groupId
artifactIdclojure-contrib/artifactId
version1.1.0/version
/dependency
/dependencies

build
plugins
plugin
groupIdcom.theoryinpractise/groupId
artifactIdclojure-maven-plugin/artifactId
version1.3.2/version
executions
execution
idcompile-clojure/id
phasecompile/phase
goals
goalcompile/goal
/goals
/execution
/executions
/plugin
/plugins
/build

repositories
repository
idclojure/id
urlhttp://build.clojure.org/releases/url
/repository
/repositories
/project

Thanks!


On Dec 7, 2:34 am, Richard Lyman richard.ly...@gmail.com wrote:
 Can you provide the pom you're using?

 By 'build' do you mean AOT?

 -Rich







 On Tue, Dec 6, 2011 at 3:35 PM, Riccardo riccardo.novie...@gmail.com wrote:
  Hello, I am doing my dissertation project with Clojure and I am using
  Maven to build. It works on REPL and it build successfully, but the
  JAR file doesn't work, it says: Java Exception all the time. Any
  suggestion?

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

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


Re: swank-cdt: Using Slime with the Clojure Debugging Toolkit

2011-12-07 Thread Young Kim
The following is the file lists in clojure-clojure-source-1.3.0-
alpha5.jar on Windows 7.
As you can see, there are no *.clj files in clojure-clojure-
source-1.3.0-alpha5.jar.
So I think that it is natural that 'clojure/set.clj - source not
found.' message appeared.
Do I misunderstand anything?

=
C:\work\lab\joy\lib\dev jar tf clojure-source-1.3.0-alpha5.jar
META-INF/
META-INF/MANIFEST.MF
clojure/
clojure/asm/
clojure/asm/AnnotationVisitor.java
clojure/asm/AnnotationWriter.java
clojure/asm/Attribute.java
clojure/asm/ByteVector.java
clojure/asm/ClassAdapter.java
clojure/asm/ClassReader.java
clojure/asm/ClassVisitor.java
clojure/asm/ClassWriter.java
clojure/asm/commons/
clojure/asm/commons/AdviceAdapter.java
clojure/asm/commons/AnalyzerAdapter.java
clojure/asm/commons/CodeSizeEvaluator.java
clojure/asm/commons/EmptyVisitor.java
clojure/asm/commons/GeneratorAdapter.java
clojure/asm/commons/LocalVariablesSorter.java
clojure/asm/commons/Method.java
clojure/asm/commons/package.html
clojure/asm/commons/SerialVersionUIDAdder.java
clojure/asm/commons/StaticInitMerger.java
clojure/asm/commons/TableSwitchGenerator.java
clojure/asm/Edge.java
clojure/asm/FieldVisitor.java
clojure/asm/FieldWriter.java
clojure/asm/Frame.java
clojure/asm/Handler.java
clojure/asm/Item.java
clojure/asm/Label.java
clojure/asm/MethodAdapter.java
clojure/asm/MethodVisitor.java
clojure/asm/MethodWriter.java
clojure/asm/Opcodes.java
clojure/asm/package.html
clojure/asm/Type.java
clojure/lang/
clojure/lang/AFn.java
clojure/lang/AFunction.java
clojure/lang/Agent.java
clojure/lang/AMapEntry.java
clojure/lang/APersistentMap.java
clojure/lang/APersistentSet.java
clojure/lang/APersistentVector.java
clojure/lang/ARef.java
clojure/lang/AReference.java
clojure/lang/ArityException.java
clojure/lang/ArrayChunk.java
clojure/lang/ArraySeq.java
clojure/lang/ASeq.java
clojure/lang/Associative.java
clojure/lang/Atom.java
clojure/lang/ATransientMap.java
clojure/lang/ATransientSet.java
clojure/lang/BigInt.java
clojure/lang/Binding.java
clojure/lang/Box.java
clojure/lang/ChunkBuffer.java
clojure/lang/ChunkedCons.java
clojure/lang/Compile.java
clojure/lang/Compiler.java
clojure/lang/Compiler.java.orig
clojure/lang/Compiler.java.rej
clojure/lang/Compiler.java~
clojure/lang/Cons.java
clojure/lang/Counted.java
clojure/lang/Delay.java
clojure/lang/DynamicClassLoader.java
clojure/lang/EnumerationSeq.java
clojure/lang/Fn.java
clojure/lang/IChunk.java
clojure/lang/IChunkedSeq.java
clojure/lang/IDeref.java
clojure/lang/IEditableCollection.java
clojure/lang/IFn.java
clojure/lang/IKeywordLookup.java
clojure/lang/ILookup.java
clojure/lang/ILookupSite.java
clojure/lang/ILookupThunk.java
clojure/lang/IMapEntry.java
clojure/lang/IMeta.java
clojure/lang/Indexed.java
clojure/lang/IndexedSeq.java
clojure/lang/IObj.java
clojure/lang/IPersistentCollection.java
clojure/lang/IPersistentList.java
clojure/lang/IPersistentMap.java
clojure/lang/IPersistentSet.java
clojure/lang/IPersistentStack.java
clojure/lang/IPersistentVector.java
clojure/lang/IPromiseImpl.java
clojure/lang/IProxy.java
clojure/lang/IReduce.java
clojure/lang/IRef.java
clojure/lang/IReference.java
clojure/lang/ISeq.java
clojure/lang/IteratorSeq.java
clojure/lang/ITransientAssociative.java
clojure/lang/ITransientCollection.java
clojure/lang/ITransientMap.java
clojure/lang/ITransientSet.java
clojure/lang/ITransientVector.java
clojure/lang/Keyword.java
clojure/lang/KeywordLookupSite.java
clojure/lang/LazilyPersistentVector.java
clojure/lang/LazySeq.java
clojure/lang/LineNumberingPushbackReader.java
clojure/lang/LispReader.java
clojure/lang/LockingTransaction.java
clojure/lang/MapEntry.java
clojure/lang/MapEquivalence.java
clojure/lang/MethodImplCache.java
clojure/lang/MultiFn.java
clojure/lang/Named.java
clojure/lang/Namespace.java
clojure/lang/Numbers.java
clojure/lang/Obj.java
clojure/lang/PersistentArrayMap.java
clojure/lang/PersistentHashMap.java
clojure/lang/PersistentHashSet.java
clojure/lang/PersistentList.java
clojure/lang/PersistentQueue.java
clojure/lang/PersistentStructMap.java
clojure/lang/PersistentTreeMap.java
clojure/lang/PersistentTreeSet.java
clojure/lang/PersistentVector.java
clojure/lang/ProxyHandler.java
clojure/lang/Range.java
clojure/lang/Ratio.java
clojure/lang/Ref.java
clojure/lang/Reflector.java
clojure/lang/Repl.java
clojure/lang/RestFn.java
clojure/lang/Reversible.java
clojure/lang/RT.java
clojure/lang/Script.java
clojure/lang/Seqable.java
clojure/lang/SeqEnumeration.java
clojure/lang/SeqIterator.java
clojure/lang/Sequential.java
clojure/lang/Settable.java
clojure/lang/Sorted.java
clojure/lang/StringSeq.java
clojure/lang/Symbol.java
clojure/lang/TransactionalHashMap.java
clojure/lang/Util.java
clojure/lang/Var.java
clojure/lang/XMLHandler.java
clojure/main.java



On Dec 7, 12:47 pm, Andrew ache...@gmail.com wrote:
 Thanks for taking the time Sean! You're 

Re: swank-cdt: Using Slime with the Clojure Debugging Toolkit

2011-12-07 Thread Young Kim
I posted the related problem on 
https://github.com/technomancy/swank-clojure/issues/86
Please refer to it! I hope that it will be helpful for you.

On Dec 7, 12:47 pm, Andrew ache...@gmail.com wrote:
 Thanks for taking the time Sean! You're right...

    - I'm on Windows XP
    - I had to copy tools.jar to my projects lib manually after lein deps
    (not sure how to change the classpath)
    - My emacs setup is munged -- I can run M-x eshell but not M-x shell; I
    have to do lein swank and M-x slime-connect because I can't M-x
    clojure-jack-in

-- 
You 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: Building Clojure applications w/ Maven

2011-12-07 Thread Matteo Moci
leiningen has a target you can call like this:

lein pom

maybe setting up a fake simple lein project
you can watch how the generated pom is different from yours.

On Wed, Dec 7, 2011 at 1:32 PM, Riccardo riccardo.novie...@gmail.com wrote:
 The error shown in Ubuntu, when I try to execute the jar file, is:
 Failed to load Main-Class manifest attribute from '...demo.jar' 

 I suppose I am missing something in the main structure...

 This is the pom:

 project xmlns=http://maven.apache.org/POM/4.0.0; xmlns:xsi=http://
 www.w3.org/2001/XMLSchema-instance
         xsi:schemaLocation=http://maven.apache.org/POM/4.0.0
 http://maven.apache.org/maven-v4_0_0.xsd;
    modelVersion4.0.0/modelVersion
    groupIdcom.snowtide/groupId
    artifactIdeasy-maven/artifactId
    packagingjar/packaging
    version1.0-demo/version
    nameClojure004/name
    dependencies
        dependency
            groupIdorg.clojure/groupId
            artifactIdclojure/artifactId
            version1.1.0/version
        /dependency
        dependency
            groupIdorg.clojure/groupId
            artifactIdclojure-contrib/artifactId
            version1.1.0/version
        /dependency
    /dependencies

    build
        plugins
            plugin
                groupIdcom.theoryinpractise/groupId
                artifactIdclojure-maven-plugin/artifactId
                version1.3.2/version
                executions
                    execution
                        idcompile-clojure/id
                        phasecompile/phase
                        goals
                            goalcompile/goal
                        /goals
                    /execution
                /executions
            /plugin
        /plugins
    /build

    repositories
        repository
            idclojure/id
            urlhttp://build.clojure.org/releases/url
        /repository
    /repositories
 /project

 Thanks!


 On Dec 7, 2:34 am, Richard Lyman richard.ly...@gmail.com wrote:
 Can you provide the pom you're using?

 By 'build' do you mean AOT?

 -Rich







 On Tue, Dec 6, 2011 at 3:35 PM, Riccardo riccardo.novie...@gmail.com wrote:
  Hello, I am doing my dissertation project with Clojure and I am using
  Maven to build. It works on REPL and it build successfully, but the
  JAR file doesn't work, it says: Java Exception all the time. Any
  suggestion?

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

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



-- 
Matteo Moci
http://it.linkedin.com/in/matteomoci
http://about.me/matteomoci/bio

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


Clojure/West registration open - San Jose - Mar 16-17

2011-12-07 Thread Alex Miller
Hello all,

If you're interested in Clojure/West (http://clojurewest.org, San
Jose, Mar 16-17 or training Mar 12-15), you can now:

- Submit a talk: http://clojurewest.org/call-for-presentations/
- Register for the conference: http://www.regonline.com/clojurewest2012
- Early bird - $450 until Jan 20
- Regular - $550 Jan 21 - Feb 17
- Late - $650 Feb 18 - Mar 15
- Register for training: http://www.regonline.com/clojurewest2012training
- Clojure Web with Chris Granger - Mar 12-13 or 14-15 - $1200
- Pallet with Hugo Duncan, Toni Batchelli - Mar 14-15 - $1200
- Cascalog with Sam Ritchie - Mar 13-15 - $1900
- Intro to Clojure with Clojure/core - Mar 13-15 - $1900
- Reserve a hotel room: https://resweb.passkey.com/go/clojurewest
- $119 / night, only open till Feb 20th

We've already had several excellent talks submitted in the CFP!  It's
going to be a great conference.  If you have any questions, let me
know.

Alex Miller

-- 
You 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: Surprising behavior with clojure.core/int (and probably other primitive integer functions)

2011-12-07 Thread Ben Smith-Mannschott
Would it help to have a naming convention for Clojure to distinguish
compile-time flags from normal dynamic vars?  // ben

On Tue, Dec 6, 2011 at 17:05, David Nolen dnolen.li...@gmail.com wrote:
 *unchecked-math* is a compiler flag.

 On Tue, Dec 6, 2011 at 7:00 AM, Cedric Greevey cgree...@gmail.com wrote:

 user= (binding [*unchecked-math* true] (map int [33 77 0x]))
 #IllegalArgumentException java.lang.IllegalArgumentException: Value out
 of range for int: 4294967295

 The cause of this:

 (defn int
   Coerce to int
   {
    :inline (fn  [x] `(. clojure.lang.RT (~(if *unchecked-math*
 'uncheckedIntCast 'intCast) ~x)))
    :added 1.0}
   [x] (. clojure.lang.RT (intCast x)))

 The inline and non-inline version don't coincide -- the non-inline version
 lacks the check for *unchecked-math*.

 On top of that, the inline version sort-of doesn't work anyway --
 specifically, it doesn't work if you do the obvious:

 user= (binding [*unchecked-math* true] (int 0x))
 #IllegalArgumentException java.lang.IllegalArgumentException: Value out
 of range for int: 4294967295
 user= (defn foo [] (binding [*unchecked-math* true] (int 0x)))
 #'user/foo
 user= (foo)
 #IllegalArgumentException java.lang.IllegalArgumentException: Value out
 of range for int: 4294967295

 The problem there is apparently that it checks *unchecked-math* at
 macroexpansion time, and of course binding it at runtime to do some
 unchecked math therefore binds it too late to influence the int function.

 If this is intentional, to avoid expensive runtime checks of dynamic Vars,
 then there are two additional problems.

 First, there's the apparent lack of an unchecked-int function, or similar,
 that either is unchecked or checks *unchecked-math* at runtime, for those
 who want dynamic behavior even if there's a cost.

 Without this, there's no way to get unchecked int casts in map and other
 HOFs short of ugly hacks like #(int %) or #(clojure.lang.RT/uncheckedIntCast
 %).

 Another use case would be when using ints not for speed but because you
 want a 32-bit wraparound integer for some other purpose, such as talking to
 I/O devices or legacy file formats that want such things, or to implement
 certain algorithms that rely heavily on wraparound and bit arithmetic in a
 relatively speed-insensitive context, likely where I/O is the bottleneck.

 Furthermore, though (do (set! *unchecked-math* true) (println (int
 0x)) (set! *unchecked-math* false)) works, it is ugly as sin and
 set! is (usually) evil.

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


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

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


Re: let-else macro

2011-12-07 Thread Stephen Compall
On Tue, 2011-12-06 at 19:13 -0800, Sam Ritchie wrote:
 (let [x (foo)
   y  (bar)]
 (when y
(let [ ]
)))
 
 that check jarred me, so I put this together:
 https://gist.github.com/1347312. On reflection, discomfort with indentation
 levels probably isn't near the top of the to macro or not to macro?
 checklist.

And may be anyway further generalized:

(defmacro - [ forms]
  `(- ~@(reverse forms)))

(- (let [x (foo) y (bar)])
 (when y)
 (let [ ])
 (do ))

-- 
Stephen Compall
^aCollection allSatisfy: [:each|aCondition]: less is better

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


Re: Building Clojure applications w/ Maven

2011-12-07 Thread Stephen Compall
On Wed, 2011-12-07 at 13:41 +0200, Matteo Moci wrote:
 lein pom
 
 maybe setting up a fake simple lein project
 you can watch how the generated pom is different from yours.

Unfortunately, that pom is too fake to be useful as a comparison tool.


-- 
Stephen Compall
^aCollection allSatisfy: [:each|aCondition]: less is better

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


Dynamically Loading Jar Strategy

2011-12-07 Thread Pierre-Yves Ritschard
Hi,

I have a use case where a daemon needs to read full namespaces from an
external jar.
I can successfuly access the namespace in the jar with tools.namespace/
find-namespaces-in-jarfile, then from the jarfile, selecting
appropriate entries, coercing into readers and then loading with load-
reader.

This approach breaks as soon as the supplied jar does requires, since
the jar is not on the classpath. I am a bit surprised that setting a
classloader in the current thread with setContextClassLoader does not
work, as my binding for *use-context-classloader* is the default:
true.

I could obviously supply a fixed directory that is always in the
classpath but that would require having two configuration files, which
I thought I could avoid.

Is there a way around this, or am I stuck ?

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


Re: getting inside another dynamic scope?

2011-12-07 Thread Andrew
(Sorry, I'll read this first 
http://clojure.org/vars#Vars%20and%20the%20Global%20Environment)

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

Re: let-else macro

2011-12-07 Thread Marshall T. Vandegrift
Stephen Compall stephen.comp...@gmail.com writes:

 And may be anyway further generalized:

 (defmacro - [ forms]
   `(- ~@(reverse forms)))

 (- (let [x (foo) y (bar)])
  (when y)
  (let [ ])
  (do ))

Another alternative,

(require '[clojure.algo.monads :as m])

(m/domonad m/maybe-m
  [x (foo), y (bar), :let [z (baz)], :when ( z 5)]
  (+ x y z))

-Marshall

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


Re: let-else macro

2011-12-07 Thread Peter Danenberg
Thanks, Evan; I had a use-case where the truthiness of nil would have
forced me out of `let-else.' This new predicate-abstraction is
beautiful.

Quoth Evan Gamble on Sweetmorn, the 49th of The Aftermath:
 Thanks for your comment, Sam.
 
 Before you posted the comment, Peter Danenberg had asked if I would
 modify let-else to include the behavior of your let? macro. Your
 comment and his request have spurred me to action.
 
 I've modified the macro to accept optional :when pred and :else
 expr clauses after bindings. The :when clause acts just like
 your :ensure clause.
 It works with just :when or just :else or both, in either order.
 
 I've also renamed my macro to be let?, because with the addition
 of :when, the name let-else doesn't make sense.
 
 The jar is still at https://clojars.org/org.clojars.egamble/let-else
 The code is still at https://github.com/egamble/let-else
 
 - Evan
 
 On Dec 6, 7:13 pm, Sam Ritchie sritchi...@gmail.com wrote:
  I had a pattern that kept popping up in code of:
 
  (let [x (foo)
        y  (bar)]
      (when y
         (let [ ]
             )))
 
  that check jarred me, so I put this 
  together:https://gist.github.com/1347312. On reflection, discomfort with 
  indentation
  levels probably isn't near the top of the to macro or not to macro?
  checklist.
 
  (defmacro let?
  [bindings  body]
   (let [[bind [kwd pred  more]] (split-with (complement #{:ensure})
  bindings)]
  `(let [~@bind]
   ~@(cond (and kwd more) [`(when ~pred (check-let [~@more] ~@body))]
  kwd [`(when ~pred ~@body)]
   :else body
 
  (let? [x 100
  y 300
   :ensure (pos? y)
  z (- y 250)]
   z)
 
  ;; expands to
 
  (let [x 100
  y 300]
   (when (pos? y)
  (let [z (- y 250)]
   z))) ;; = 50
 
  ;; and returns 50. The following returns nil:
 
  (let? [x 100
 
         y 300
 
         :ensure (neg? y)
 
         z (- y 250)]
        z) ;; = nil
 
 
 
 
 
 
 
 
 
  On Tue, Dec 6, 2011 at 11:51 AM, Evan Gamble solar.f...@gmail.com wrote:
   I noticed in my code that I often nest a let inside an if-let, or vice-
   versa, so I wrote a macro let-else that expands into nested lets,
   except where there's an :else expr after a binding, in which case
   that binding expands into an if-let.
 
   E.g.
 
   (let-else
    [foo (f1) :else (e)
     bar (f2)]
    (b1)
    (b2))
 
   expands into
 
   (if-let [foo (f1)]
    (let [bar (f2)]
      (b1)
      (b2))
    (e))
 
   The jar is athttps://clojars.org/org.clojars.egamble/let-else
   The code is athttps://github.com/egamble/let-else
 
   - Evan
 
   --
   You received this message because you are subscribed to the Google
   Groups Clojure group.
   To post to this group, send email to clojure@googlegroups.com
   Note that posts from new members are moderated - please be patient with
   your first post.
   To unsubscribe from this group, send email to
   clojure+unsubscr...@googlegroups.com
   For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
 
  --
  Sam Ritchie, Twitter Inc
  703.662.1337
  @sritchie09
 
  (Too brief? Here's why!http://emailcharter.org)
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 

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


AOT compilation for library targeting multiple Clojure versions

2011-12-07 Thread Sam Ritchie
Hey all,

I'm almost finished integration Kryo serialization into Cascalog using Alex
Miller's Carbonite library, and I'm running into a bit of a hitch with
AOT-compilation. I'm exposing the Clojure serializers to Kryo using a
namespace compiled with :gen-class:

https://github.com/sritchie/carbonite/blob/master/src/carbonite/JavaBridge.clj

and calling JavaBridge.enhanceRegistry(kryo); from my java code. The
problem is that this locks me into Clojure 1.3.0, or whatever version was
used to compile JavaBridge.

What's the recommended way to work around this and support multiple Clojure
versions? Should I build JavaBridge for 1.2 and 1.3 under different names
and query *clojure-version* from java at runtime to decide which version to
use?

Thanks all,
-- 
Sam Ritchie, Twitter Inc
703.662.1337
@sritchie09

(Too brief? Here's why! http://emailcharter.org)

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

Re: AOT compilation for library targeting multiple Clojure versions

2011-12-07 Thread Meikel Brandmeyer (kotarak)
Hi,

I found the easiest approach to be a small wrapper written in Java. 
Something like this should work. Not tested, though.

package carbonite;

import clojure.lang.RT;
import clojure.lang.Var;
import com.esotericsoftware.kryo.Kryo;

public class JavaBridge {
static Var require = RT.var(clojure.core, require);
static Var symbol = RT.var(clojure.core, symbol);

static Var defaultReg;
static Var regSerializers;
static Var cljPrimitives;
static var cljCollections;

static {
require.invoke(symbol.invoke(carbonite.api));
require.invoke(symbol.invoke(carbonite.serializer));

defaultReg = RT.var(carbonite.api, default-registry);
regSerializers = RT.var(carbonite.api, register-serializers);
cljPrimitives = RT.var(carbonite.serializer, 
clojure-primitives);
cljCollections = RT.var(carbonite.serializer, 
clojure-collections);
}

static Kryo defaultRegistry() {
return (Kryo)defaultReg.invoke();
}

static void enhanceRegistry(Kryo registry) {
regSerializers.invoke(registry, cljPrimitives.deref());
regSerializers.invoke(registry, cljCollections.invoke(registry));
}
}

Sincerely
Meikel

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

Re: Literate Programming in Emacs?

2011-12-07 Thread Robert McIntyre
Here's a pew literate programs I've written, as well as the website on
which they are hosted.

http://hg.bortreb.com/abomination/
http://hg.bortreb.com/aurellem/
http://hg.bortreb.com/cortex/

http://www.aurellem.com

I use some emacs scripts to automate tangling and weaving.
http://hg.bortreb.com/org-tools/
http://hg.bortreb.com/repl/

sincerely,
--Robert McIntyre

On Tue, Nov 29, 2011 at 7:31 PM, Stuart Sierra
the.stuart.sie...@gmail.com wrote:
 Haven't done any recently. A long, long time ago I wrote a Common Lisp
 FFI tool using a Literate Programming tool called noweb.

 It's so old it predates GitHub: http://stuartsierra.com/software/perl-in-lisp

 -S

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

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


NW UK Clojurians?

2011-12-07 Thread Simon Holgate
Hi,

anyone out there in the NW of the UK? I'm in Liverpool and pondering a
NW Meetup.

Any takers?

Simon

-- 
You 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: Keeping an SSH tunnel open on Heroku using Clojure

2011-12-07 Thread Dave Barker
FYI I've improved my example https://gist.github.com/1443579 in case anyone 
needs it, not tested it on Heroku yet though.

Cheers, Dave.

-- 
You 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: Get multiple vals from a map

2011-12-07 Thread vitalyper
Thanks, Alan. It is more general solution which also works for keys
that are not keywords
user= (map {a 1 b 2 c 3} [ a b])
(1 2)

On Dec 1, 5:02 pm, Alan Malloy a...@malloys.org wrote:
 I usually use juxt, but a more correct/robust solution is to use map,
 with the lookup-map as the function:

 (map {:foo 1 :bar 2 :baz 0} [:foo :bar])

 On Dec 1, 12:26 pm, Ulises ulises.cerv...@gmail.com wrote:







  How about using juxt:

  sandbox ((juxt :foo :bar) {:foo 1 :bar 2 :baz 0})
  [1 2]
  sandbox

  This only works, however, if you use keywords for keys (as they are
  functions themselves).

  U

-- 
You 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: swank-cdt: Using Slime with the Clojure Debugging Toolkit

2011-12-07 Thread George Jahad
I think you are right Sean.  This is a problem on Windows with the
file separator.

Aravindh Johendran suggested a fix a while ago.  Let me try
integrating it and see if that doesn't fix the windows platform.

I'll let you know when I have something.


On Dec 6, 4:36 pm, Sean Corfield seancorfi...@gmail.com wrote:

 (looks like you're on Windows from clojure\set.clj so that might be a
 clue to a difference)

 Sean

 On Tue, Dec 6, 2011 at 1:38 PM, Andrew ache...@gmail.com wrote:
  user (require 'clojure.set)
  nil
  user (set-bp clojure.set/difference)
  nil
  nil
  user (clojure.set/difference #{1 2} #{2 3})

  CDT buffer appears

  CDT BreakpointEvent in thread Swank REPL Thread
  From here you can: e/eval, v/show source, s/step, x/next, o/exit func

  Restarts:
   0: [QUIT] Quit to the SLIME top level

  Backtrace:
    0: clojure.set$difference.invoke(set.clj:48)
    [No Locals]

  If I press v and then go to the *Messageages* buffer, I see this:

  Source not found; check @source-path

  clojure\set.clj - source not found.

-- 
You 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: swank-cdt: Using Slime with the Clojure Debugging Toolkit

2011-12-07 Thread George Jahad


On Dec 6, 11:05 pm, Young Kim philo...@gmail.com wrote:
 The following is the file lists in clojure-clojure-source-1.3.0-
 alpha5.jar on Windows 7.
 As you can see, there are no *.clj files in clojure-clojure-
 source-1.3.0-alpha5.jar.
 So I think that it is natural that 'clojure/set.clj - source not
 found.' message appeared.
 Do I misunderstand anything?


Andrew says he is seeing the problem on Clojure 1.2 as well.

-- 
You 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: swank-cdt: Using Slime with the Clojure Debugging Toolkit

2011-12-07 Thread George Jahad
Thanks very much for this bug report Young!

I'm going to summarize your findings here for everyone else.
Basically, you found 3 problems:

1. The set-bp command requires full name-space qualification of the
function name.

2. On Windows, if attach.dll isn't on the java-library path, you get
the following errors:

on stdout:
java.util.ServiceConfigurationError:
com.sun.tools.attach.spi.AttachProvider: Pr
ovider sun.tools.attach.WindowsAttachProvider could not be
instantiated: java.la
ng.UnsatisfiedLinkError: no attach in java.library.path

at the repl:
CDT  1.4.0a startup failed:  #RuntimeException
java.lang.RuntimeException: java.io.IOException: no providers
installed


The fix is to add something like the following to your project.clj:

 :jvm-opts [-agentlib:jdwp=transport=dt_socket,server=y,suspend=n
 -Djava.library.path=C:\\usr\\lang\\java\\jdk\\jre\\bin]
  :extra-classpath-dirs [C:\\usr\\lang\\java\\jdk\\lib\\tools.jar]


3. You are seeing a problem with how swank-cdt handles file separators
on
Windows, which may be the same problem reported by Andrew above.  I'll
have you try the fix I send him and see if it helps you as well.

Thanks again!


On Dec 7, 2:57 am, Young Kim philo...@gmail.com wrote:
 I posted the related problem 
 onhttps://github.com/technomancy/swank-clojure/issues/86
 Please refer to it! I hope that it will be helpful for you.

 On Dec 7, 12:47 pm, Andrew ache...@gmail.com wrote:

  Thanks for taking the time Sean! You're right...

     - I'm on Windows XP
     - I had to copy tools.jar to my projects lib manually after lein deps
     (not sure how to change the classpath)
     - My emacs setup is munged -- I can run M-x eshell but not M-x shell; I
     have to do lein swank and M-x slime-connect because I can't M-x
     clojure-jack-in

-- 
You 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: AOT compilation for library targeting multiple Clojure versions

2011-12-07 Thread Sam Ritchie
Meikel, thanks so much for this. I followed your
advicehttps://github.com/sritchie/carbonite/blob/master/src/jvm/carbonite/JavaBridge.javaand
Cascalog and Carbonite are now working Clojures 1.2, 1.3 and 1.4 :)

Cheers,
Sam

On Wed, Dec 7, 2011 at 8:17 AM, Meikel Brandmeyer (kotarak) 
m...@kotka.dewrote:

 Hi,

 I found the easiest approach to be a small wrapper written in Java.
 Something like this should work. Not tested, though.

 package carbonite;

 import clojure.lang.RT;
 import clojure.lang.Var;
 import com.esotericsoftware.kryo.Kryo;

 public class JavaBridge {
 static Var require = RT.var(clojure.core, require);
 static Var symbol = RT.var(clojure.core, symbol);

 static Var defaultReg;
 static Var regSerializers;
 static Var cljPrimitives;
 static var cljCollections;

 static {
 require.invoke(symbol.invoke(carbonite.api));
 require.invoke(symbol.invoke(carbonite.serializer));

 defaultReg = RT.var(carbonite.api, default-registry);
 regSerializers = RT.var(carbonite.api, register-serializers);
 cljPrimitives = RT.var(carbonite.serializer,
 clojure-primitives);
 cljCollections = RT.var(carbonite.serializer,
 clojure-collections);
 }

 static Kryo defaultRegistry() {
 return (Kryo)defaultReg.invoke();
 }

 static void enhanceRegistry(Kryo registry) {
 regSerializers.invoke(registry, cljPrimitives.deref());
 regSerializers.invoke(registry, cljCollections.invoke(registry));
 }
 }

 Sincerely
 Meikel

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




-- 
Sam Ritchie, Twitter Inc
703.662.1337
@sritchie09

(Too brief? Here's why! http://emailcharter.org)

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

Re: Dynamically Loading Jar Strategy

2011-12-07 Thread vitalyper
You can add jar to a classpath at runtime via the hack below.
http://groups.google.com/group/clojure/browse_thread/thread/95ea6e918c430e/69c0d195defeeed3?lnk=gstq=classpath#69c0d195defeeed3

HTH

On Dec 7, 10:26 am, Pierre-Yves Ritschard p...@spootnik.org wrote:
 Hi,

 I have a use case where a daemon needs to read full namespaces from an
 external jar.
 I can successfuly access the namespace in the jar with tools.namespace/
 find-namespaces-in-jarfile, then from the jarfile, selecting
 appropriate entries, coercing into readers and then loading with load-
 reader.

 This approach breaks as soon as the supplied jar does requires, since
 the jar is not on the classpath. I am a bit surprised that setting a
 classloader in the current thread with setContextClassLoader does not
 work, as my binding for *use-context-classloader* is the default:
 true.

 I could obviously supply a fixed directory that is always in the
 classpath but that would require having two configuration files, which
 I thought I could avoid.

 Is there a way around this, or am I stuck ?

-- 
You 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: Dynamically Loading Jar Strategy

2011-12-07 Thread Pierre-Yves Ritschard
I ended up doing that, all the other approaches fail for me.
Thanks for the confirmation.

On Wed, Dec 7, 2011 at 8:12 PM, vitalyper vitaly...@yahoo.com wrote:
 You can add jar to a classpath at runtime via the hack below.
 http://groups.google.com/group/clojure/browse_thread/thread/95ea6e918c430e/69c0d195defeeed3?lnk=gstq=classpath#69c0d195deeed3

 HTH

 On Dec 7, 10:26 am, Pierre-Yves Ritschard p...@spootnik.org wrote:
 Hi,

 I have a use case where a daemon needs to read full namespaces from an
 external jar.
 I can successfuly access the namespace in the jar with tools.namespace/
 find-namespaces-in-jarfile, then from the jarfile, selecting
 appropriate entries, coercing into readers and then loading with load-
 reader.

 This approach breaks as soon as the supplied jar does requires, since
 the jar is not on the classpath. I am a bit surprised that setting a
 classloader in the current thread with setContextClassLoader does not
 work, as my binding for *use-context-classloader* is the default:
 true.

 I could obviously supply a fixed directory that is always in the
 classpath but that would require having two configuration files, which
 I thought I could avoid.

 Is there a way around this, or am I stuck ?

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

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


Re: Dynamically Loading Jar Strategy

2011-12-07 Thread Stuart Sierra
Also check out https://github.com/cemerick/pomegranate
-S

-- 
You 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: Dynamically Loading Jar Strategy

2011-12-07 Thread Kevin Downey
try something like

https://github.com/hiredman/clojurebot/blob/master/src/clojurebot/plugin.clj

On Wed, Dec 7, 2011 at 11:53 AM, Pierre-Yves Ritschard p...@spootnik.org 
wrote:
 I ended up doing that, all the other approaches fail for me.
 Thanks for the confirmation.

 On Wed, Dec 7, 2011 at 8:12 PM, vitalyper vitaly...@yahoo.com wrote:
 You can add jar to a classpath at runtime via the hack below.
 http://groups.google.com/group/clojure/browse_thread/thread/95ea6e918c430e/69c0d195defeeed3?lnk=gstq=classpath#69c0d195deeed3

 HTH

 On Dec 7, 10:26 am, Pierre-Yves Ritschard p...@spootnik.org wrote:
 Hi,

 I have a use case where a daemon needs to read full namespaces from an
 external jar.
 I can successfuly access the namespace in the jar with tools.namespace/
 find-namespaces-in-jarfile, then from the jarfile, selecting
 appropriate entries, coercing into readers and then loading with load-
 reader.

 This approach breaks as soon as the supplied jar does requires, since
 the jar is not on the classpath. I am a bit surprised that setting a
 classloader in the current thread with setContextClassLoader does not
 work, as my binding for *use-context-classloader* is the default:
 true.

 I could obviously supply a fixed directory that is always in the
 classpath but that would require having two configuration files, which
 I thought I could avoid.

 Is there a way around this, or am I stuck ?

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

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



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

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


Re: getting inside another dynamic scope?

2011-12-07 Thread Stuart Sierra
Clojure doesn't provide any mechanism to peek inside other threads. Dynamic 
Var bindings create java.lang.ThreadLocal objects to store the temporary 
bindings. A Java debugger or IDE *might* let you look at those.

-S

-- 
You 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: AOT compilation for library targeting multiple Clojure versions

2011-12-07 Thread Stuart Sierra
This is a well-known issue. Some workarounds and potential fixes here:
http://dev.clojure.org/display/design/Transitive+AOT+Compilation

-S

-- 
You 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: Building Clojure applications w/ Maven

2011-12-07 Thread Stuart Sierra
Adding the Main-Class attribute to a JAR manifest is handled, in Maven, by 
the Assembly Plugin.  See here for examples:

http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

-S

-- 
You 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: no :main namespace specified in project.clj

2011-12-07 Thread Stuart Sierra
`lein run` expects the project.clj file to specify a namespace that 
contains the main function used to start the program.

It usually looks like this:
https://github.com/technomancy/leiningen/blob/07a755c8afe936ec904ea455659dadf8aae1ae88/sample.project.clj#L95

See https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md
under What to do with it for more information.

-S

-- 
You 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: Building Clojure applications w/ Maven

2011-12-07 Thread Riccardo
That Stuart Sierra? I am a fan of you :) and I have bought Practical
Clojure (but not read much yet).
Thanks, I'll try that solution!

On Dec 7, 8:13 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 Adding the Main-Class attribute to a JAR manifest is handled, in Maven, by
 the Assembly Plugin.  See here for examples:

 http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

 -S

-- 
You 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: Building Clojure applications w/ Maven

2011-12-07 Thread Alex Ott
Hi

had you seen my article on Clojure/Maven?
(http://alexott.net/en/clojure/ClojureMaven.html)

P.S. and you can look onto following project
(https://github.com/alexott/clojure-examples/tree/master/compojure-simple)
that uses multi-project maven setup

On Tue, Dec 6, 2011 at 11:35 PM, Riccardo riccardo.novie...@gmail.com wrote:
 Hello, I am doing my dissertation project with Clojure and I am using
 Maven to build. It works on REPL and it build successfully, but the
 JAR file doesn't work, it says: Java Exception all the time. Any
 suggestion?

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



-- 
With best wishes,                    Alex Ott
http://alexott.net/
Tiwtter: alexott_en (English), alexott (Russian)
Skype: alex.ott

-- 
You 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: Dynamically Loading Jar Strategy

2011-12-07 Thread Pierre-Yves Ritschard
Thanks a lot for the good advice. Pomegranate is very nice and very
useful for testing.
As for your trick Kevin, certainly nicer that the reflection mess.

On Wed, Dec 7, 2011 at 9:00 PM, Kevin Downey redc...@gmail.com wrote:
 try something like

 https://github.com/hiredman/clojurebot/blob/master/src/clojurebot/plugin.clj

 On Wed, Dec 7, 2011 at 11:53 AM, Pierre-Yves Ritschard p...@spootnik.org 
 wrote:
 I ended up doing that, all the other approaches fail for me.
 Thanks for the confirmation.

 On Wed, Dec 7, 2011 at 8:12 PM, vitalyper vitaly...@yahoo.com wrote:
 You can add jar to a classpath at runtime via the hack below.
 http://groups.google.com/group/clojure/browse_thread/thread/95ea6e918c430e/69c0d195defeeed3?lnk=gstq=classpath#69c0d195deeed3

 HTH

 On Dec 7, 10:26 am, Pierre-Yves Ritschard p...@spootnik.org wrote:
 Hi,

 I have a use case where a daemon needs to read full namespaces from an
 external jar.
 I can successfuly access the namespace in the jar with tools.namespace/
 find-namespaces-in-jarfile, then from the jarfile, selecting
 appropriate entries, coercing into readers and then loading with load-
 reader.

 This approach breaks as soon as the supplied jar does requires, since
 the jar is not on the classpath. I am a bit surprised that setting a
 classloader in the current thread with setContextClassLoader does not
 work, as my binding for *use-context-classloader* is the default:
 true.

 I could obviously supply a fixed directory that is always in the
 classpath but that would require having two configuration files, which
 I thought I could avoid.

 Is there a way around this, or am I stuck ?

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

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



 --
 And what is good, Phaedrus,
 And what is not good—
 Need we ask anyone to tell us these things?

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

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


Re: Building Clojure applications w/ Maven

2011-12-07 Thread Riccardo
Right I am finally getting closer: the generated jar finally works,
but it still gives a message A java exception has occurred

My code (not really mine...) look like this:
-
(ns com.yourcompany.defpackage
(:gen-class))


(import '(javax.swing JFrame JButton JOptionPane)) ;'
(import '(java.awt.event ActionListener))  ;'

(let [frame (JFrame. Hello Swing)
 button (JButton. Click Me)]
 (.addActionListener button
   (proxy [ActionListener] []
 (actionPerformed [evt]
   (JOptionPane/showMessageDialog  nil,
  (str htmlHello from bClojure/b. Button 
   (.getActionCommand evt)  clicked.)

 (.. frame getContentPane (add button))

 (doto frame
   (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
   .pack
   (.setVisible true)))

print(code sample)

-

The POM file is this:

---
?xml version=1.0 encoding=UTF-8?
project xmlns=http://maven.apache.org/POM/4.0.0; xmlns:xsi=http://
www.w3.org/2001/XMLSchema-instance
  xsi:schemaLocation=http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd;
properties
clojure.version1.2.0/clojure.version
/properties
  modelVersion4.0.0/modelVersion
  groupIdorg.enclojure/groupId
  artifactIdsample/artifactId
  version0.0.1/version
  nameBanking_Clojure/name
  descriptionBanking_Clojure/description
  build
 sourceDirectorysrc/main/clojure/sourceDirectory
 testSourceDirectorysrc/test/clojure/testSourceDirectory
resources
resource
directorysrc/main/clojure/directory
/resource
resource
directorysrc/main/resources/directory
/resource
/resources
testResources
testResource
directorysrc/test/clojure/directory
/testResource
/testResources
plugins
  plugin
groupIdcom.theoryinpractise/groupId
artifactIdclojure-maven-plugin/artifactId
version1.3.2/version
configuration
sourceDirectories
sourceDirectorysrc/main/clojure/sourceDirectory
/sourceDirectories
clojureOptions-Xmx1G/clojureOptions
/configuration
executions
  execution
idcompile-clojure/id
phasecompile/phase
goals
  goalcompile/goal
/goals
  /execution
/executions
  /plugin
  plugin
groupIdorg.apache.maven.plugins/groupId
artifactIdmaven-compiler-plugin/artifactId
configuration
  source1.6/source
  target1.6/target
/configuration
  /plugin

   plugin
artifactIdmaven-assembly-plugin/artifactId
version2.2.2/version
configuration
  descriptorRefs
descriptorRefjar-with-dependencies/descriptorRef
  /descriptorRefs
   archive
manifest
  mainClasscom.yourcompany.defpackage/mainClass
/manifest
  /archive
/configuration
executions
  execution
idmake-assembly/id !-- this is used for inheritance
merges --
phasepackage/phase !-- bind to the packaging phase --

goals
  goalsingle/goal
/goals
  /execution
/executions
  /plugin

/plugins
  /build
  repositories
repository
  idcentral/id
  urlhttp://repo1.maven.org/maven2/url
/repository
repository
  idclojure-releases/id
  urlhttp://build.clojure.org/releases/url
/repository
repository
  idincanter/id
  urlhttp://repo.incanter.org/url
/repository
repository
  idclojure-snapshots/id
  urlhttp://build.clojure.org/snapshots/url
/repository
repository
  idclojars/id
  urlhttp://clojars.org/repo//url
/repository
  /repositories
  dependencies
  dependency
groupIdorg.clojure/groupId
artifactIdclojure/artifactId
version${clojure.version}/version
  /dependency
  dependency
groupIdorg.clojure/groupId
artifactIdclojure-contrib/artifactId
version${clojure.version}/version
  /dependency
dependency
  groupIdswank-clojure/groupId
  artifactIdswank-clojure/artifactId
  version1.2.1/version
exclusions
  exclusion
groupIdorg.clojure/groupId
artifactIdclojure/artifactId
  /exclusion
  exclusion
groupIdorg.clojure/groupId
artifactIdclojure-contrib/artifactId
  /exclusion
/exclusions
/dependency
  /dependencies
/project

-

Many thanks to 

Re: Building Clojure applications w/ Maven

2011-12-07 Thread Riccardo
Oh sorry it is fine now: it's just because there is no output to print
with the last script print(code sample) , after deleting it, the
jar is working fine.
Thanks again.

If somebody else will need more information, the steps to compile this
project were:

Easy AOT Compile with NetbeansMaven

1- Install Maven and Enclojure (in my case)

2- Create a new clojure project

3- In sources create a new clojure file like the above, putting
(ns com.yourcompany.defpackage(:gen-class)) ... at the beginning of
the clj file.

4- Add Assembly Plugin in the POM file specifying the package of the
main clojure file, something like this:
...
plugin
artifactIdmaven-assembly-plugin/artifactId
version2.2.2/version
configuration
  descriptorRefs
descriptorRefjar-with-dependencies/descriptorRef
  /descriptorRefs
   archive
manifest
  mainClasscom.yourcompany.defpackage/mainClass
/manifest
  /archive
/configuration
executions
  execution
idmake-assembly/id !-- this is used for inheritance
merges --
phasepackage/phase !-- bind to the packaging phase --

goals
  goalsingle/goal
/goals
  /execution
/executions
  /plugin
...

5- Build the project (with Netbeans just right click on the project)

6- Done



On Dec 8, 12:42 am, Riccardo riccardo.novie...@gmail.com wrote:
 Right I am finally getting closer: the generated jar finally works,
 but it still gives a message A java exception has occurred

 My code (not really mine...) look like this:
 -
 (ns com.yourcompany.defpackage
         (:gen-class))

 (import '(javax.swing JFrame JButton JOptionPane)) ;'
 (import '(java.awt.event ActionListener))          ;'

 (let [frame (JFrame. Hello Swing)
      button (JButton. Click Me)]
  (.addActionListener button
    (proxy [ActionListener] []
      (actionPerformed [evt]
        (JOptionPane/showMessageDialog  nil,
           (str htmlHello from bClojure/b. Button 
                (.getActionCommand evt)  clicked.)

  (.. frame getContentPane (add button))

  (doto frame
    (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
    .pack
    (.setVisible true)))

 print(code sample)

 -

 The POM file is this:

 ---
 ?xml version=1.0 encoding=UTF-8?
 project xmlns=http://maven.apache.org/POM/4.0.0; 
 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
   
 xsi:schemaLocation=http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd;
 properties
         clojure.version1.2.0/clojure.version
 /properties
   modelVersion4.0.0/modelVersion
   groupIdorg.enclojure/groupId
   artifactIdsample/artifactId
   version0.0.1/version
   nameBanking_Clojure/name
   descriptionBanking_Clojure/description
   build
      sourceDirectorysrc/main/clojure/sourceDirectory
      testSourceDirectorysrc/test/clojure/testSourceDirectory
         resources
             resource
                 directorysrc/main/clojure/directory
             /resource
             resource
                 directorysrc/main/resources/directory
             /resource
         /resources
         testResources
             testResource
                 directorysrc/test/clojure/directory
             /testResource
         /testResources
     plugins
       plugin
         groupIdcom.theoryinpractise/groupId
         artifactIdclojure-maven-plugin/artifactId
         version1.3.2/version
         configuration
             sourceDirectories
                 sourceDirectorysrc/main/clojure/sourceDirectory
             /sourceDirectories
             clojureOptions-Xmx1G/clojureOptions
         /configuration
         executions
           execution
             idcompile-clojure/id
             phasecompile/phase
             goals
               goalcompile/goal
             /goals
           /execution
         /executions
       /plugin
       plugin
         groupIdorg.apache.maven.plugins/groupId
         artifactIdmaven-compiler-plugin/artifactId
         configuration
           source1.6/source
           target1.6/target
         /configuration
       /plugin

        plugin
         artifactIdmaven-assembly-plugin/artifactId
         version2.2.2/version
         configuration
           descriptorRefs
             descriptorRefjar-with-dependencies/descriptorRef
           /descriptorRefs
            archive
             manifest
               mainClasscom.yourcompany.defpackage/mainClass
             /manifest
           /archive
         /configuration
         executions
           execution
             idmake-assembly/id !-- this is used for inheritance
 

Re: Dynamically Loading Jar Strategy

2011-12-07 Thread Brent Millare
To better understand what's going underneath, you're just calling the 
addURL method of the classloader. But since you might be evaluating this at 
the repl, there is an important point regarding the classloader. Everytime 
clojure evaluates a form, it will use a new classloader on that form, and 
the parent will be the classloader of the caller of the eval. So this means 
if you evaluate two forms consecutively, the first being the addURL, and 
the second, the command depending on the jar, the second will fail (unless 
you wrap both commands in a let). You need to ensure that the parent of the 
current classloader in the call to addURL is set. This way, all future 
evals will delegate to the classloader that knows about the jar.

So in summary, the heart of the command should just be:

(.addURL (.getContextClassLoader (Thread/currentThread)) (.toURL (.toURI 
file)))

For runtime dependency management, pomegranate does this, and so does my 
library, dj https://github.com/bmillare/dj

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

Macro to ease multiple-key sorting

2011-12-07 Thread Andy Fingerhut
I've been going through the PLEAC web site, writing Clojure examples
corresponding to the Perl code examples from the Perl Cookbook:

http://pleac.sourceforge.net

Michael Bacarella started a github repo to collect these together, and I'm
helping flesh some of them out.

https://github.com/mbacarella/pleac-clojure

One thing that is very convenient in Perl is doing sorts on multiple
comparison keys -- since 0 is treated as logically false in Perl, they can
simply do what in Clojure would look like:

(sort #(or (compare (key1 %1) (key2 %2))
(compare (key2 %1) (key2 %2))
...)
 collection)

This doesn't work in Clojure, because it only treats nil or false as
logically false.  It is easy to write a short-circuiting macro 'multicmp'
that does the correct thing:

(defmacro multicmp
  ([x] x)
  ([x  next]
 `(let [cmp# ~x]
(if (not= cmp# 0)
  cmp#
  (multicmp ~@next)

Then just replace 'or' in the first code snippet with 'multicmp'.

Does something like this already exist in a library I'm unaware of?  Would
others find it useful to have around?  And any suggestions on where it best
belongs if so?

Thanks,
Andy

-- 
You 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: clojurescript on windows (how create goog.jar)...Noob question

2011-12-07 Thread bjconlan
Yes, I imagine that bootstrapping on windows isn't the funnest
process. Life might become easier if you installed the windows
services for unix or cygwin/msys or the like and call the script/
bootstrap file.

but just to clarify the structure of the lib folder should be as
follows (if following the
bootstrap script)
lib\clojure-x.x.x.jar
lib\closure-compiler-r.jar
lib\rhino-rx.x.jar
lib\goog.jar (this is what you created with the `jar -cf goog.jar
closure-library/goog` command.

If you're unfamiliar with the bootstrap script (found in the scripts
directory) which i'm assuming that you are using as a reference. It
can be (on *nix environments to perform the tasks which you are having
a problem with.

Now as an alternative (and I by no means endorse using this unless you
just want to test - but in saying that it has not been testing on
windows yet...) you can checkout a fork I've made of clojurescript -
It's really just the master branch from about a week ago - I'm yet to
re-merge the latest changes, but it has the merged prop-access branch
and some minor refactoring to make use of lein to resolve any deps it
can (it also includes some manually built assets such as the goog.jar
you require which are not contributed to maven) it's found @
https://github.com/bjconlan/clojurescript.

If you have leiningen installed you can just call `lein deps` and it
will populate the `lib` folder with the required libraries then just
copy them into master branch you have checked out from clojure/
clojurescript.

I hope this helps? Although I might have overlooked your question...
perhaps looking at the tools jar documentation (http://docs.oracle.com/
javase/1.4.2/docs/tooldocs/windows/jar.html) might help a little more
in that regard.

On Dec 7, 11:13 am, ron clag...@gmail.com wrote:
 hi everybody...I'm trying install clojurescript on windows...I'm
 follow the steps but I'm not sure with this specific step:

     Create a goog.jar file and copy to lib

 cd closure\library\closure
 jar cf goog.jar goog
 copy goog.jar ..\..\..\lib

 now..I've downloaded clojure, closure and the closure compiler...and
 in any folder I've a path like closure\library
 \closure...actually..I'vent any .jar except the compiler.jar inside
 the compiler-latestfor create this file I think I must be inside a
 folder with some .jar...where is this folder?...

 I don't know but I feel than these steps are very mechanics and maybe
 a script than download all packages or something like this would be
 usefull for noobs users.

 thanks so much

-- 
You 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: Macro to ease multiple-key sorting

2011-12-07 Thread Alan Malloy
This should be a function, not a macro. In fact it is just:

(defn multicmp [ xs] (first (remove zero? xs)))

But what you really wanted to begin with is a comparator function, so
more like:

(defn multicmp [ keys]
  (fn [a b]
(or (first (remove zero? (map #(compare (% a) (% b))
  keys)))
0)))

(sort-by (multicmp  =) coll)

On Dec 7, 5:51 pm, Andy Fingerhut andy.finger...@gmail.com wrote:
 I've been going through the PLEAC web site, writing Clojure examples
 corresponding to the Perl code examples from the Perl Cookbook:

 http://pleac.sourceforge.net

 Michael Bacarella started a github repo to collect these together, and I'm
 helping flesh some of them out.

 https://github.com/mbacarella/pleac-clojure

 One thing that is very convenient in Perl is doing sorts on multiple
 comparison keys -- since 0 is treated as logically false in Perl, they can
 simply do what in Clojure would look like:

 (sort #(or (compare (key1 %1) (key2 %2))
                 (compare (key2 %1) (key2 %2))
                 ...)
          collection)

 This doesn't work in Clojure, because it only treats nil or false as
 logically false.  It is easy to write a short-circuiting macro 'multicmp'
 that does the correct thing:

 (defmacro multicmp
   ([x] x)
   ([x  next]
      `(let [cmp# ~x]
         (if (not= cmp# 0)
           cmp#
           (multicmp ~@next)

 Then just replace 'or' in the first code snippet with 'multicmp'.

 Does something like this already exist in a library I'm unaware of?  Would
 others find it useful to have around?  And any suggestions on where it best
 belongs if so?

 Thanks,
 Andy

-- 
You 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: Macro to ease multiple-key sorting

2011-12-07 Thread Andy Fingerhut
The intent of making it a macro is that it allows short-circuit evaluation,
like Clojure's or/and.  There is no reason to evaluate comparisons between
keys when an earlier comparison has already decided the ordering.

Hardwiring in the compare function and the order between %1 and %2 is an
interesting idea I hadn't considered, partly because it is often the case
that one would like an ascending sort order on one key, but descending on
others, which is commonly done by swapping %1 and %2's position, but could
also be done by negating the return value of compare.

Andy

On Wed, Dec 7, 2011 at 6:59 PM, Alan Malloy a...@malloys.org wrote:

 This should be a function, not a macro. In fact it is just:

 (defn multicmp [ xs] (first (remove zero? xs)))

 But what you really wanted to begin with is a comparator function, so
 more like:

 (defn multicmp [ keys]
  (fn [a b]
(or (first (remove zero? (map #(compare (% a) (% b))
  keys)))
0)))

 (sort-by (multicmp  =) coll)

 On Dec 7, 5:51 pm, Andy Fingerhut andy.finger...@gmail.com wrote:
  I've been going through the PLEAC web site, writing Clojure examples
  corresponding to the Perl code examples from the Perl Cookbook:
 
  http://pleac.sourceforge.net
 
  Michael Bacarella started a github repo to collect these together, and
 I'm
  helping flesh some of them out.
 
  https://github.com/mbacarella/pleac-clojure
 
  One thing that is very convenient in Perl is doing sorts on multiple
  comparison keys -- since 0 is treated as logically false in Perl, they
 can
  simply do what in Clojure would look like:
 
  (sort #(or (compare (key1 %1) (key2 %2))
  (compare (key2 %1) (key2 %2))
  ...)
   collection)
 
  This doesn't work in Clojure, because it only treats nil or false as
  logically false.  It is easy to write a short-circuiting macro 'multicmp'
  that does the correct thing:
 
  (defmacro multicmp
([x] x)
([x  next]
   `(let [cmp# ~x]
  (if (not= cmp# 0)
cmp#
(multicmp ~@next)
 
  Then just replace 'or' in the first code snippet with 'multicmp'.
 
  Does something like this already exist in a library I'm unaware of?
  Would
  others find it useful to have around?  And any suggestions on where it
 best
  belongs if so?
 
  Thanks,
  Andy

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

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

Re: thank you, clojure hackers

2011-12-07 Thread Craig Brozefsky
Ambrose Bonnaire-Sergeant abonnaireserge...@gmail.com writes:

 What are you making?

Malware behavior analysis tool.  I'll be able to release most of the
non-malware specific portions once this gets out of the proof of concept
phase.

-- 
Craig Brozefsky cr...@red-bean.com
Premature reification is the root of all evil

-- 
You 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: Macro to ease multiple-key sorting

2011-12-07 Thread Andy Fingerhut
Ugh.  And if I were slightly lazier at pressing the send button, I would
have realized that the laziness of map and remove gives this short-circuit
evaluation.

I generalized your example to allow the notation [- keyfn] as an argument
to specify descending order on that key, instead of ascending order.  It
doesn't check its arguments carefully, but if you give it correct
arguments, it works :-)

(defn multicmp [ keys]
  (fn [a b]
(or (first (remove zero? (map #(if (vector? %)
 (let [[order keyfn] %]
   (if (= order -)
 (compare (keyfn b) (keyfn a))
 (compare (keyfn a) (keyfn b
 (compare (% a) (% b)))
  keys)))
0)))

Example, with implicit ascending order for :name, but explicit ascending
order for :salary:

(pprint (sort (multicmp :name [- :age] [+ :salary]) employees))

Thanks,
Andy

On Wed, Dec 7, 2011 at 7:23 PM, Andy Fingerhut andy.finger...@gmail.comwrote:

 The intent of making it a macro is that it allows short-circuit
 evaluation, like Clojure's or/and.  There is no reason to evaluate
 comparisons between keys when an earlier comparison has already decided the
 ordering.

 Hardwiring in the compare function and the order between %1 and %2 is an
 interesting idea I hadn't considered, partly because it is often the case
 that one would like an ascending sort order on one key, but descending on
 others, which is commonly done by swapping %1 and %2's position, but could
 also be done by negating the return value of compare.

 Andy


 On Wed, Dec 7, 2011 at 6:59 PM, Alan Malloy a...@malloys.org wrote:

 This should be a function, not a macro. In fact it is just:

 (defn multicmp [ xs] (first (remove zero? xs)))

 But what you really wanted to begin with is a comparator function, so
 more like:

 (defn multicmp [ keys]
  (fn [a b]
(or (first (remove zero? (map #(compare (% a) (% b))
  keys)))
0)))

 (sort-by (multicmp  =) coll)

 On Dec 7, 5:51 pm, Andy Fingerhut andy.finger...@gmail.com wrote:
  I've been going through the PLEAC web site, writing Clojure examples
  corresponding to the Perl code examples from the Perl Cookbook:
 
  http://pleac.sourceforge.net
 
  Michael Bacarella started a github repo to collect these together, and
 I'm
  helping flesh some of them out.
 
  https://github.com/mbacarella/pleac-clojure
 
  One thing that is very convenient in Perl is doing sorts on multiple
  comparison keys -- since 0 is treated as logically false in Perl, they
 can
  simply do what in Clojure would look like:
 
  (sort #(or (compare (key1 %1) (key2 %2))
  (compare (key2 %1) (key2 %2))
  ...)
   collection)
 
  This doesn't work in Clojure, because it only treats nil or false as
  logically false.  It is easy to write a short-circuiting macro
 'multicmp'
  that does the correct thing:
 
  (defmacro multicmp
([x] x)
([x  next]
   `(let [cmp# ~x]
  (if (not= cmp# 0)
cmp#
(multicmp ~@next)
 
  Then just replace 'or' in the first code snippet with 'multicmp'.
 
  Does something like this already exist in a library I'm unaware of?
  Would
  others find it useful to have around?  And any suggestions on where it
 best
  belongs if so?
 
  Thanks,
  Andy

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




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

Re: Macro to ease multiple-key sorting

2011-12-07 Thread Alan Malloy
On Dec 7, 8:12 pm, Andy Fingerhut andy.finger...@gmail.com wrote:
 Ugh.  And if I were slightly lazier at pressing the send button, I would
 have realized that the laziness of map and remove gives this short-circuit
 evaluation.

 I generalized your example to allow the notation [- keyfn] as an argument
 to specify descending order on that key, instead of ascending order.  It
 doesn't check its arguments carefully, but if you give it correct
 arguments, it works :-)

Just use comp: (sort-by (multicmp f (comp - g)) coll)

-- 
You 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: Macro to ease multiple-key sorting

2011-12-07 Thread Andy Fingerhut
On Wed, Dec 7, 2011 at 8:29 PM, Alan Malloy a...@malloys.org wrote:

 On Dec 7, 8:12 pm, Andy Fingerhut andy.finger...@gmail.com wrote:
  Ugh.  And if I were slightly lazier at pressing the send button, I would
  have realized that the laziness of map and remove gives this
 short-circuit
  evaluation.
 
  I generalized your example to allow the notation [- keyfn] as an argument
  to specify descending order on that key, instead of ascending order.  It
  doesn't check its arguments carefully, but if you give it correct
  arguments, it works :-)

 Just use comp: (sort-by (multicmp f (comp - g)) coll)


I don't see how to make that work if the value extracted by function g is
something besides a number, e.g. a string.  Do you see a way?

Thanks,
Andy

-- 
You 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: Macro to ease multiple-key sorting

2011-12-07 Thread Alan Malloy
On Dec 7, 9:23 pm, Andy Fingerhut andy.finger...@gmail.com wrote:
 On Wed, Dec 7, 2011 at 8:29 PM, Alan Malloy a...@malloys.org wrote:
  On Dec 7, 8:12 pm, Andy Fingerhut andy.finger...@gmail.com wrote:
   Ugh.  And if I were slightly lazier at pressing the send button, I would
   have realized that the laziness of map and remove gives this
  short-circuit
   evaluation.

   I generalized your example to allow the notation [- keyfn] as an argument
   to specify descending order on that key, instead of ascending order.  It
   doesn't check its arguments carefully, but if you give it correct
   arguments, it works :-)

  Just use comp: (sort-by (multicmp f (comp - g)) coll)

 I don't see how to make that work if the value extracted by function g is
 something besides a number, e.g. a string.  Do you see a way?

No, you're right. I was thinking you were working with Comparator-type
two-arg functions already, in which case this works, but obviously
that's not the case.

-- 
You 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: Quartz and Clojure

2011-12-07 Thread Lars Rune Nøstdal
You've probably found this by now, but there's: 
https://github.com/mdpendergrass/quartz-clj

-- 
You 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-def a non-dynamic var to a ^:dynamic var make a mistake

2011-12-07 Thread zhi zhu
Hi,everyone!
  I'm a newbie here.When I'm reading Mark Volkmann's Tutorial,i make a
mistake by binding a non-dynamic var 'x' to new value.Then I def 'x'
with ^:dynamic again,but in this line (binding [x 9] (foo)), the
function 'foo' ignore the binding.Why?
  Thanks for reply!!!

uer= (def x 0)
#'user/x

user= (defn foo [] (println x))
#'user/foo

user= (foo)
0
nil

user= (def ^:dynamic x 1)
#'user/x

user= (foo)
1
nil

user= (binding [x 9] (println x))
9
nil

user= (binding [x 9] (foo))
1
nil

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


Re: re-def a non-dynamic var to a ^:dynamic var make a mistake

2011-12-07 Thread Meikel Brandmeyer (kotarak)
Hi,

just a guess: ^:dynmamic is a compile-time thing. foo was compiled without 
it in place, so the compiler didn't consider it. Recompile foo after the 
re-def with  ^:dynamic and it should honor the setting.

Sincerely
Meikel

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