public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Debabrata Pani <debabrata.pani@gmail.com>
To: kawa@sourceware.org
Subject: learning scheme with kawa
Date: Sun, 25 Oct 2015 17:59:00 -0000	[thread overview]
Message-ID: <CAKJw4fdTWByFgD9LW9L2cXSneX9fh7tWHes=jGtYZYL=fVPw2w@mail.gmail.com> (raw)

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

             reply	other threads:[~2015-10-25 17:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-25 17:59 Debabrata Pani [this message]
2015-10-25 18:36 ` Per Bothner
2015-10-26  3:43   ` Debabrata Pani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKJw4fdTWByFgD9LW9L2cXSneX9fh7tWHes=jGtYZYL=fVPw2w@mail.gmail.com' \
    --to=debabrata.pani@gmail.com \
    --cc=kawa@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).