[gambit-list] Puzzlement (different behavior of compiled code)

David Rush kumoyuki at gmail.com
Sat Jun 9 17:52:17 EDT 2012

With Gambit 4.6.6, I am seeing decidedly different behavior for
open-output-file between code compiled with gsc/gcc to run as a
standalone executable and that same code compiled with gsc to run
under gsi. The source code follows the body of the message, but the
error from the standalone run tells the whole story, really.

drr at dibbuk$ make target=gambit test/bug.gambit
gsc -:s -link test/bug.Gambit
gcc -I/home/drr/include test/bug.c test/bug_.c -o test/bug.gambit \
		-L/home/drr/lib -lgambc -lm -lutil -ldl
drr at dibbuk$ test/bug.gambit
*** ERROR IN flog-file -- (Argument 1) STRING or port settings expected
(open-output-file '(|path:| "test.flog" |create:| maybe |append:| #t))

drr at dibbuk$ gsc test/bug.Gambit
drr at dibbuk$ gsi
Gambit v4.6.6

> (load "test/bug")
> (main (vector "this is a test"))
> (exit)
drr at dibbuk$ cat test.flog
this is a test
this is a test

Now the repeated lines in test.flog are expected from the gsi case
because the code is effectively run twice, once upon load and once
manually (as will be seen from the source below). So what is going on
with the standalone execution? I am very puzzled.

the source code for bug.Gambit. This is the output of a preprocessor,
so it looks a little strange, but it is really very straightforward.

(define _cons_23 cons)
(define *flog-use-current-output-port* #f)
(define *flog-use-current-error-port* #f)

    (_file-name_38 _s_39)
       (begin (display _s_39 _f_40)
              (newline _f_40)
              (if *flog-use-current-output-port*
                  (display _s_39 (current-output-port)))
              (if *flog-use-current-error-port*
                  (display _s_39 (current-error-port)))
              (close-output-port _f_40)))
         (quote path:)
           (quote (create: maybe append: #t))))))))

      (flog-file "test.flog" "this is a test")

(main (command-line))

More information about the Gambit-list mailing list