This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: java -Dplugins.dir=./jars kawa.repl
- From: Jamison Hope <jrh at theptrgroup dot com>
- To: kawa list <kawa at sourceware dot org>
- Date: Wed, 30 Sep 2015 19:24:08 -0400
- Subject: Re: java -Dplugins.dir=./jars kawa.repl
- Authentication-results: sourceware.org; auth=none
- References: <20150930165245 dot 5bfd8aa2 at capac> <560C4511 dot 3060402 at bothner dot com> <20150930193314 dot 7a5cf55b at capac>
Note that Guile and Kawa do not take the same command-line arguments
(compare `kawa --help` and `guile --help`), so your usage of
"-e main -s" is not going to do what you're after.
You should read the Usage Reference section of the manual:
http://www.gnu.org/software/kawa/Running.html
particularly the sections on command-line arguments and "running
command scripts".
My own Kawa scripts usually start with something like this at the top:
> #!/bin/sh # -*- scheme -*-
> exec java -Dkawa.command.name="$0" kawa.repl --script2 "$0" "$@"
If I need to set an environment variable or something, then I put that
before the exec and change the --scriptN argument appropriately:
> #!/bin/sh # -*- scheme -*-
> export CLASSPATH=/path/to/kawa.jar:/path/to/other-stuff.jar
> exec java -Dkawa.command.name="$0" kawa.repl --script3 "$0" "$@"
--scriptN tells Kawa to disregard the first N lines of the file before
beginning to parse the file as Scheme, so you don't have to put !#
on the next line.
There is no command line argument to specify an entry point, it will
just start evaluating the contents of the file, so you don't need to
define a function called "main".
There is not a getopt facility (patches welcome), so you'll have to
iterate over the list returned by command-line or the vector
command-line-arguments. There is a process-command-line-assignments
function which will handle simple definitions.
http://www.gnu.org/software/kawa/System-inquiry.html
Altogether, an executable Kawa script might look like:
> #!/bin/sh # -*- scheme -*-
> exec java -Dkawa.command.name="$0" kawa.repl --script2 "$0" "$@"
> (let ((cl (command-line)))
> (format #t "Hello from \"~a\"~%My arguments were:~%~{~a~%~}" (car cl)
> (cdr cl)))
When I put that in /tmp/foo, chmod +x it, and then call it as
`/tmp/foo a b c d=3` I get:
> Hello from "/tmp/foo"
> My arguments were:
> a
> b
> c
> d=3
-Jamie
On Sep 30, 2015, at 6:33 PM, David Pirotte <david@altosw.be> wrote:
> Per,
> Jhope,
>
>> ...
>> My advance: Don't try to change the plugins.dir after the JVM running Kawa has
>> started up.
>> ...
>
> Thanks both
>
> Now I want to script, here is an example: I brutely copied the exec from guile,
> I could not find an example in the manual [I may have missed if, though]
>
> Could you tell me what I should do instead?
>
> As I'm at it, does kawa has a module to parse args? I'm thinking of
> something similar to our (ice-9 getopt-long) in guile:
>
> https://www.gnu.org/software/guile/manual/guile.html#getopt_002dlong
>
> Thanks,
> David
>
>
> ;;; nl-mean starts here
> #!/bin/sh
> # -*- mode: scheme; coding: utf-8 -*-
> exec /opt/bin/kawa -Dplugins.dir=./jars -e main -s "$0" "$@"
> !#
>
> (define (main args)
> (display (command-line))
> (newline)
> (display args)
> (newline))
> ;; nl-mean ends here
>
> chmod a+x nl-mean
> ./nl-mean . img1 png img2 30
> <string>:1:1: warning - no declaration seen for main
> <string>:1:1: unbound location: main
> ...
--
Jamison Hope
The PTR Group
www.theptrgroup.com