[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.
Specifically:

----------------------------------------------------------------------
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")
"/home/drr/git/heureka/framework/test/bug.o2"
> (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)

(define
  flog-file
  (lambda
    (_file-name_38 _s_39)
    ((lambda
       (_f_40)
       (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)))
     (open-output-file
       (_cons_23
         (quote path:)
         (_cons_23
           _file-name_38
           (quote (create: maybe append: #t))))))))


(define
  main
  (lambda
    (_argv_38)
    (begin
      (flog-file "test.flog" "this is a test")
      )))

(main (command-line))



More information about the Gambit-list mailing list