This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

learning scheme with kawa


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]