[gambit-list] Trouble building gambit

Marc Feeley feeley at iro.umontreal.ca
Sun May 14 03:03:21 EDT 2017


Hello Faré.  Patches are always welcome for features that improve functionality while sticking to Gambit’s design philosophy and goals.  An important aspect is that to achieve high portability Gambit links with no external libraries (except for OpenSSL but only if you enable that).  For this reason Gambit does its own command line parsing (and garbage collector, and bignum library, and Unicode encoding/decoding, etc) and a lot of the runtime library is written in Scheme (for example bignums and thread system).  So adding --eval would require an explicit change of the code… this is done in Scheme code in gsi/main.scm).

Concerning “loading more than one file” you can do that already like this:

    gsi a.scm b.scm c.scm

This will load those files sequentially (and you can intersperse -e options).  If you want the program to process command line arguments the best way it to start the “main” program module file with a shebang.  So if a.scm is written like so

    #! /usr/bin/env gsi
    (define (main . args) (pp args))

and you run

    gsi a.scm 11 22 33

you will get ("11" "22" "33")

This syntax is parsed by the Gambit compiler so you can do:

    % gsi a.scm 11 22 33
    ("11" "22" "33")
    % chmod +x a.scm
    % ./a.scm 11 22 33
    ("11" "22" "33")
    % gsc -exe a.scm
    % ./a 11 22 33
    ("11" "22" "33")

Also note that the shebang approach also has an impact on the value returned by (command-line)… the file with the shebang will be returned at the head of the list.  So with:

    #! /usr/bin/env gsi
    (define (main . args) (pp (command-line)))

you will get:

    % gsi a.scm 11 22 33
    ("/Users/feeley/a.scm" "11" "22" "33")
    % ./a.scm 11 22 33
    ("/Users/feeley/a.scm" "11" "22" "33")
    % gsc -exe a.scm
    % ./a 11 22 33
    ("./a" "11" "22" "33")

which allows the program to get the location of the script or executable with

    (path-directory (path-normalize (car (command-line))))

The compiler is smart enough to take the shebang line’s gsi runtime options (of the form -:…) and compile them into the executable as the default runtime options.  For example, if you compile the following a.scm file:

    #! /usr/bin/env gsi
    (define (main x y) (pp (/ (string->number x) (string->number y))))

you get an executable that will report run time exceptions by default:

    % ./a 42 2
    21
    % ./a 42 0
    *** ERROR IN main -- Divide by zero
    (/ 42 0)
    % echo $?
    70

And if you add the -:d0 runtime option (verbosity level = 0), then run time exceptions are not reported by default:

    #! /usr/bin/env gsi -:d0
    (define (main x y) (pp (/ (string->number x) (string->number y))))

You will get:

    % ./a 42 0
    % echo $?
    70
    % ./a -:d1 42 0
    *** ERROR IN main -- Divide by zero
    (/ 42 0)

I guess the -- option would still be convenient for situations where a shebang line is awkward.  But should that automatically call the “main” function as is the case when a shebang is present?  And adding this interferes with the Scheme program’s ad-hoc command line parsing (it can’t “see” a -- option which might be relevant to its own command line parsing logic).

As for --enable-absolute-shared-libs, I think that may do what you want.  Here is the description from INSTALL.txt:

When --enable-shared is used, the option --enable-absolute-shared-libs
will install executables (for gsi and gsc) which contain references to
the absolute paths of the libraries.  This is necessary when multiple
versions of Gambit are installed so that each executable refers to the
appropriate Gambit shared library.

Marc



> On May 14, 2017, at 1:42 AM, Faré <fahree at gmail.com> wrote:
> 
> Dear Marc & gambiteers,
> 
>>> Could the install path from the --prefix option be included in the
>>> binary, or is there a good reason not to?
>> 
>> Yes it is a good idea.  Can you make the appropriate changes to the configure script and makefiles, and send in a pull request?
>> 
> I see an option --enable-absolute-shared-libs -- would it be doing
> what I want already, or is it different? What does it do?
> 
> I see that gsi does not have long options (e.g. --eval for -e) nor a
> help option, nor seemingly a fully general purpose declarative option
> parser. Is it on purpose (e.g. for size), or would you accept a patch
> that implement them? Maybe also a --load to directly load more than
> one file, in order? And a -- to terminate arguments so that user
> programs be provided arguments when no file was provided? In my
> dealing with Common Lisp invocation from the command line I found that
> these were a great way to let users invoke Lisp code from outside
> Lisp. There again, would you accept a patch to implement these?
> 
> Also, is there a way from a gsi in the $PATH to extract the
> installation path of gambit? Say with a suitable -e argument.
> 
> —♯ƒ • François-René ÐVB Rideau •Reflection&Cybernethics• http://fare.tunes.org
> Each new generation born is in effect an invasion of civilization by little
> barbarians, who must be civilized before it is too late. — Thomas Sowell



More information about the Gambit-list mailing list