Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMT (Generative Modeling Technologies) » [MOFScript] functions
[MOFScript] functions [message #596111] Thu, 10 May 2007 11:04
Andy Carpenter is currently offline Andy CarpenterFriend
Messages: 145
Registered: July 2009
Senior Member
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) {
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) {
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

Does anyone know a better approach for the
simple case or how to do the more complicated one.


-- ------------------------------------------------------------ -------------
Dr Andy Carpenter
School of Computer Science,
University of Manchester, Manchester M13 9PL, UK
Tel: +44 161 275 6168
Fax: +44 161 275 6280
Previous Topic:[TCS] How to do a substring ?
Next Topic:[TCS] How to do a substring ?
Goto Forum:

Current Time: Tue Dec 01 22:12:24 GMT 2015

Powered by FUDForum. Page generated in 0.02020 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software