public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Questions regarding modules
@ 2014-03-01 15:52 Marius Kjeldahl
  2014-03-01 22:30 ` Marius Kjeldahl
  2014-03-01 23:06 ` Per Bothner
  0 siblings, 2 replies; 16+ messages in thread
From: Marius Kjeldahl @ 2014-03-01 15:52 UTC (permalink / raw)
  To: kawa

I've read and re-read the module explanations from Per many times, but
I still run into trouble, so I will ask here. My testing is done on
Android, using gradle. If you do not know gradle, what you might need
to know is that a project (by default) is laid out in a certain way.
For instance for a kawa source file for the class
net.kjeldahl.kawa.MyClass will exist in
src/main/kawa/net/kjeldahl/kawa/MyClass.scm . Similarily, the output
of the class files will go into the path
build/classes/debug/net/kjeldahl/kawa/MyClass.class . To the best of
my abilities I've also verified that the class files get put where
they are supposed to be and that the stuff in them is correct (proper
class names, using javap to check the contents).

Anyway, I have my Android activity defined in it's own
KawaActivity.scm file more or less like follows:

(module-name net.kjeldahl.kawatest.app.KawaActivity)
...
(require net.kjeldahl.kawatest.app.HelloKawa "HelloKawa.scm")

(define-simple-class KawaActivity (Activity)
  ((onCreate (savedInstanceState::Bundle)) (@Override)
   (invoke-special Activity (this) 'onCreate savedInstanceState)
   (define tv::TextView (TextView (this) text: "Kawa hello."))
   (define my-view::View (LinearLayout (this)
                                       orientation: LinearLayout:VERTICAL
                                       view: tv))
   ((this):setContentView my-view)
   (define str (string-append "Retval: " (HelloKawa:hello)))
   (tv:setText str)
   ))

The HelloKawa.scm source file is located in the same "namespace" and
directory as the file above, and simply contains:

(module-name net.kjeldahl.kawatest.app.HelloKawa)

(define-simple-class HelloKawa ()
  ((hello) allocation: 'static
   "Hello from HelloKawa!"))

;; (define (hello)
;;    "Hello from Kawa!")

The code shown above works just fine. What I am having trouble with is
figuring out why certain things are needed and not.

Question 1 - The line that does require HelloKawa; Unless I list the
filename "HelloKawa.scm" as the second parameter, I will get a kawa
compiler error; invalid specifier for 'require'. I have no idea why.
I've experienced with setting the working dir prior to calling the
kawa compiler, but it does not seem to matter much. It looks like kawa
has it's own idea about the proper path for start searching for the
source file for the module.

Question 2 - When invoking (HelloKawa:hello), how come kawa knows
about my HelloKawa class without the full class name? I haven't done
any define-alias on it, so it's a bit unexpected.

Question 3 - The file defining HelloKawa uses define-simple-class, but
I've also tried it with a straight up define instead (you'll see that
commented out in the source file above). If I do that, I get two
errors from kawa; no known slot hello in java.lang.Object, and no
declaration seen for HelloKawa. Based on what I've read, this second
method of defining a module should work as long as we stay within the
kawa domain, but I may have interpreted that wrong.

And just to reiterate; I realize there are better ways to write this
kind of code on Android. The trouble is there is a lot more code out
there than Android, and I need to get comfortable with the mappings
before I dare to try and do real stuff with this. If I'm still
struggling at these basic things I can assure you when/if others try
to follow they will have similar issues. So I'm hoping to have some
answers ready!

Thanks,

Marius K.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-01 15:52 Questions regarding modules Marius Kjeldahl
@ 2014-03-01 22:30 ` Marius Kjeldahl
  2014-03-01 23:06 ` Per Bothner
  1 sibling, 0 replies; 16+ messages in thread
From: Marius Kjeldahl @ 2014-03-01 22:30 UTC (permalink / raw)
  To: kawa

I did figure out that (require "HelloKawa.scm") also works, but I
still do not understand why the short form (HelloKawa:hello) works,
but not (net.kjeldahl.kawatest.app.HelloKawa:hello) which is the
full/proper name for that module (at least that's what I'm trying).

Thanks,

Marius K.


On Sat, Mar 1, 2014 at 4:52 PM, Marius Kjeldahl
<marius.kjeldahl@gmail.com> wrote:
> I've read and re-read the module explanations from Per many times, but
> I still run into trouble, so I will ask here. My testing is done on
> Android, using gradle. If you do not know gradle, what you might need
> to know is that a project (by default) is laid out in a certain way.
> For instance for a kawa source file for the class
> net.kjeldahl.kawa.MyClass will exist in
> src/main/kawa/net/kjeldahl/kawa/MyClass.scm . Similarily, the output
> of the class files will go into the path
> build/classes/debug/net/kjeldahl/kawa/MyClass.class . To the best of
> my abilities I've also verified that the class files get put where
> they are supposed to be and that the stuff in them is correct (proper
> class names, using javap to check the contents).
>
> Anyway, I have my Android activity defined in it's own
> KawaActivity.scm file more or less like follows:
>
> (module-name net.kjeldahl.kawatest.app.KawaActivity)
> ...
> (require net.kjeldahl.kawatest.app.HelloKawa "HelloKawa.scm")
>
> (define-simple-class KawaActivity (Activity)
>   ((onCreate (savedInstanceState::Bundle)) (@Override)
>    (invoke-special Activity (this) 'onCreate savedInstanceState)
>    (define tv::TextView (TextView (this) text: "Kawa hello."))
>    (define my-view::View (LinearLayout (this)
>                                        orientation: LinearLayout:VERTICAL
>                                        view: tv))
>    ((this):setContentView my-view)
>    (define str (string-append "Retval: " (HelloKawa:hello)))
>    (tv:setText str)
>    ))
>
> The HelloKawa.scm source file is located in the same "namespace" and
> directory as the file above, and simply contains:
>
> (module-name net.kjeldahl.kawatest.app.HelloKawa)
>
> (define-simple-class HelloKawa ()
>   ((hello) allocation: 'static
>    "Hello from HelloKawa!"))
>
> ;; (define (hello)
> ;;    "Hello from Kawa!")
>
> The code shown above works just fine. What I am having trouble with is
> figuring out why certain things are needed and not.
>
> Question 1 - The line that does require HelloKawa; Unless I list the
> filename "HelloKawa.scm" as the second parameter, I will get a kawa
> compiler error; invalid specifier for 'require'. I have no idea why.
> I've experienced with setting the working dir prior to calling the
> kawa compiler, but it does not seem to matter much. It looks like kawa
> has it's own idea about the proper path for start searching for the
> source file for the module.
>
> Question 2 - When invoking (HelloKawa:hello), how come kawa knows
> about my HelloKawa class without the full class name? I haven't done
> any define-alias on it, so it's a bit unexpected.
>
> Question 3 - The file defining HelloKawa uses define-simple-class, but
> I've also tried it with a straight up define instead (you'll see that
> commented out in the source file above). If I do that, I get two
> errors from kawa; no known slot hello in java.lang.Object, and no
> declaration seen for HelloKawa. Based on what I've read, this second
> method of defining a module should work as long as we stay within the
> kawa domain, but I may have interpreted that wrong.
>
> And just to reiterate; I realize there are better ways to write this
> kind of code on Android. The trouble is there is a lot more code out
> there than Android, and I need to get comfortable with the mappings
> before I dare to try and do real stuff with this. If I'm still
> struggling at these basic things I can assure you when/if others try
> to follow they will have similar issues. So I'm hoping to have some
> answers ready!
>
> Thanks,
>
> Marius K.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-01 15:52 Questions regarding modules Marius Kjeldahl
  2014-03-01 22:30 ` Marius Kjeldahl
@ 2014-03-01 23:06 ` Per Bothner
  2014-03-03  9:06   ` Per Bothner
  1 sibling, 1 reply; 16+ messages in thread
From: Per Bothner @ 2014-03-01 23:06 UTC (permalink / raw)
  To: Marius Kjeldahl, kawa

On 03/01/2014 07:52 AM, Marius Kjeldahl wrote:
> Question 1 - The line that does require HelloKawa; Unless I list the
> filename "HelloKawa.scm" as the second parameter, I will get a kawa
> compiler error; invalid specifier for 'require'. I have no idea why.
> I've experienced with setting the working dir prior to calling the
> kawa compiler, but it does not seem to matter much. It looks like kawa
> has it's own idea about the proper path for start searching for the
> source file for the module.

IIRC the filename "HelloKawa.scm" is needed in a require if
the file is not already-compiled *and* it is not currently being
compiled (i.e. on the kawa -C command line).

This may change if/when we implement R7RS define-library, or
we implement some kind of Scheme packaging mechanism, as has been discussed.

> Question 2 - When invoking (HelloKawa:hello), how come kawa knows
> about my HelloKawa class without the full class name? I haven't done
> any define-alias on it, so it's a bit unexpected.

When you (require MODULE) what happens is that all the public (exported)
names in MODULE are added to the current lexical scope.  The class HelloKawa
is a public exported Scheme name in the HelloKawa module - since they happen
to have the same name - and they happen to get compiled to the same class.

A (define-simple-class HelloKawa () ...) creates a definition of the
identifier HelloKawa in the current Scheme scope - and that binding
is by default exported.  This action is in addition and distinct from
the action of create a JCM class net.kjeldahl.kawatest.app.HelloKawa.

Conceptually the "module class" net.kjeldahl.kawatest.app.HelloKawa
is different from the define-simple-class HelloKawa.  They're just
implemented using a single class, with module-level functionality being
static, and define-simple-class-level stuff being (usually) non-static.

> Question 3 - The file defining HelloKawa uses define-simple-class, but
> I've also tried it with a straight up define instead (you'll see that
> commented out in the source file above). If I do that, I get two
> errors from kawa; no known slot hello in java.lang.Object, and no
> declaration seen for HelloKawa.

Hopefully the previous answers will explain this.

>Based on what I've read, this second
> method of defining a module should work as long as we stay within the
> kawa domain, but I may have interpreted that wrong.

There is no special magic for the "kawa" domain.  They is some special
magic for "kawa.lib" when using R7RS-style import.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-01 23:06 ` Per Bothner
@ 2014-03-03  9:06   ` Per Bothner
  2014-03-03  9:23     ` Marius Kjeldahl
  2014-03-04  9:10     ` Per Bothner
  0 siblings, 2 replies; 16+ messages in thread
From: Per Bothner @ 2014-03-03  9:06 UTC (permalink / raw)
  To: Marius Kjeldahl, kawa

I experimented with a simplified version of your example, and I think
there may be a bug - but I haven't yet figured out why it behaves 
differently
from comiling kawa/lib.

One data-point: Using
   (import (net kjeldahl kawatest appHelloKawa))
instead of:
   (require net.kjeldahl.kawatest.app.HelloKawa)
seems to work.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-03  9:06   ` Per Bothner
@ 2014-03-03  9:23     ` Marius Kjeldahl
  2014-03-03 20:30       ` Per Bothner
  2014-03-04  9:10     ` Per Bothner
  1 sibling, 1 reply; 16+ messages in thread
From: Marius Kjeldahl @ 2014-03-03  9:23 UTC (permalink / raw)
  To: kawa

If it's a bug than certainly explains my struggles.

I can confirm that the import statement does not trigger the error
that the similar require statement does. However I am still unable to
access the "hello" function from KawaHello (when using the
module-name/define pattern) using net.kjeldahl.kawatest.app.KawaHello.
The same "no known slot hello in java.lang.Object" warning gets
triggered.

I've also tried various forms of the (import (prefix (...))) pattern
without any success (still not able to access the hello function with
any class/alias/prefix).

Thanks,

Marius K.


On Mon, Mar 3, 2014 at 10:06 AM, Per Bothner <per@bothner.com> wrote:
> I experimented with a simplified version of your example, and I think
> there may be a bug - but I haven't yet figured out why it behaves
> differently
> from comiling kawa/lib.
>
> One data-point: Using
>   (import (net kjeldahl kawatest appHelloKawa))
> instead of:
>   (require net.kjeldahl.kawatest.app.HelloKawa)
> seems to work.
>
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-03  9:23     ` Marius Kjeldahl
@ 2014-03-03 20:30       ` Per Bothner
  2014-03-03 20:50         ` Marius Kjeldahl
  0 siblings, 1 reply; 16+ messages in thread
From: Per Bothner @ 2014-03-03 20:30 UTC (permalink / raw)
  To: Marius Kjeldahl, kawa

On 03/03/2014 01:23 AM, Marius Kjeldahl wrote:
> If it's a bug than certainly explains my struggles.
>
> I can confirm that the import statement does not trigger the error
> that the similar require statement does. However I am still unable to
> access the "hello" function from KawaHello (when using the
> module-name/define pattern) using net.kjeldahl.kawatest.app.KawaHello.
> The same "no known slot hello in java.lang.Object" warning gets
> triggered.

Replace:
   (HelloKawa:hello)
by plain:
   (hello)
or:
   (net.kjeldahl.kawatest.app.HelloKawa:hello)

Remember what I wrote March 1:

   When you (require MODULE) what happens is that all the public (exported)
   names in MODULE are added to the current lexical scope.

If you write:

(module-name net.kjeldahl.kawatest.app.HelloKawa)
(define (hello)
    "Hello from Kawa!")

then HelloKawa is *not* a public exported name in the module,
so it is *not* in scope in KawaActivity (or in HelloKawa).

Kawa's default binding mechanism does add bindings for all
fully-qualified class names that exist in the classpath.
The is why you can write things like (java.util.ArrayList).
The binding is a default (fall-back), so it only triggers only
if there is no binding in the lexical scope.

However, HelloKawa is not a fully-qualified class name.  For that
you have to write:
    (net.kjeldahl.kawatest.app.HelloKawa:hello)

Best is to write plain:
   (hello)
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-03 20:30       ` Per Bothner
@ 2014-03-03 20:50         ` Marius Kjeldahl
  2014-03-03 21:15           ` Per Bothner
  0 siblings, 1 reply; 16+ messages in thread
From: Marius Kjeldahl @ 2014-03-03 20:50 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa

As I've written, plain "(hello)" works when I include the module with
(require "HelloKawa.scm"). For good reasons I need to control where
the exported symbols appear when requiring the module, not when
defining the individual methods, which is why simply importing all the
defines doesn't cut it. That's why I'm trying to put it into a class
(I really want a namespace, but who cares). Which I've managed to do
when using define-class as explained already.

However, the docs you've written under the section "How a module
becomes a class" states that using module-name is an alternative to
define-class, and THIS is what I am struggling to get working.

Without resorting to using define-class in HelloKawa.scm, I am not
able to use (net.kjeldahl.kawatest.app.HelloKawa:hello) at all. If
possible, could you show me how I can define the "class" in
HelloKawa.scm with module-name and defining the hello method in it so
that it would be callable with the full name
net.kjeldahl.kawatest.app.HelloKawa:hello from KawaActivity?

I would be perfectly happy to be told that define-class IS what I need
to use, but based on how I understand the docs, kawa offers a "less
javalike" method of defining "javalike" classes, and that is what I'm
trying to figure out.

Thanks,

Marius K.


On Mon, Mar 3, 2014 at 9:30 PM, Per Bothner <per@bothner.com> wrote:
> On 03/03/2014 01:23 AM, Marius Kjeldahl wrote:
>>
>> If it's a bug than certainly explains my struggles.
>>
>> I can confirm that the import statement does not trigger the error
>> that the similar require statement does. However I am still unable to
>> access the "hello" function from KawaHello (when using the
>> module-name/define pattern) using net.kjeldahl.kawatest.app.KawaHello.
>> The same "no known slot hello in java.lang.Object" warning gets
>> triggered.
>
>
> Replace:
>   (HelloKawa:hello)
> by plain:
>   (hello)
> or:
>   (net.kjeldahl.kawatest.app.HelloKawa:hello)
>
> Remember what I wrote March 1:
>
>
>   When you (require MODULE) what happens is that all the public (exported)
>   names in MODULE are added to the current lexical scope.
>
> If you write:
>
> (module-name net.kjeldahl.kawatest.app.HelloKawa)
>
> (define (hello)
>    "Hello from Kawa!")
>
> then HelloKawa is *not* a public exported name in the module,
> so it is *not* in scope in KawaActivity (or in HelloKawa).
>
> Kawa's default binding mechanism does add bindings for all
> fully-qualified class names that exist in the classpath.
> The is why you can write things like (java.util.ArrayList).
> The binding is a default (fall-back), so it only triggers only
> if there is no binding in the lexical scope.
>
> However, HelloKawa is not a fully-qualified class name.  For that
> you have to write:
>    (net.kjeldahl.kawatest.app.HelloKawa:hello)
>
> Best is to write plain:
>   (hello)
>
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-03 20:50         ` Marius Kjeldahl
@ 2014-03-03 21:15           ` Per Bothner
       [not found]             ` <CAHdMyCKEqZXfpqTL-AX5q+XAQNq3cChoYFa0aDDVet+_PX_2og@mail.gmail.com>
  0 siblings, 1 reply; 16+ messages in thread
From: Per Bothner @ 2014-03-03 21:15 UTC (permalink / raw)
  To: Marius Kjeldahl; +Cc: kawa

On 03/03/2014 12:50 PM, Marius Kjeldahl wrote:
> For good reasons I need to control where
> the exported symbols appear when requiring the module, not when
> defining the individual methods, which is why simply importing all the
> defines doesn't cut it.

In that case I suggest using import with either rename or prefix.
For example:
   (import (prefix (net kjeldahl kawatest app HelloKawa) kawa-utils-))
...
   (kawa-utils-hello)

>  That's why I'm trying to put it into a class
> (I really want a namespace, but who cares).

As I see it, a module *is* a namespace.

> However, the docs you've written under the section "How a module
> becomes a class" states that using module-name is an alternative to
> define-class, and THIS is what I am struggling to get working.
>
> Without resorting to using define-class in HelloKawa.scm, I am not
> able to use (net.kjeldahl.kawatest.app.HelloKawa:hello) at all. If
> possible, could you show me how I can define the "class" in
> HelloKawa.scm with module-name and defining the hello method in it so
> that it would be callable with the full name
> net.kjeldahl.kawatest.app.HelloKawa:hello from KawaActivity?

Doesn't seem to be working for me either.  But since it's sort-of
a backdoor part the module system, that may be ok.  Still, I'd like to
understand why it isn't working.

> I would be perfectly happy to be told that define-class IS what I need
> to use, but based on how I understand the docs, kawa offers a "less
> javalike" method of defining "javalike" classes, and that is what I'm
> trying to figure out.

Using import seems to make sense.  Though import does need some tweaks
- it should probably be extended to support a source filename, as in
require.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Fwd: Questions regarding modules
       [not found]             ` <CAHdMyCKEqZXfpqTL-AX5q+XAQNq3cChoYFa0aDDVet+_PX_2og@mail.gmail.com>
@ 2014-03-03 21:42               ` Marius Kjeldahl
  0 siblings, 0 replies; 16+ messages in thread
From: Marius Kjeldahl @ 2014-03-03 21:42 UTC (permalink / raw)
  To: kawa

---------- Forwarded message ----------
From: Marius Kjeldahl <marius.kjeldahl@gmail.com>
Date: Mon, Mar 3, 2014 at 10:42 PM
Subject: Re: Questions regarding modules
To: Per Bothner <per@bothner.com>


Ah, thanks for confirming my issues; I was starting to go insane over
why I couldn't get it working.

The import rename makes me feel dirty, but will definitively work for
now. The module stuff should probably be fixed eventually (give me
enough time and keep answering my questions... ;-).

Thanks,

Marius K.

On Mon, Mar 3, 2014 at 10:15 PM, Per Bothner <per@bothner.com> wrote:
> On 03/03/2014 12:50 PM, Marius Kjeldahl wrote:
>>
>> For good reasons I need to control where
>> the exported symbols appear when requiring the module, not when
>> defining the individual methods, which is why simply importing all the
>> defines doesn't cut it.
>
>
> In that case I suggest using import with either rename or prefix.
> For example:
>   (import (prefix (net kjeldahl kawatest app HelloKawa) kawa-utils-))
> ...
>   (kawa-utils-hello)
>
>
>>  That's why I'm trying to put it into a class
>> (I really want a namespace, but who cares).
>
>
> As I see it, a module *is* a namespace.
>
>
>> However, the docs you've written under the section "How a module
>> becomes a class" states that using module-name is an alternative to
>> define-class, and THIS is what I am struggling to get working.
>>
>> Without resorting to using define-class in HelloKawa.scm, I am not
>> able to use (net.kjeldahl.kawatest.app.HelloKawa:hello) at all. If
>> possible, could you show me how I can define the "class" in
>> HelloKawa.scm with module-name and defining the hello method in it so
>> that it would be callable with the full name
>> net.kjeldahl.kawatest.app.HelloKawa:hello from KawaActivity?
>
>
> Doesn't seem to be working for me either.  But since it's sort-of
> a backdoor part the module system, that may be ok.  Still, I'd like to
> understand why it isn't working.
>
>
>> I would be perfectly happy to be told that define-class IS what I need
>> to use, but based on how I understand the docs, kawa offers a "less
>> javalike" method of defining "javalike" classes, and that is what I'm
>> trying to figure out.
>
>
> Using import seems to make sense.  Though import does need some tweaks
> - it should probably be extended to support a source filename, as in
> require.
>
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-03  9:06   ` Per Bothner
  2014-03-03  9:23     ` Marius Kjeldahl
@ 2014-03-04  9:10     ` Per Bothner
  2014-03-04  9:55       ` Marius Kjeldahl
  1 sibling, 1 reply; 16+ messages in thread
From: Per Bothner @ 2014-03-04  9:10 UTC (permalink / raw)
  To: Marius Kjeldahl, kawa

On 03/03/2014 01:06 AM, Per Bothner wrote:
> I experimented with a simplified version of your example, and I think
> there may be a bug - but I haven't yet figured out why it behaves
> differently
> from comiling kawa/lib.
>
> One data-point: Using
>    (import (net kjeldahl kawatest appHelloKawa))
> instead of:
>    (require net.kjeldahl.kawatest.app.HelloKawa)
> seems to work.

I checked in a fix.  The following should work now:
   (require <net.kjeldahl.kawatest.app.HelloKawa>)
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-04  9:10     ` Per Bothner
@ 2014-03-04  9:55       ` Marius Kjeldahl
  2014-03-04 17:23         ` Per Bothner
  0 siblings, 1 reply; 16+ messages in thread
From: Marius Kjeldahl @ 2014-03-04  9:55 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa

Sounds great, but I'm not seeing any new revisions since Sunday
(r7840). Maybe you forgot to "push" it?

Thanks,

Marius K.

On Tue, Mar 4, 2014 at 10:10 AM, Per Bothner <per@bothner.com> wrote:
> On 03/03/2014 01:06 AM, Per Bothner wrote:
>>
>> I experimented with a simplified version of your example, and I think
>> there may be a bug - but I haven't yet figured out why it behaves
>> differently
>> from comiling kawa/lib.
>>
>> One data-point: Using
>>    (import (net kjeldahl kawatest appHelloKawa))
>> instead of:
>>    (require net.kjeldahl.kawatest.app.HelloKawa)
>> seems to work.
>
>
> I checked in a fix.  The following should work now:
>   (require <net.kjeldahl.kawatest.app.HelloKawa>)
>
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-04  9:55       ` Marius Kjeldahl
@ 2014-03-04 17:23         ` Per Bothner
  2014-03-04 18:26           ` Marius Kjeldahl
  0 siblings, 1 reply; 16+ messages in thread
From: Per Bothner @ 2014-03-04 17:23 UTC (permalink / raw)
  To: Marius Kjeldahl; +Cc: kawa

On 03/04/2014 01:55 AM, Marius Kjeldahl wrote:
> Sounds great, but I'm not seeing any new revisions since Sunday
> (r7840). Maybe you forgot to "push" it?

There is no "push" in Subversion - but I failed to exit the
emacs-window for composing the check-in message.  One of the dangers
of trying to get things done just before going to bed ...
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-04 17:23         ` Per Bothner
@ 2014-03-04 18:26           ` Marius Kjeldahl
  2014-03-04 18:48             ` Per Bothner
  0 siblings, 1 reply; 16+ messages in thread
From: Marius Kjeldahl @ 2014-03-04 18:26 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa

I know svn doesn't have push, which is why I quoted it. Consider it a
clue on what I'll be "pushing" for when/if I start comitting patches.
;-)

I got the r7841 update, but ufortunately I can still not get it
working (I've tried various combinations with the < > signs and
without, still no luck).

Thanks,

Marius K.

On Tue, Mar 4, 2014 at 6:23 PM, Per Bothner <per@bothner.com> wrote:
> On 03/04/2014 01:55 AM, Marius Kjeldahl wrote:
>>
>> Sounds great, but I'm not seeing any new revisions since Sunday
>> (r7840). Maybe you forgot to "push" it?
>
>
> There is no "push" in Subversion - but I failed to exit the
> emacs-window for composing the check-in message.  One of the dangers
> of trying to get things done just before going to bed ...
>
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-04 18:26           ` Marius Kjeldahl
@ 2014-03-04 18:48             ` Per Bothner
  2014-03-04 18:58               ` Marius Kjeldahl
  0 siblings, 1 reply; 16+ messages in thread
From: Per Bothner @ 2014-03-04 18:48 UTC (permalink / raw)
  To: Marius Kjeldahl; +Cc: kawa

On 03/04/2014 10:18 AM, Marius Kjeldahl wrote:
> I know svn doesn't have push, which is why I quoted it. Consider it a
> clue on what I'll be "pushing" for when/if I start comitting patches.
> ;-)
>
> I got the r7841 update, but ufortunately I can still not get it
> working (I've tried various combinations with the < > signs and
> without, still no luck).

Can you show me some simplified sample code? It would be easier for me
to try it if you make it non-Android-specific.  For example I experimented
with:

(module-name p.KawaActivity)
(require <p.HelloKawa>)
(define-simple-class KawaActivity ()
   ((onCreate) (HelloKawa:hello)))

....

(module-name p.HelloKawa)
(define-simple-class HelloKawa ()
   ((hello) allocation: 'static
    "Hello from HelloKawa!"))
;;(define (hello)
;;  "Hello from Kawa!")
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-04 18:48             ` Per Bothner
@ 2014-03-04 18:58               ` Marius Kjeldahl
  2014-03-04 20:16                 ` Per Bothner
  0 siblings, 1 reply; 16+ messages in thread
From: Marius Kjeldahl @ 2014-03-04 18:58 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa

Possibly a delusion on my part, but I was under the assumption that a
module defined without any class declaration could be made, i.e.:

(module-name net.kjeldahl.mymod)
(define (hello)
  "Hello")

which could then somehow be required and used in another module:

(require <net.kjeldahl.mymod>)
....
(net.kjeldahl.mymod:hello)

That assumption may be wrong on my part. But that begs my previous
question on what the module-name declaration does. My earlier testing
shows that it is not needed if I use define-class or similar...

Thanks,

Marius K.


On Tue, Mar 4, 2014 at 7:48 PM, Per Bothner <per@bothner.com> wrote:
> On 03/04/2014 10:18 AM, Marius Kjeldahl wrote:
>>
>> I know svn doesn't have push, which is why I quoted it. Consider it a
>> clue on what I'll be "pushing" for when/if I start comitting patches.
>> ;-)
>>
>> I got the r7841 update, but ufortunately I can still not get it
>> working (I've tried various combinations with the < > signs and
>> without, still no luck).
>
>
> Can you show me some simplified sample code? It would be easier for me
> to try it if you make it non-Android-specific.  For example I experimented
> with:
>
> (module-name p.KawaActivity)
> (require <p.HelloKawa>)
> (define-simple-class KawaActivity ()
>   ((onCreate) (HelloKawa:hello)))
>
> ....
>
> (module-name p.HelloKawa)
>
> (define-simple-class HelloKawa ()
>   ((hello) allocation: 'static
>    "Hello from HelloKawa!"))
> ;;(define (hello)
> ;;  "Hello from Kawa!")
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Questions regarding modules
  2014-03-04 18:58               ` Marius Kjeldahl
@ 2014-03-04 20:16                 ` Per Bothner
  0 siblings, 0 replies; 16+ messages in thread
From: Per Bothner @ 2014-03-04 20:16 UTC (permalink / raw)
  To: Marius Kjeldahl; +Cc: kawa

On 03/04/2014 10:58 AM, Marius Kjeldahl wrote:
> Possibly a delusion on my part, but I was under the assumption that a
> module defined without any class declaration could be made, i.e.:
>
> (module-name net.kjeldahl.mymod)
> (define (hello)
>    "Hello")
>
> which could then somehow be required and used in another module:
>
> (require <net.kjeldahl.mymod>)
> ....
> (net.kjeldahl.mymod:hello)

It can - but you should write:
   (hello)

The (require <net.kjeldahl.mymod>) does not add 'net.kjeldahl.mymod'
to the importing scope.  It adds 'hello' to the importing scope.
If you don't want to add 'hello', use import with either prefix
or rename.

Both <net.kjeldahl.mymod> and net.kjeldahl.mymod are available
in the "fall-back" scope - along with all other classes - but only if
they are existing classes in the classpath.  Making use of this
feature is rather counter to using require (or import): It is
redundant, and may bypass module initialization (unless the
module is compiled with --module-static-run).

> But that begs my previous
> question on what the module-name declaration does.

module-name just sets the name of the generated "module class".
I.e. it overrides the default name computed from the source file name
and the -P and -T flags.  It doesn't otherwise change how the
module is compiled.

> My earlier testing
> shows that it is not needed if I use define-class or similar...

They do different things.  define-class/define-simple-class
creates a named class.  (You can also override the name and
package of the class generated by define-[simple-]class.
The define-[simple-]class class is *in addition* to the
module class, which is always created.  There is a special
hack when a define-[simple-]class class has the same name
as the module class - in that case they're "merged" into
a single class.

Trying to access a define-class/define-simple-class
directly using its full-qualified name, instead of
importing or requiring it will often work, but is
fragile, because module initialization may not have
been done.  For example if the module has a top-level
variable, it may not have been initialized.  If you
want to do that, you should compile using --module-static-run
or (module-static 'init-run).  The causes the module
body and related initialization to be executed byn the
static initializer of the module class.  Some initialization
happens in the static initializer regradless, so you can
often get away with not having properly initialized
the module - but that doesn't make it a good idea.

So you have these good choices:

(1) Use the module system: Put the names you want in a module,
export them.  To use them import or require the module - and
use the imported names - not the class names.

(2) By-pass the module system, and use define[-simple]-class
instead, but compile with --module-static-run.  Access the
classes directly - optionally defining define-aliases.

My recommendation is:
* If you want a class in the sense of something that can be
instantiated multiple times, use (2).
It is possible to use a module, with module-extends,
but it doesn't seem the best way.

* If you want a module/namespace in the sense of a
collection of (name,value)-bindings, or other kind of
singleton, use (1).
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2014-03-04 20:16 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-01 15:52 Questions regarding modules Marius Kjeldahl
2014-03-01 22:30 ` Marius Kjeldahl
2014-03-01 23:06 ` Per Bothner
2014-03-03  9:06   ` Per Bothner
2014-03-03  9:23     ` Marius Kjeldahl
2014-03-03 20:30       ` Per Bothner
2014-03-03 20:50         ` Marius Kjeldahl
2014-03-03 21:15           ` Per Bothner
     [not found]             ` <CAHdMyCKEqZXfpqTL-AX5q+XAQNq3cChoYFa0aDDVet+_PX_2og@mail.gmail.com>
2014-03-03 21:42               ` Fwd: " Marius Kjeldahl
2014-03-04  9:10     ` Per Bothner
2014-03-04  9:55       ` Marius Kjeldahl
2014-03-04 17:23         ` Per Bothner
2014-03-04 18:26           ` Marius Kjeldahl
2014-03-04 18:48             ` Per Bothner
2014-03-04 18:58               ` Marius Kjeldahl
2014-03-04 20:16                 ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).