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]

Re: (array index)


Hi,

On Nov 21, 2012, at 9:59 AM, Ito Kazumitsu <kaz@maczuka.gcd.org> wrote:

> Is the syntax (array index) where array is a general sequence object
> explained anywhere in the Kawa Document?

Not that I'm aware of.

> Is it safe to use this syntax for a general sequence object?


As it is currently implemented in ApplyToArgs.java,
CompilationHelpers.java, and Setter.java, apart from arrays, the
syntax will work with any object that implements java.util.List.

It's safe to use, in that this functionality isn't going to go away
any time soon, but it's probably arguable whether it's a good idea
from a code readability standpoint.  From a philosophical/mathematical
viewpoint, it's handy and somewhat elegant to be able to treat any
arbitrary sequence as a function that maps integers to elements, but
it can be surprising if you aren't used to seeing an object treated
like a function.

Somewhere around here I have some local mods that extend the syntax to
CharSequence as well, so that ("abc" 2) => #\c, not so much so that I
can use the functionality as-is from user code, but rather to simplify
the implementation of a generic function like Common Lisp's ELT:

(define (elt sequence index) (sequence index))


By the way, you can also define your ArrayList like this:
#|kawa:1|# (define a (java.util.ArrayList "a" "b" "c"))
#|kawa:2|# a
[a, b, c]

If there are extra arguments not used by the constructor, then Kawa
looks for an "add" method and calls it on each.  That's documented in
the "Allocating Objects" section.


--
Jamison Hope
The PTR Group
www.theptrgroup.com




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