[MOFScript] functions [message #596111] |
Thu, 10 May 2007 07:04 |
Eclipse User |
|
|
|
I'm outputting a comma separated list within a
forEach iterator and want to append a comma
after all elements, except the last. I thought
that a simple conditional statement might do this: i.e.:
self.elements->forEach(element) {
element.output()
if (position() + 1 < self.elements.size()) {
','
}
}
However, the use of arithmetic expressions in
sub parts of logical expressions seems not to
be allowed and the above gives me a syntax error.
As an alternative I factored out the arithmetic; i.e.:
var lastPosition = self.elements.size() - 1
self.elements->forEach(element) {
element.output()
if (position() < lastPosition) {
','
}
}
Although this works for this example, I now need to
filter the collection and the last element output may
not be at the end of the collection. So, I need a
something like a MOFScript function that indicates
when the last element in the collection is being
processed.
Does anyone know a better approach for the
simple case or how to do the more complicated one.
thanks
Andy.
--
-- ------------------------------------------------------------ -------------
Dr Andy Carpenter
School of Computer Science,
University of Manchester, Manchester M13 9PL, UK
Email: Andy.Carpenter@manchester.ac.uk
Tel: +44 161 275 6168
Fax: +44 161 275 6280
|
|
|
Powered by
FUDForum. Page generated in 0.03134 seconds