Applying collection of functions

2011-04-07 Thread zm

Hi,

Given a collection of functions

(def fs [#(* % 10) #(+ % 1)])

and some numbers

(def c [1 2 3])

How do I apply all the functions to c so that the results of one
function are passed to the other. In the same way - works. Thus in
this case the expected result would be: 11 21 31

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


Re: NullPointerExecption after Java class import

2010-08-30 Thread zm

Indeed if exception is thrown in static initializer block then clojure
import throws exception as well.

The following class will cause this:

package aaa;
public class Test {
static{
Object o = null;
o.toString();
}
}

Then in clojure:

(ns x (:import (aaa Test))

Results in:

Exception in thread main java.lang.ExceptionInInitializerError
(core.clj:1)

Why does this happen in clojure? If you do the same in java, import
aaa.Test, then nothing happens. NLP will be thrown when you actualy
try to initialize the class.


On Aug 30, 6:12 am, Stuart Campbell stu...@harto.org wrote:
 Hello,

 I don't know this library specifically, but the NPE is probably occurring in
 a static initialisation block. I believe static initialisation occurs when
 the class is first loaded.

 Regards,
 Stuart

 On 30 August 2010 06:42, zm zygiman...@medelis.lt wrote:





  I am using GATE java libs in my clojure code and behaviour of the
  application changes after Java class import. I don't even have to
  initialize it.

  This runs fine (a bit shorter version than it is):

   (ns gate
   (:import
      (gate Gate)
      (java.io File)))

  (defn gate-init
   [gate-home]
   (Gate/setGateHome (File. gate-home))
   (Gate/init)))

  Now if I import gate.Factory class, like this (gate Gate Factory), I
  get the exception:

  Caused by: java.lang.NullPointerException
         at gate.Factory.createResource(Factory.java:154)

  How can import of a class cause this?

  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@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: NullPointerExecption after Java class import

2010-08-30 Thread zm

Initialization exception can be avoided if Factory class is
initialized indirectly:

(let [factory (.newInstance (Class/forName gate.Factory))] ...)

The problem is that Factory can only be initialized (its static
fields) after Gate.init was called. But clojure reader (or what it is)
initializes all the classes mentioned in the namespace. Thus Factory
gets created before cojure function calls which do Gate/init.

Is this workaround ok? Or are there better ways to solve it?

On Aug 30, 2:39 pm, zm zygiman...@medelis.lt wrote:
 Indeed if exception is thrown in static initializer block then clojure
 import throws exception as well.

 The following class will cause this:

 package aaa;
 public class Test {
         static{
                 Object o = null;
                 o.toString();
         }

 }

 Then in clojure:

 (ns x (:import (aaa Test))

 Results in:

 Exception in thread main java.lang.ExceptionInInitializerError
 (core.clj:1)

 Why does this happen in clojure? If you do the same in java, import
 aaa.Test, then nothing happens. NLP will be thrown when you actualy
 try to initialize the class.

 On Aug 30, 6:12 am, Stuart Campbell stu...@harto.org wrote:



  Hello,

  I don't know this library specifically, but the NPE is probably occurring in
  a static initialisation block. I believe static initialisation occurs when
  the class is first loaded.

  Regards,
  Stuart

  On 30 August 2010 06:42, zm zygiman...@medelis.lt wrote:

   I am using GATE java libs in my clojure code and behaviour of the
   application changes after Java class import. I don't even have to
   initialize it.

   This runs fine (a bit shorter version than it is):

    (ns gate
    (:import
       (gate Gate)
       (java.io File)))

   (defn gate-init
    [gate-home]
    (Gate/setGateHome (File. gate-home))
    (Gate/init)))

   Now if I import gate.Factory class, like this (gate Gate Factory), I
   get the exception:

   Caused by: java.lang.NullPointerException
          at gate.Factory.createResource(Factory.java:154)

   How can import of a class cause this?

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


NullPointerExecption after Java class import

2010-08-29 Thread zm

I am using GATE java libs in my clojure code and behaviour of the
application changes after Java class import. I don't even have to
initialize it.

This runs fine (a bit shorter version than it is):

 (ns gate
  (:import
 (gate Gate)
 (java.io File)))

(defn gate-init
  [gate-home]
  (Gate/setGateHome (File. gate-home))
  (Gate/init)))

Now if I import gate.Factory class, like this (gate Gate Factory), I
get the exception:

Caused by: java.lang.NullPointerException
at gate.Factory.createResource(Factory.java:154)

How can import of a class cause this?

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