Re: Calling Native C-code from Clojure

2020-12-05 Thread John Doe

Cool! Thanks again Chris.
On Saturday, December 5, 2020 at 4:09:39 PM UTC+1 ch...@techascent.com 
wrote:

> You are most welcome :-).  For numerical computation, libjulia-clj 
>  may interest you :-).
>
> On Sat, Dec 5, 2020 at 8:06 AM John Doe  wrote:
>
>> Thank you Chris. It's very helpful.
>>
>> The approach you took for dtype-next is very interesting. This library is 
>> closer to my work (numerical computation). Also, the efficient use of Java 
>> heap is very interesting although I admit I don't know enough about it. 
>> This reminds me of Rich Hickey's emphasis of understanding data structures.
>>
>> On Friday, December 4, 2020 at 4:52:25 PM UTC+1 ch...@techascent.com 
>> wrote:
>>
>>> Ngwua,
>>>
>>> Looking through the caesium bindings just mentioned, it appears the 
>>> author dynamically creates an interface and then you can simply ask the 
>>> native library to instantiate a concrete implementation of that 
>>> interface 
>>> .  
>>> So you do not always have to create a class with 'native' methods.
>>>
>>> Integrating with C libraries is part of the reason I wrote dtype-next 
>>>  which has the ability to 
>>> efficiently write/read from either java heap or native heap storage.  
>>> dtype-next has no dependency on either JNA or JNR.
>>>
>>> Hope this helps,
>>>
>>> Chris 
>>>
>>> On Fri, Dec 4, 2020 at 7:53 AM John Doe  wrote:
>>>
 Hello Everyone,

 *Motivation:* I want to invoke C-code functions from Clojure: writing 
 Java functions in Clojure.

 *Plan of Attack:* Rather than go with the JNI approach I want to 
 interface with C-Library via JNR-FFI (https://github.com/jnr/jnr-ffi)

 Based on some example of using JNR-FFI

 https://github.com/jnr/jnr-ffi-examples/blob/master/getpid/src/main/java/getpid/Getpid.java


 https://www.programcreek.com/java-api-examples/?api=jnr.ffi.LibraryLoader

 The wrapper in Java might look like
 ```
 package blahblah;

 public class BlahNative {
 private static int[] intDummy;
 private static double[] doubleDummy;

 public BlahNative() {
 }

 public static native void native_a(char var0, char var1, int var2, int 
 var3, int var4, double[] var7, int var8, int var9);

 static {
 lib = LibraryLoader
 .create(LibSodium.class)
 .search("/usr/local/lib")
 .search("/opt/local/lib")
 .search("/usr/lib")
 .search("/lib")
 .load(LIBRARY_NAME);
 initializeLibrary(lib);
 }
 }
 ```

 Question: For my package
 ```
 (defproject mypkg
 :dependencies [[org.clojure/clojure "1.10.1"]
[com.github.jnr/jnr-ffi "2.2.0"]])
 ```
 How do I write the wrapper for the native functions in
 ```
 (ns mypkg.native
 (:import [jnr.ffi LibraryLoader])
 (:import [jnr.ffi.annotations IgnoreError])
 (:import [jnr.ffi.provider FFIProvider]))
 ```
 For the Java interop I am assuming the above namespace should be based 
 on gen-class (http://clojure-doc.org/articles/language/interop.html).

 What is not clear to me is:
 *1. How does one create the `native` method* (since most (defn foo) 
 are static methods)?
 *2. How do I access the native functions after loading* the Native 
 Library (LibraryLoader.load(LIBRARY_NAME))?

 I am neither a C nor a Java expert so any guidance will be much 
 appreciated.

 Thanks,
 Ngwua

 -- 

>>> You received this message because you are subscribed to the Google
 Groups "Clojure" group.
 To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send 
 an email to clojure+u...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/clojure/3bd05d7a-297e-49cf-86d4-aec4a88c83cbn%40googlegroups.com
  
 
 .

>>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from 

Re: State of Clojure/CLR: (was: Scicloj meeting: Nikita Propokov about Skija - graphics in the JVM)

2020-12-05 Thread Daniel Slutsky
The time for the Skija meetup has changed:
https://time.is/1400_16_Dec_2020_in_UTC/

The RSVP link stays the same:
https://tinyurl.com/yyb6zhmd

On Friday, 20 November 2020 at 17:49:00 UTC+2 dmiller wrote:

> Reports of the death of ClojureCLR are greatly exaggerated.
>
> The newframework branch in the repo has a completed 1.10 version running 
> on .Net Core 3.1 and 5. 
> Should be released 'soon'.
>
>
>
> On Wednesday, November 18, 2020 at 1:20:54 AM UTC-6 oleksand...@zalando.de 
> wrote:
>
>> On Tue, Nov 17, 2020 at 4:56 PM Daniel Slutsky  
>> wrote:
>>
>>> https://time.is/1400_08_Dec_2020_in_UTC/
>>>
>>> Tonsky has recently released Skija: a library for high-performance 
>>> graphics on the JVM.
>>> https://tonsky.me/blog/skija/
>>>
>>> Of course, this opens some possibilities in Clojure. In this talk, 
>>> Tonsky will present Skija to the Clojure audience.
>>>
>>
>> Nice, thanks for sharing!
>>
>> Can anyone (maybe the author himself) comment on this: C# would do, too, 
>> but it doesn’t have Clojure. 
>> I have never tried it myself, but what is the state of Clojure/CLR 
>> currently?
>>
>> Regards,
>> --
>> Alex
>>
>>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/688674fd-4cbf-4b06-9e2d-17f9182d7bf0n%40googlegroups.com.


Re: Calling Native C-code from Clojure

2020-12-05 Thread Chris Nuernberger
You are most welcome :-).  For numerical computation, libjulia-clj
 may interest you :-).

On Sat, Dec 5, 2020 at 8:06 AM John Doe  wrote:

> Thank you Chris. It's very helpful.
>
> The approach you took for dtype-next is very interesting. This library is
> closer to my work (numerical computation). Also, the efficient use of Java
> heap is very interesting although I admit I don't know enough about it.
> This reminds me of Rich Hickey's emphasis of understanding data structures.
>
> On Friday, December 4, 2020 at 4:52:25 PM UTC+1 ch...@techascent.com
> wrote:
>
>> Ngwua,
>>
>> Looking through the caesium bindings just mentioned, it appears the
>> author dynamically creates an interface and then you can simply ask the
>> native library to instantiate a concrete implementation of that interface
>> .
>> So you do not always have to create a class with 'native' methods.
>>
>> Integrating with C libraries is part of the reason I wrote dtype-next
>>  which has the ability to
>> efficiently write/read from either java heap or native heap storage.
>> dtype-next has no dependency on either JNA or JNR.
>>
>> Hope this helps,
>>
>> Chris
>>
>> On Fri, Dec 4, 2020 at 7:53 AM John Doe  wrote:
>>
>>> Hello Everyone,
>>>
>>> *Motivation:* I want to invoke C-code functions from Clojure: writing
>>> Java functions in Clojure.
>>>
>>> *Plan of Attack:* Rather than go with the JNI approach I want to
>>> interface with C-Library via JNR-FFI (https://github.com/jnr/jnr-ffi)
>>>
>>> Based on some example of using JNR-FFI
>>>
>>> https://github.com/jnr/jnr-ffi-examples/blob/master/getpid/src/main/java/getpid/Getpid.java
>>>
>>> https://www.programcreek.com/java-api-examples/?api=jnr.ffi.LibraryLoader
>>>
>>> The wrapper in Java might look like
>>> ```
>>> package blahblah;
>>>
>>> public class BlahNative {
>>> private static int[] intDummy;
>>> private static double[] doubleDummy;
>>>
>>> public BlahNative() {
>>> }
>>>
>>> public static native void native_a(char var0, char var1, int var2, int
>>> var3, int var4, double[] var7, int var8, int var9);
>>>
>>> static {
>>> lib = LibraryLoader
>>> .create(LibSodium.class)
>>> .search("/usr/local/lib")
>>> .search("/opt/local/lib")
>>> .search("/usr/lib")
>>> .search("/lib")
>>> .load(LIBRARY_NAME);
>>> initializeLibrary(lib);
>>> }
>>> }
>>> ```
>>>
>>> Question: For my package
>>> ```
>>> (defproject mypkg
>>> :dependencies [[org.clojure/clojure "1.10.1"]
>>>[com.github.jnr/jnr-ffi "2.2.0"]])
>>> ```
>>> How do I write the wrapper for the native functions in
>>> ```
>>> (ns mypkg.native
>>> (:import [jnr.ffi LibraryLoader])
>>> (:import [jnr.ffi.annotations IgnoreError])
>>> (:import [jnr.ffi.provider FFIProvider]))
>>> ```
>>> For the Java interop I am assuming the above namespace should be based
>>> on gen-class (http://clojure-doc.org/articles/language/interop.html).
>>>
>>> What is not clear to me is:
>>> *1. How does one create the `native` method* (since most (defn foo) are
>>> static methods)?
>>> *2. How do I access the native functions after loading* the Native
>>> Library (LibraryLoader.load(LIBRARY_NAME))?
>>>
>>> I am neither a C nor a Java expert so any guidance will be much
>>> appreciated.
>>>
>>> Thanks,
>>> Ngwua
>>>
>>> --
>>>
>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+u...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/clojure/3bd05d7a-297e-49cf-86d4-aec4a88c83cbn%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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 unsubscribe from this group 

Re: Calling Native C-code from Clojure

2020-12-05 Thread John Doe
Thank you Chris. It's very helpful.

The approach you took for dtype-next is very interesting. This library is 
closer to my work (numerical computation). Also, the efficient use of Java 
heap is very interesting although I admit I don't know enough about it. 
This reminds me of Rich Hickey's emphasis of understanding data structures.

On Friday, December 4, 2020 at 4:52:25 PM UTC+1 ch...@techascent.com wrote:

> Ngwua,
>
> Looking through the caesium bindings just mentioned, it appears the author 
> dynamically creates an interface and then you can simply ask the native 
> library to instantiate a concrete implementation of that interface 
> .  
> So you do not always have to create a class with 'native' methods.
>
> Integrating with C libraries is part of the reason I wrote dtype-next 
>  which has the ability to 
> efficiently write/read from either java heap or native heap storage.  
> dtype-next has no dependency on either JNA or JNR.
>
> Hope this helps,
>
> Chris 
>
> On Fri, Dec 4, 2020 at 7:53 AM John Doe  wrote:
>
>> Hello Everyone,
>>
>> *Motivation:* I want to invoke C-code functions from Clojure: writing 
>> Java functions in Clojure.
>>
>> *Plan of Attack:* Rather than go with the JNI approach I want to 
>> interface with C-Library via JNR-FFI (https://github.com/jnr/jnr-ffi)
>>
>> Based on some example of using JNR-FFI
>>
>> https://github.com/jnr/jnr-ffi-examples/blob/master/getpid/src/main/java/getpid/Getpid.java
>>
>> https://www.programcreek.com/java-api-examples/?api=jnr.ffi.LibraryLoader
>>
>> The wrapper in Java might look like
>> ```
>> package blahblah;
>>
>> public class BlahNative {
>> private static int[] intDummy;
>> private static double[] doubleDummy;
>>
>> public BlahNative() {
>> }
>>
>> public static native void native_a(char var0, char var1, int var2, int 
>> var3, int var4, double[] var7, int var8, int var9);
>>
>> static {
>> lib = LibraryLoader
>> .create(LibSodium.class)
>> .search("/usr/local/lib")
>> .search("/opt/local/lib")
>> .search("/usr/lib")
>> .search("/lib")
>> .load(LIBRARY_NAME);
>> initializeLibrary(lib);
>> }
>> }
>> ```
>>
>> Question: For my package
>> ```
>> (defproject mypkg
>> :dependencies [[org.clojure/clojure "1.10.1"]
>>[com.github.jnr/jnr-ffi "2.2.0"]])
>> ```
>> How do I write the wrapper for the native functions in
>> ```
>> (ns mypkg.native
>> (:import [jnr.ffi LibraryLoader])
>> (:import [jnr.ffi.annotations IgnoreError])
>> (:import [jnr.ffi.provider FFIProvider]))
>> ```
>> For the Java interop I am assuming the above namespace should be based on 
>> gen-class (http://clojure-doc.org/articles/language/interop.html).
>>
>> What is not clear to me is:
>> *1. How does one create the `native` method* (since most (defn foo) are 
>> static methods)?
>> *2. How do I access the native functions after loading* the Native 
>> Library (LibraryLoader.load(LIBRARY_NAME))?
>>
>> I am neither a C nor a Java expert so any guidance will be much 
>> appreciated.
>>
>> Thanks,
>> Ngwua
>>
>> -- 
>>
> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/clojure/3bd05d7a-297e-49cf-86d4-aec4a88c83cbn%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/acd1be6c-5156-4316-98e2-e4df9d55566bn%40googlegroups.com.


Re: Calling Native C-code from Clojure

2020-12-05 Thread John Doe
Thanks so much lvh.

Your Youtube presentation was one of the main reasons I chose JNI-FFI :-)

I did not consider looking into Caesium, let alone the source code: 
probably, because my current work does not involve cryptography. Thank you 
so much for the github link to the repo. Looking at the source code I found 
it very useful. It gave me all sorts of ideas to move forward :-)

On Friday, December 4, 2020 at 4:37:47 PM UTC+1 Laurens Van Houtven wrote:

> Hi,
>
> I did a talk on this and conveniently my library caesium wraps the library 
> you're referencing :)
>
> https://www.youtube.com/watch?v=Lf-M1ZH6KME
> https://github.com/lvh/caesium/
>
> I still think that approach is great particularly for libraries like 
> libsodium where some care was taken to make them easy to FFI. That is 
> typically less true for more complex, often C++, libraries. In that case I 
> would consider JavaCPP, where you basically do more up front work to tell 
> it how it works and it generates JNI for you (up front, not dynamically 
> like jnr). Which one I'd recommend depends on what you're binding. Like I 
> said, for libsodium I think jnr is probably easier to use.
>
> lvh
>
> On Fri, Dec 4, 2020 at 8:53 AM John Doe  wrote:
>
>> Hello Everyone,
>>
>> *Motivation:* I want to invoke C-code functions from Clojure: writing 
>> Java functions in Clojure.
>>
>> *Plan of Attack:* Rather than go with the JNI approach I want to 
>> interface with C-Library via JNR-FFI (https://github.com/jnr/jnr-ffi)
>>
>> Based on some example of using JNR-FFI
>>
>> https://github.com/jnr/jnr-ffi-examples/blob/master/getpid/src/main/java/getpid/Getpid.java
>>
>> https://www.programcreek.com/java-api-examples/?api=jnr.ffi.LibraryLoader
>>
>> The wrapper in Java might look like
>> ```
>> package blahblah;
>>
>> public class BlahNative {
>> private static int[] intDummy;
>> private static double[] doubleDummy;
>>
>> public BlahNative() {
>> }
>>
>> public static native void native_a(char var0, char var1, int var2, int 
>> var3, int var4, double[] var7, int var8, int var9);
>>
>> static {
>> lib = LibraryLoader
>> .create(LibSodium.class)
>> .search("/usr/local/lib")
>> .search("/opt/local/lib")
>> .search("/usr/lib")
>> .search("/lib")
>> .load(LIBRARY_NAME);
>> initializeLibrary(lib);
>> }
>> }
>> ```
>>
>> Question: For my package
>> ```
>> (defproject mypkg
>> :dependencies [[org.clojure/clojure "1.10.1"]
>>[com.github.jnr/jnr-ffi "2.2.0"]])
>> ```
>> How do I write the wrapper for the native functions in
>> ```
>> (ns mypkg.native
>> (:import [jnr.ffi LibraryLoader])
>> (:import [jnr.ffi.annotations IgnoreError])
>> (:import [jnr.ffi.provider FFIProvider]))
>> ```
>> For the Java interop I am assuming the above namespace should be based on 
>> gen-class (http://clojure-doc.org/articles/language/interop.html).
>>
>> What is not clear to me is:
>> *1. How does one create the `native` method* (since most (defn foo) are 
>> static methods)?
>> *2. How do I access the native functions after loading* the Native 
>> Library (LibraryLoader.load(LIBRARY_NAME))?
>>
>> I am neither a C nor a Java expert so any guidance will be much 
>> appreciated.
>>
>> Thanks,
>> Ngwua
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/clojure/3bd05d7a-297e-49cf-86d4-aec4a88c83cbn%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit