Missing feature or just differences with Guile for define-public

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

Missing feature or just differences with Guile for define-public

scprotz
I was trying to compile the scm files that come with Aisleriot using
Kawa (these are intended for use with Guile, but I was hoping to try
them out in Java).  Many seem to compile ok, but one of the core
files, api.scm has problems.

I came across two issues when trying to convert api.scm to .class.

The first was "invalid use of '_".  Apparently kawa doesn't like the _
as part of define's.  Easy enough to fix just by changing the '_ to
another identifier.

The second issue though was I get "improper list (circular or dotted)
is not allowed here.

Here is an example define-public from the file:

(define-public (set-features . feature-list)
  (set-feature-word! (+ (get-feature-word)
       (apply + feature-list))))

My scheme-fu is very very weak, so I'm not sure if this is just an
implementation difference, a bug, or my misunderstanding.

Any help is appreciated  (and if you want your own copy of the scm
files from aisleriot, you can grab them here:
https://github.com/GNOME/aisleriot)

-scprotz
Reply | Threaded
Open this post in threaded view
|

Re: Missing feature or just differences with Guile for define-public

Per Bothner
On 01/28/2017 04:40 AM, scprotz wrote:

> I was trying to compile the scm files that come with Aisleriot using
> Kawa (these are intended for use with Guile, but I was hoping to try
> them out in Java).  Many seem to compile ok, but one of the core
> files, api.scm has problems.
>
> I came across two issues when trying to convert api.scm to .class.
>
> The first was "invalid use of '_".  Apparently kawa doesn't like the _
> as part of define's.  Easy enough to fix just by changing the '_ to
> another identifier.
>
> The second issue though was I get "improper list (circular or dotted)
> is not allowed here.
>
> Here is an example define-public from the file:
>
> (define-public (set-features . feature-list)
>   (set-feature-word! (+ (get-feature-word)
>        (apply + feature-list))))
>
> My scheme-fu is very very weak, so I'm not sure if this is just an
> implementation difference, a bug, or my misunderstanding.

This problem is because Kawa does not define define-public,
so Kawa thinks it is a function call.  And an quoted dotted
list is not valid in an expression.

Kawa has a different module system that Guile.
Specifically, it does not define define-module,
use-module, or define-public.

It might be possible to define Kawa implementations for
the Guile module system on top of the Kawa module system,
though there would probably be some incompatibilities.

It seems like Aisleriot depends on lots of native code,
including calls to Gnome.  So getting anything working will be
a major porting effort.

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

Re: Missing feature or just differences with Guile for define-public

scprotz
So my guess is, from a functional point of view, 'define-public' is
essentially like 'extern' in C (exposing the function to the C/Gnome)
calls?

I have already reviewed the C/C++ code in Aisleriot and converting it
from C to Java has been very easy so far (since GTK/Glib have very
similar counterparts in Java).  I'm just trying to figure out how I'd
make the functional equivalent of a 'define-public' in a Kawa program
so that my Java app can call it, or is everything automatically
exposed as part of the compiled class once compiled by Kawa  (i.e.
there would be a class called "api.class" and it would have a function
called "setFeatures"?  Again, my exposure to Kawa specifically is
limited at this time, so just looking for pointers.

If all defines are exposed as class objects (methods), then just
changing define-public to define might be good enough (since
define-public seems to be a guile-specific thing to expose functions
to C).

-scprotz


On Sun, Jan 29, 2017 at 3:07 AM, Per Bothner <[hidden email]> wrote:

> On 01/28/2017 04:40 AM, scprotz wrote:
>>
>> I was trying to compile the scm files that come with Aisleriot using
>> Kawa (these are intended for use with Guile, but I was hoping to try
>> them out in Java).  Many seem to compile ok, but one of the core
>> files, api.scm has problems.
>>
>> I came across two issues when trying to convert api.scm to .class.
>>
>> The first was "invalid use of '_".  Apparently kawa doesn't like the _
>> as part of define's.  Easy enough to fix just by changing the '_ to
>> another identifier.
>>
>> The second issue though was I get "improper list (circular or dotted)
>> is not allowed here.
>>
>> Here is an example define-public from the file:
>>
>> (define-public (set-features . feature-list)
>>   (set-feature-word! (+ (get-feature-word)
>>        (apply + feature-list))))
>>
>> My scheme-fu is very very weak, so I'm not sure if this is just an
>> implementation difference, a bug, or my misunderstanding.
>
>
> This problem is because Kawa does not define define-public,
> so Kawa thinks it is a function call.  And an quoted dotted
> list is not valid in an expression.
>
> Kawa has a different module system that Guile.
> Specifically, it does not define define-module,
> use-module, or define-public.
>
> It might be possible to define Kawa implementations for
> the Guile module system on top of the Kawa module system,
> though there would probably be some incompatibilities.
>
> It seems like Aisleriot depends on lots of native code,
> including calls to Gnome.  So getting anything working will be
> a major porting effort.
>
> --
>         --Per Bothner
> [hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Missing feature or just differences with Guile for define-public

Per Bothner
On 01/28/2017 10:07 PM, scprotz wrote:

> So my guess is, from a functional point of view, 'define-public' is
> essentially like 'extern' in C (exposing the function to the C/Gnome)
> calls?
>
> I have already reviewed the C/C++ code in Aisleriot and converting it
> from C to Java has been very easy so far (since GTK/Glib have very
> similar counterparts in Java).  I'm just trying to figure out how I'd
> make the functional equivalent of a 'define-public' in a Kawa program
> so that my Java app can call it, or is everything automatically
> exposed as part of the compiled class once compiled by Kawa  (i.e.
> there would be a class called "api.class" and it would have a function
> called "setFeatures"?  Again, my exposure to Kawa specifically is
> limited at this time, so just looking for pointers.
>
> If all defines are exposed as class objects (methods), then just
> changing define-public to define might be good enough

Guile's define-public is like a combination of Kawa's define and export.
But in Kawa export is the default - assuming there is no explicit export (or equivalently
module-export).

You can generally remove 'define-module', optionally replace it with 'module-name'.
If you see a use-module, you can replace it with an 'import' or a 'require'.
(This are basically the same - import is more flexible, and is R7RS-compatible,
so is usually preferred.)

Lots of information in https://www.gnu.org/software/kawa/Module-classes.html
and https://www.gnu.org/software/kawa/Importing.html .

> (since define-public seems to be a guile-specific thing to expose functions
> to C).

I don't believe that is current.  My understanding it's more like 'public'
in Java.  It not only exposes functions to C, but more importantly it
exposes them to other modules.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Missing feature or just differences with Guile for define-public

scprotz
Thanks.  This answers my question.  I was browsing the Kawa docs and
those functions seemed very similar so I'll explore them and see if I
can use them as drop-in solutions (or decent approximations).  If I
ever get it all up and running, I'll be sure to post the results back
for others.

On Sun, Jan 29, 2017 at 11:03 AM, Per Bothner <[hidden email]> wrote:

> On 01/28/2017 10:07 PM, scprotz wrote:
>>
>> So my guess is, from a functional point of view, 'define-public' is
>> essentially like 'extern' in C (exposing the function to the C/Gnome)
>> calls?
>>
>> I have already reviewed the C/C++ code in Aisleriot and converting it
>> from C to Java has been very easy so far (since GTK/Glib have very
>> similar counterparts in Java).  I'm just trying to figure out how I'd
>> make the functional equivalent of a 'define-public' in a Kawa program
>> so that my Java app can call it, or is everything automatically
>> exposed as part of the compiled class once compiled by Kawa  (i.e.
>> there would be a class called "api.class" and it would have a function
>> called "setFeatures"?  Again, my exposure to Kawa specifically is
>> limited at this time, so just looking for pointers.
>>
>> If all defines are exposed as class objects (methods), then just
>> changing define-public to define might be good enough
>
>
> Guile's define-public is like a combination of Kawa's define and export.
> But in Kawa export is the default - assuming there is no explicit export (or
> equivalently
> module-export).
>
> You can generally remove 'define-module', optionally replace it with
> 'module-name'.
> If you see a use-module, you can replace it with an 'import' or a 'require'.
> (This are basically the same - import is more flexible, and is
> R7RS-compatible,
> so is usually preferred.)
>
> Lots of information in https://www.gnu.org/software/kawa/Module-classes.html
> and https://www.gnu.org/software/kawa/Importing.html .
>
>> (since define-public seems to be a guile-specific thing to expose
>> functions
>> to C).
>
>
> I don't believe that is current.  My understanding it's more like 'public'
> in Java.  It not only exposes functions to C, but more importantly it
> exposes them to other modules.
>
> --
>         --Per Bothner
> [hidden email]   http://per.bothner.com/