From: Jamison Hope <jrh@theptrgroup.com>
To: kawa mailing list <kawa@sourceware.org>
Subject: Re: conditional bindings
Date: Tue, 09 Dec 2014 21:16:00 -0000 [thread overview]
Message-ID: <8FDA27DC-2AC0-442E-879B-390760EAC000@theptrgroup.com> (raw)
In-Reply-To: <54868D3A.10605@bothner.com>
On Dec 9, 2014, at 12:48 AM, Per Bothner <per@bothner.com> wrote:
> The syntax (? NAME::TYPE VALUE) can be used in conditional forms:
> if, and, cond, etc. First VALUE is evaluated. Then if the result
> is an compatible with TYPE, then NAME is bound to the result
> (possibly after conversion). The result is #t, but with the "side effect"
> that NAME is lexically bound in "following forms". If VALUE doesn't
> match TYPE then the ?-form is false.
Is the result actually #t, or some unspecified true value? Is something
like this supposed to work?
#|kawa:1|# (define (f x) (cond ((? r ::real x) => (lambda (y) y)) (else #f)))
/dev/stdin:1:22: '?' is only allowed in a conditional e.g. 'if' or 'and'
Types backed by Java primitives seem to be troublesome. I get VerifyErrors
("Bad type on operand stack") with the following:
(define (f x) (if (? b ::boolean x) b #f))
(define (f x) (if (? c ::character x) c #\?))
What types of implicit conversions are to be expected? I find the
difference between these to be slightly unintuitive.
#|kawa:5|# (map (lambda (x) (if (? i ::int x) i -1)) '(3 "hello" 3.5 #\?))
(3 -1 3 -1)
#|kawa:6|# (map (lambda (x) (if (? i ::integer x) i -1)) '(3 "hello" 3.5 #\?))
(3 -1 -1 -1)
Note that 3.5 becomes int 3, but not integer 3.
#|kawa:7|# (map (lambda (x) (if (? s ::string x) s "N/A")) '(3 "hello" 3.5 #\?))
(N/A hello N/A N/A)
but
#|kawa:8|# (map (lambda (x) (if (? s ::String x) s "N/A")) '(3 "hello" 3.5 #\?))
Exception in thread "main" java.lang.NoClassDefFoundError: String
--
Jamison Hope
The PTR Group
www.theptrgroup.com
next prev parent reply other threads:[~2014-12-09 21:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-09 5:48 Per Bothner
2014-12-09 21:16 ` Jamison Hope [this message]
2014-12-10 3:25 ` Per Bothner
2014-12-11 4:05 ` Jamison Hope
2014-12-11 4:38 ` Per Bothner
2014-12-11 16:43 ` Jamison Hope
2014-12-11 18:37 ` Per Bothner
2014-12-11 22:43 ` Jamison Hope
2014-12-11 23:16 ` Per Bothner
2014-12-12 5:07 ` Per Bothner
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=8FDA27DC-2AC0-442E-879B-390760EAC000@theptrgroup.com \
--to=jrh@theptrgroup.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).