Using Kawa extensions in R7RS libraries

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Kawa extensions in R7RS libraries

Helmut Eller-2
I supposed it's possible to import Kawa extensions into
R7RS libraries like so:

 (define-library (foo)
   (import (only <some-library> invoke invoke-static field static-field))
   ...)

But what is the name of <some-library> that exports the various Kawa
extensions?

Howev

Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Per Bothner


On 02/12/2015 01:27 AM, Helmut Eller wrote:
> I supposed it's possible to import Kawa extensions into
> R7RS libraries like so:
>
>   (define-library (foo)
>     (import (only <some-library> invoke invoke-static field static-field))
>     ...)
>
> But what is the name of <some-library> that exports the various Kawa
> extensions?

I think we could start with:
   (kawa reflect) ; includes invoke invoke-static field static-field and more
   (kawa all) ; everything defined in the default REPL

I'll get to it soon, but if you want to contribute at least (kawa reflect)
it's fairly straightforward. See kawa/lib/prim_imports.scm for how to do it.
We just need to create kawa/lib/kawa/reflect.scm based on that pattern.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Helmut Eller-2
On Thu, Feb 12 2015, Per Bothner wrote:

> I'll get to it soon, but if you want to contribute at least (kawa reflect)
> it's fairly straightforward. See kawa/lib/prim_imports.scm for how to do it.
> We just need to create kawa/lib/kawa/reflect.scm based on that pattern.

Here are two files reflect.scm and all.scm.  I added to (kawa all) the
stuff that I happened to need; many things that are described in the
manual are missing.  I'm also not sure that (kawa reflect) is very I
usually need the features to access Java libraries and this includes
try-catch and define-simple-class.

When I tried to import (kawa reflect) into (kawa all) I got errors like
 Exception in thread "main" java.lang.NoClassDefFoundError:
   kawa/reflect (wrong name: kawa/lib/kawa/reflect)
I wasn't sure how to fix it, so I just duplicated the imports.

Helmut


reflect.scm (840 bytes) Download Attachment
all.scm (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Per Bothner


On 02/15/2015 12:49 PM, Helmut Eller wrote:

> On Thu, Feb 12 2015, Per Bothner wrote:
>
>> I'll get to it soon, but if you want to contribute at least (kawa reflect)
>> it's fairly straightforward. See kawa/lib/prim_imports.scm for how to do it.
>> We just need to create kawa/lib/kawa/reflect.scm based on that pattern.
>
> Here are two files reflect.scm and all.scm.  I added to (kawa all) the
> stuff that I happened to need; many things that are described in the
> manual are missing.  I'm also not sure that (kawa reflect) is very I
> usually need the features to access Java libraries and this includes
> try-catch and define-simple-class.

Thanks.  I checked this in.

I intended (kawa all) to include all the definitions available in the normal
Kawa environment.  So I also imported and re-exported all the (scheme XXX)
libraries.

We might want a different library for all the of the definitions in kawa
but *not* in r7rs - perhaps named (kawa extras) or (kawa non-r7rs).
However, I can't think of a use for this.

I haven't added all the kawa bindings yet - this is a weork-in-progress.
When done we can probably remove all the deinitions in Scheme#initScheme,
instead just do a loadClass of the kawa.lib.scheme.all class thus removing
a bunch of duplication.

> When I tried to import (kawa reflect) into (kawa all) I got errors like
>   Exception in thread "main" java.lang.NoClassDefFoundError:
>     kawa/reflect (wrong name: kawa/lib/kawa/reflect)
> I wasn't sure how to fix it, so I just duplicated the imports.

I fixed this by adding a catch to ignore this Error.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Per Bothner


On 02/16/2015 10:23 PM, Per Bothner wrote:
> I intended (kawa all) to include all the definitions available in the normal
> Kawa environment.  So I also imported and re-exported all the (scheme XXX)
> libraries.

On second thoughts, this should probably be (kawa base).  Calling it '(kawa all)'
implies including every single library, and I don't think we want
everything to be defined by default.

--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Jamison Hope
In reply to this post by Per Bothner
On Feb 17, 2015, at 1:23 AM, Per Bothner <[hidden email]> wrote:

> On 02/15/2015 12:49 PM, Helmut Eller wrote:
>> Here are two files reflect.scm and all.scm.  I added to (kawa all) the
>> stuff that I happened to need; many things that are described in the
>> manual are missing.  I'm also not sure that (kawa reflect) is very I
>> usually need the features to access Java libraries and this includes
>> try-catch and define-simple-class.
>
> Thanks.  I checked this in.

(kawa reflect) was missing the field setters set-field! and
set-static-field!, patch attached.


--
Jamison Hope
The PTR Group
www.theptrgroup.com



field-setters.patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Per Bothner


On 04/12/2015 10:45 PM, Jamison Hope wrote:

> (kawa reflect) was missing the field setters set-field! and
> set-static-field!, patch attached.

Thanks - checked in.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Per Bothner


On 07/05/2015 12:31 AM, Elías Alonso G.-Cornejo wrote:

> I've been having some trouble using
>
> (object ...)
>
> to create anonymous classes inside
>
> (define-library ...)
>
> declarations. I've added (import (kawa base)), but Kawa tries to
> instantiate java.lang.Object instead of creating the anonymous class.
> Where is the (object ...) macro defined? I've looking in lib/kawa,
> but can't find it.
The object macro is implemented by the Java code kawa/standard/object.java.
(You can see this by searching for "object" in kawa/standard/Scheme.java.)

It looks like 'object' is missing in (kawa base).  Please try the
attached patch and let me know if that fixes the issue.

We need to systematically go through the kawa extensions and add
them to (kawa base).  (We should also re-do the bindings in Scheme.java
to use (kawa base) rather than duplicate it.)
--
        --Per Bothner
[hidden email]   http://per.bothner.com/

obj.patch (540 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Elías Alonso G.-Cornejo
The patch works correctly but raises another issue: (future ...) and
(runnable ...) are not included in (kawa base). I don't know if they
should be included, but if I require kawa/lib/thread.scm with (import
thread), any attempt to call (future ...) will show the following
message:

warning - no declaration seen for lambda

And fail. I fixed it by adding (import (scheme base)) at the top of
kawa/lib/thread.scm but I'm not sure if that's the best way to do it.

> The object macro is implemented by the Java code kawa/standard/object.java.
> (You can see this by searching for "object" in kawa/standard/Scheme.java.)

Thanks, I appreciate the directions. I've tried to read kawa's source
code before, but didn't know where to begin. kawa/standard/Scheme.java
looks like a good starting point :)

2015-07-05 18:17 GMT+02:00 Per Bothner <[hidden email]>:

>
>
> On 07/05/2015 12:31 AM, Elías Alonso G.-Cornejo wrote:
>>
>> I've been having some trouble using
>>
>> (object ...)
>>
>> to create anonymous classes inside
>>
>> (define-library ...)
>>
>> declarations. I've added (import (kawa base)), but Kawa tries to
>> instantiate java.lang.Object instead of creating the anonymous class.
>> Where is the (object ...) macro defined? I've looking in lib/kawa,
>> but can't find it.
>
>
> The object macro is implemented by the Java code kawa/standard/object.java.
> (You can see this by searching for "object" in kawa/standard/Scheme.java.)
>
> It looks like 'object' is missing in (kawa base).  Please try the
> attached patch and let me know if that fixes the issue.
>
> We need to systematically go through the kawa extensions and add
> them to (kawa base).  (We should also re-do the bindings in Scheme.java
> to use (kawa base) rather than duplicate it.)
>
> --
>         --Per Bothner
> [hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Elías Alonso G.-Cornejo
The bitwise operators are missing from (kawa base) too.

2015-07-06 9:29 GMT+02:00 Elías Alonso G.-Cornejo <[hidden email]>:

> The patch works correctly but raises another issue: (future ...) and
> (runnable ...) are not included in (kawa base). I don't know if they
> should be included, but if I require kawa/lib/thread.scm with (import
> thread), any attempt to call (future ...) will show the following
> message:
>
> warning - no declaration seen for lambda
>
> And fail. I fixed it by adding (import (scheme base)) at the top of
> kawa/lib/thread.scm but I'm not sure if that's the best way to do it.
>
>> The object macro is implemented by the Java code kawa/standard/object.java.
>> (You can see this by searching for "object" in kawa/standard/Scheme.java.)
>
> Thanks, I appreciate the directions. I've tried to read kawa's source
> code before, but didn't know where to begin. kawa/standard/Scheme.java
> looks like a good starting point :)
>
> 2015-07-05 18:17 GMT+02:00 Per Bothner <[hidden email]>:
>>
>>
>> On 07/05/2015 12:31 AM, Elías Alonso G.-Cornejo wrote:
>>>
>>> I've been having some trouble using
>>>
>>> (object ...)
>>>
>>> to create anonymous classes inside
>>>
>>> (define-library ...)
>>>
>>> declarations. I've added (import (kawa base)), but Kawa tries to
>>> instantiate java.lang.Object instead of creating the anonymous class.
>>> Where is the (object ...) macro defined? I've looking in lib/kawa,
>>> but can't find it.
>>
>>
>> The object macro is implemented by the Java code kawa/standard/object.java.
>> (You can see this by searching for "object" in kawa/standard/Scheme.java.)
>>
>> It looks like 'object' is missing in (kawa base).  Please try the
>> attached patch and let me know if that fixes the issue.
>>
>> We need to systematically go through the kawa extensions and add
>> them to (kawa base).  (We should also re-do the bindings in Scheme.java
>> to use (kawa base) rather than duplicate it.)
>>
>> --
>>         --Per Bothner
>> [hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Per Bothner
On 07/08/2015 07:10 AM, Elías Alonso G.-Cornejo wrote:
> The bitwise operators are missing from (kawa base) too.

I added those, and checked in the addition of object.

--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Per Bothner
In reply to this post by Elías Alonso G.-Cornejo
On 07/06/2015 12:29 AM, Elías Alonso G.-Cornejo wrote:
> The patch works correctly but raises another issue: (future ...) and
> (runnable ...) are not included in (kawa base).

'runnable' appears to have been in (kawa base).
I also added 'future' and 'sleep.'

I don't know if they
> should be included, but if I require kawa/lib/thread.scm with (import
> thread), any attempt to call (future ...) will show the following
> message:
>
> warning - no declaration seen for lambda
>
> And fail. I fixed it by adding (import (scheme base)) at the top of
> kawa/lib/thread.scm but I'm not sure if that's the best way to do it.

Yes, that is the correct idea, though I used prim_imports instead.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Using Kawa extensions in R7RS libraries

Elías Alonso G.-Cornejo
Thanks!

2015-07-13 2:16 GMT+02:00 Per Bothner <[hidden email]>:

> On 07/06/2015 12:29 AM, Elías Alonso G.-Cornejo wrote:
>>
>> The patch works correctly but raises another issue: (future ...) and
>> (runnable ...) are not included in (kawa base).
>
>
> 'runnable' appears to have been in (kawa base).
> I also added 'future' and 'sleep.'
>
> I don't know if they
>>
>> should be included, but if I require kawa/lib/thread.scm with (import
>> thread), any attempt to call (future ...) will show the following
>> message:
>>
>> warning - no declaration seen for lambda
>>
>> And fail. I fixed it by adding (import (scheme base)) at the top of
>> kawa/lib/thread.scm but I'm not sure if that's the best way to do it.
>
>
> Yes, that is the correct idea, though I used prim_imports instead.
>
> --
>         --Per Bothner
> [hidden email]   http://per.bothner.com/