Skip to content

Modifying a procedure's list argument to a scalar fails

I am not sure, but I believe that the Scheme standard permits a procedure's list argument to be modified within that procedure to a non-list type (such as an integer). However, at least in some instances (example below), Kawa does not seem to permit such modifications. Given that Kawa issues a warning to that effect prior to the error, I suppose it may be intended behavior but I am not sure.

Apart from general clarification, my reason for this query/report is that I hit this feature/bug in attempting to get SLIB working with Kawa.

$ cat w.scm
(import (scheme base)
        (scheme write))

(define (f x)
  (set! x 1729)
  'ok)

(display (f 0))
(newline)

(define (g . x)
  (set! x '(1729))
  'ok)

(display (g 0))
(newline)

(define (h . x)
  (set! x 1729)
  'ok)

(display (h 0))
(newline)
$ kawa w.scm
w.scm:19:11: warning - type integer is incompatible with required type list
w.scm:19:3: warning - cannot convert literal (of type gnu.math.IntNum) to Type list
ok
ok
java.lang.ClassCastException: gnu.math.IntNum cannot be cast to gnu.lists.LList
	at w.h$V(w.scm:19)
	at w.h$check(w.scm:18)
	at gnu.mapping.CallContext.runUntilValue(CallContext.java:656)
	at gnu.mapping.Procedure.apply1(Procedure.java:154)
	at w.run(w.scm:22)
	at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:290)
	at gnu.expr.CompiledModule.evalModule(CompiledModule.java:42)
	at gnu.expr.CompiledModule.evalModule(CompiledModule.java:60)
	at kawa.Shell.runFile(Shell.java:582)
	at kawa.Shell.runFileOrClass(Shell.java:485)
	at kawa.repl.processArgs(repl.java:710)
	at kawa.repl.main(repl.java:830)
$ kawa --version
Kawa 3.1.1 (git describe: 3.1.1-20-g2b9674927-dirty)
Copyright (C) 2020 Per Bothner
$ java -version
openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)
$