This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: the right way to compile and load modules


On May 13, 2014, at 8:43 PM, Per Bothner <per@bothner.com> wrote:

>> 
>> Using module-export cures these symptoms.
>> 
>> Since this is contrary to the kawa docs, I'm open to the possibility that I'm still doing something wrong that causes the unexpected behavior.
> 
> I don't know.  Sounds mysterious.  If you have *no* module-exports it's supposed to be equivalent to
> exporting everything that isn't define-private etc.  There are some exceptions - for examples names that
> are imported using require aren'r re-exported by default.Again, perhaps you can show us a simple test-case?

Two source files:

src/fact.scm:

(define (fact n)
  (if (<= n 1)
      1
      (* n (fact (- n 1)))))



src/factest.scm:

(require "fact.scm")


(newline)
(display (fact 6))
(newline)



Ant build file in the directory that contains the src directory:

...

  <path id="kawa.class.path">
    <pathelement location="./lib/kawa-1.14.jar"/>
    <pathelement path="."/>
  </path>

...


  <!--compile fact -->
  <target name="fact">
    <java taskname="kawa"
          classname="kawa.repl"
          failOnError="true"
          dir="./src"
          fork="true">
      <classpath refid="kawa.class.path"/>
      <arg line="-C 'fact.scm'"/>
    </java>
  </target>

  <!--compile factest -->
  <target name="factest" depends="fact">
    <java taskname="kawa"
          classname="kawa.repl"
          failOnError="true"
          dir="./src"
          fork="true">
      <classpath refid="kawa.class.path"/>
      <arg line="--main -C 'factest.scm'"/>
    </java>
  </target>


Build results:

$ ant factest
Buildfile: /Users/mikel/Workshop/fabric/build.xml

fact:
     [kawa] (compiling fact.scm to fact)

factest:
     [kawa] (compiling factest.scm to factest)
     [kawa] /Users/mikel/Workshop/fabric/src/fact.scm:3:9: warning - no use of fact
     [kawa] factest.scm:3:1: warning - no declaration seen for fact


Run test:

$ java -cp src:lib/kawa-1.14.jar factest
factest.scm:3:1: unbound location fact
	at gnu.mapping.SharedLocation.get(SharedLocation.java:22)
	at gnu.mapping.ThreadLocation.get(ThreadLocation.java:105)
	at factest.run(factest.scm:3)
	at gnu.expr.ModuleBody.runAsMain(ModuleBody.java:152)
	at factest.main(factest.scm)

BUILD SUCCESSFUL


Add a module-export form to fact.scm:

Build results:

$ ant factest
Buildfile: /Users/mikel/Workshop/fabric/build.xml

fact:
     [kawa] (compiling fact.scm to fact)

factest:
     [kawa] (compiling factest.scm to factest)

BUILD SUCCESSFUL


Run test:

$ java -cp src:lib/kawa-1.14.jar factest

720




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]