learning scheme with kawa

Debabrata Pani debabrata.pani@gmail.com
Sun Oct 25 17:59:00 GMT 2015


Hi,

I was reading The Scheme Programming Language 4th Edition and
practicing on Kawa. I wanted to use kawa because it sits atop jvm and
this can help in leveraging my experience in using java apis.

I ran into some issues while solving the following exercise

Exercise 2.7.2 had you use length in the definition of shorter, which
returns the shorter of its two list arguments, or the first if the two
have the same length. Write shorter without using length. [Hint:
Define a recursive helper, shorter?, and use it in place of the length
comparison.]

(reference : http://scheme.com/tspl4/start.html#./start:h2)

I wrote up the following(see below) in a file reciprocal.ss . The
expectation was that the out of order definition (of shorter and
shorter?) should not matter.

(define shorter
;; (shorter ‘(a b c) ‘(d e f g)) => (a b c)
;; (shorter ‘(a b c) ‘(d e f)) => (a b c)
;; (shorter ‘(a b c) ‘(d e)) => (d e)
;; don’t use the length function
(lambda (l1 l2)
(let ((val (shorter? l1 l2)))
(if (= 0 val)
l1
l2))))

(define shorter?
(lambda (l1 l2)
(if (null? l1)
0
(if (null? l2)
1
(shorter? (cdr l1) (cdr l2))))))

But in KAWA it does matter.

I got the following error:
|kawa:1|# (load “reciprocal.ss”)

reciprocal.ss:67:20: call to ‘shorter?’ has too many arguments (2; must be 1)
|kawa:2|# (shorter ‘(a b) ‘(d e f))

/dev/stdin:2:1: warning - no declaration seen for shorter
/dev/stdin:2:1: unbound location: shorter
at gnu.mapping.SharedLocation.get(SharedLocation.java:22)
at gnu.mapping.DynamicLocation.get(DynamicLocation.java:28)
at atInteractiveLevel$13.run(stdin:2)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:317)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:219)
at kawa.Shell.run(Shell.java:291)
at kawa.Shell.run(Shell.java:203)
at kawa.Shell.run(Shell.java:184)
at kawa.repl.main(repl.java:892)
|kawa:3|

But in Chicken scheme, I am able to go through :
;4> (load “reciprocal.ss”)

; loading reciprocal.ss …
;5> (shorter ‘(a b) ‘(d e f))

(a b)
;6>

I get the same error when executing the script using kawa

java -cp "/usr/local/Cellar/kawa/2.0/kawa-2.0.jar" kawa.repl -f reciprocal.ss
reciprocal.ss:67:20: call to 'shorter?' has too many arguments (2; must be 1)
reciprocal.ss:80:10: warning - no declaration seen for shorter
reciprocal.ss:80:10: unbound location: shorter
    at gnu.mapping.SharedLocation.get(SharedLocation.java:22)
    at gnu.mapping.DynamicLocation.get(DynamicLocation.java:28)
    at atInteractiveLevel$11.run(reciprocal.ss:80)
    at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:317)
    at gnu.expr.ModuleExp.evalModule(ModuleExp.java:219)
    at kawa.Shell.run(Shell.java:291)
    at kawa.Shell.runFile(Shell.java:523)
    at kawa.Shell.runFileOrClass(Shell.java:447)
    at kawa.repl.processArgs(repl.java:260)
    at kawa.repl.main(repl.java:871)


Query

Is this a known discrepancy in the behavior of kawa?

Are we violating any RNRS rule when we do this ?


Regards,

Debabrata Pani



More information about the Kawa mailing list