Hi Lasanatha,

Having looked at Clojure code, I feel Clojure is too far away from java for
this usecase. (it is like LISP).

--Srinath

On Fri, Nov 28, 2014 at 5:15 PM, Lasantha Fernando <[email protected]>
wrote:

> Hi Srinath,
>
> Sorry for the late response. Clojure code gets eventually compiled into
> java byte code. So it can be run from Java.
>
> Performance-wise running clojure directly is quite slow. Actually the
> startup time of clojure is slow [1]. However, we can use gen-class or proxy
> keywords of clojure to say a clojure namespace should generate a java class
> directly. I think we should be able to use *load* or *compile* functions
> of clojure to compile it beforehand and simply do a java call on that class.
>
> For an extension that does exponentiation, the pure clojure syntax would
> be something similar to below for a function that returns power for two
> parameters.
>
> (defn exp [x n]
>   (reduce * (repeat n x)))
>
> If we write a function executor making use of the current extension points
> of Siddhi and java.lang.Math.pow(), it will be something like below.
>
> (ns org.wso2.siddhi.math
>   (:import '(org.wso2.siddhi.core.function FunctionExecutor))
>   (:use [clojure])
>   (:gen-class
>     :name org.wso2.siddhi.math.PowerFunction
>     :extends [org.wso2.siddhi.core.function.FunctionExecutor]))
>
> (defn -processEvent [this params (Object.)]
>   (. Math pow (aget params 0) (aget params 1)))
>
> The siddhi query would be something like below.
>
> from healthStatStream#window.lenght(1) join avgLoadTable
> on healthStatStream.nodeId == avgLoadTable.nodeId
> select healthStatStream.nodeId, custom.power(healthStatStream.load -
> avgLoadTable.load , 2) as variance
> insert into loadVarianceStream;
>
> Since clojure is interoperable with Java  [2] (which is same for Scala I
> think), we can directly use Java classes in clojure and vice versa. Clojure
> syntax is more towards functional/Lisp like syntax more than Scala IMHO. So
> if we are looking at providing extensions that are geared a bit more
> towards object oriented style, +1 to use Scala instead of Clojure. Though
> clojure does have a certain techy appeal because it is more of a functional
> programming language... :-)
>
> [1]
> http://nicholaskariniemi.github.io/2014/02/25/clojure-bootstrapping.html
> [2]
> https://github.com/clojuredocs/guides/blob/master/articles/language/interop.md
>
> Thanks,
> Lasantha
>
> On 26 November 2014 at 11:11, Srinath Perera <[email protected]> wrote:
>
>> Can we run Clojure from Java? How fast would that be? Can we give a
>> example on how it will look like?
>>
>> I was chatting with Sanjiva, and he proposed java scripts. However, until
>> we switch to Java 8, it is slow. Need to discuss that.
>>
>> --Srinath
>>
>> On Mon, Nov 24, 2014 at 1:20 PM, Lasantha Fernando <[email protected]>
>> wrote:
>>
>>> Can we use Clojure for this? Clojure can be used as a dynamic language
>>> as well [1,2]. I think we should be able to use the load-file [3] function
>>> or load/load-script [4,5].
>>>
>>> Since clojure has a strong affinity to Storm, someone coming in from
>>> Storm background will be more used to Clojure IMHO. Clojure also supports
>>> lambda expressions. (It is also mostly a functional programming language
>>> :-))
>>>
>>> [1]
>>> http://nicholaskariniemi.github.io/2014/01/26/clojure-compilation.html
>>> [2]
>>> http://nicholaskariniemi.github.io/2014/02/06/clojure-compilation2.html
>>> [3] https://clojuredocs.org/clojure.core/load-file
>>> [4] https://clojuredocs.org/clojure.core/load
>>> [5] https://clojuredocs.org/clojure.main/load-script
>>>
>>> Thanks,
>>> Lasantha
>>>
>>> On 22 November 2014 at 09:15, Srinath Perera <[email protected]> wrote:
>>>
>>>> Would that needs tools.jar in the classpath?
>>>>
>>>> One advantage of scala are lamba function (e.g. see Sameera's slides on
>>>> java 8) .. but disadvantage is you need to learn scala a bit.
>>>>
>>>> --Srinath
>>>>
>>>> On Fri, Nov 21, 2014 at 4:43 PM, Rajeev Sampath <[email protected]>
>>>> wrote:
>>>>
>>>>>
>>>>> On Fri, Nov 21, 2014 at 10:40 AM, Srinath Perera <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Useful to have in competition with Storm. Performance is the concern.
>>>>>>
>>>>>> One ida is to get extensions as scala function and running is using
>>>>>> https://code.google.com/p/scalascriptengine/
>>>>>>
>>>>>>
>>>>> This will be a very useful feature to have.
>>>>>
>>>>> Also another option is to let users embed plain java code inline, and
>>>>> then convert it to bytecode at the query initialization time with a
>>>>> bytecode generator like Javassist.
>>>>> http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/
>>>>>
>>>>>
>>>>> Thanks
>>>>> Rajeev
>>>>>
>>>>>
>>>>>> WDYT?
>>>>>>
>>>>>> --Srinath
>>>>>>
>>>>>> --
>>>>>> ============================
>>>>>> Blog: http://srinathsview.blogspot.com twitter:@srinath_perera
>>>>>> Site: http://people.apache.org/~hemapani/
>>>>>> Photos: http://www.flickr.com/photos/hemapani/
>>>>>> Phone: 0772360902
>>>>>>
>>>>>> _______________________________________________
>>>>>> Architecture mailing list
>>>>>> [email protected]
>>>>>> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Rajeev Sampath
>>>>> Senior Software Engineer
>>>>> WSO2, Inc.; http://www.wso2.com.
>>>>>
>>>>> Mobile:
>>>>> * +94716265766 <%2B94716265766>*
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> ============================
>>>> Srinath Perera, Ph.D.
>>>>    http://people.apache.org/~hemapani/
>>>>    http://srinathsview.blogspot.com/
>>>>
>>>> _______________________________________________
>>>> Architecture mailing list
>>>> [email protected]
>>>> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>>>>
>>>>
>>>
>>>
>>> --
>>> *Lasantha Fernando*
>>> Software Engineer - Data Technologies Team
>>> WSO2 Inc. http://wso2.com
>>>
>>> email: [email protected]
>>> mobile: (+94) 71 5247551
>>>
>>> _______________________________________________
>>> Architecture mailing list
>>> [email protected]
>>> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>>>
>>>
>>
>>
>> --
>> ============================
>> Blog: http://srinathsview.blogspot.com twitter:@srinath_perera
>> Site: http://people.apache.org/~hemapani/
>> Photos: http://www.flickr.com/photos/hemapani/
>> Phone: 0772360902
>>
>> _______________________________________________
>> Architecture mailing list
>> [email protected]
>> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>>
>>
>
>
> --
> *Lasantha Fernando*
> Software Engineer - Data Technologies Team
> WSO2 Inc. http://wso2.com
>
> email: [email protected]
> mobile: (+94) 71 5247551
>



-- 
============================
Blog: http://srinathsview.blogspot.com twitter:@srinath_perera
Site: http://people.apache.org/~hemapani/
Photos: http://www.flickr.com/photos/hemapani/
Phone: 0772360902
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture

Reply via email to