public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* The command line option --script
@ 2024-01-04  3:16 伊藤一光
  2024-01-04  5:46 ` Per Bothner
  0 siblings, 1 reply; 2+ messages in thread
From: 伊藤一光 @ 2024-01-04  3:16 UTC (permalink / raw)
  To: kawa

[-- Attachment #1: Type: text/plain, Size: 918 bytes --]

I remember reading some explanation about the command line option
"--script", but I do not fully understand it. Now I have got a script which
shows significantly different results depending on whether it is run with
or without "--script".  I would like to know how this happens.

Here is my test case.

$ java kawa.repl -e '(scheme-implementation-version)'
3.1.1 (git describe: 3.1.1-0-gc47de33ad)$
$ cat 0.scm
(include "01.scm")
(include "02.scm")
(display (format #f "~a ~a ~a ~%" a1 a2 aa))
$ cat 01.scm
;; This is 01.scm
(define aa '())

(define-syntax define-a
  (syntax-rules ()
    ((_ a p)
       (begin
          (define a p)
          (set! aa (cons a aa))))))
$ cat 02.scm
;; This is 02.scm
(define-a a1 1)
(define-a a2 2)
$ java kawa.repl 0.scm
1 2 (2 1)
$ java kawa.repl --script 0.scm
/home/kaz/02.scm:3:1: duplicate declaration of 'aa'
/home/kaz/02.scm:3:1: (this is the previous declaration of 'aa')
$

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: The command line option --script
  2024-01-04  3:16 The command line option --script 伊藤一光
@ 2024-01-04  5:46 ` Per Bothner
  0 siblings, 0 replies; 2+ messages in thread
From: Per Bothner @ 2024-01-04  5:46 UTC (permalink / raw)
  To: 伊藤一光, kawa



On 1/3/24 19:16, 伊藤一光 via Kawa wrote:
> I remember reading some explanation about the command line option
> "--script", but I do not fully understand it.

Yes, the Kawa documentation doesn't explain this properly.

Basically, the difference is that --script causes the file to be
processed line-by-line. This means that the Kawa evaluates each line in order.
A "line" in this context is the minimum non-zero number of complete lines
that comprise a balanced S-expressions (list) or until a reader error occurs.
That line is read, macro-expanded, analyzed, compiled, and evaluated,
before the following line is processed. Each "line" treated as a separate "module".
This is in contrast to the default whole-file mode, where the whole file is read;
all of the resulting S-expressions are macro-expanded, analyzed, and compiled
to a single "module". Only after the whole file has been compiled, then the
whole module is evaluated.

That doesn't explain the error you're seeing, which is because of the
kludge starting at line 73 in kawa/standard/set_b.java.  And that in turn
was to fix this issue: https://gitlab.com/kashell/Kawa/-/issues/44

This is a Kawa bug, but it isn't obvious how to fix it.  The clean/simple
way would probably be to remove the "kludge" in set_b.java. However,
that would presumably re-introduce the issue #44. On the other hand,
trace and untrace are a big kludge that don't go very well with the
compiler-based model of what Kawa is about, so perhaps we should just
give up on them - they only work in limited cases, anyway.

I don't know what the right solution is - and I don't want to spend
a lot of time on it.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-04  5:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-04  3:16 The command line option --script 伊藤一光
2024-01-04  5:46 ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).