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]

square brackets for sequences in Kawa


I checked in support for using sequence brackets for
creating immutable sequences.  The syntax:
  [exp1 exp2 ... expn]
is roughly equivalent to:
  (vector exp1 exp2 ... expn)
except that the resulting sequence is immutable (constant).
Also:
  #(val1 val2 ... valn)
is more-or-less equivalent to:
  ['val1 'val2 ... 'valn]

If (and when) the expression are evaluated is unspecified: For now
they are evaluated eagerly and in order, but I have ideas for
lazy lists (streams) that might be evaluated in parallel.
I also have ideas for extending this syntax for sequence/loop
operations and list comprehensions.  I hope to discuss these soon.

If an expression [exp1 exp2 ... expn] is used in a compile-time
context where a Java array or a java.util.List is needed, then
an array/List of the appropriate type is created.  This
makes it easier to initialize arrays and lists.  This is
currently limited to a compile-time coercion.  As an example,
see the JAXB/annotation example testsuite/jaxb-annotations3.scm.
(I'm working on a blog/tutorial/how-to about using JAXB.)

The reader syntax [val1 val2 ... valn] is translated to:
  ($bracket-list$ val1 val2 ... valn)
while the reader syntax val0[val1 val2 ... valn] (with no
delimiter before the '[') is translated to:
  ($bracket-apply$ val0 val1 val2 ... valn)
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


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