Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMT (Generative Modeling Technologies) » [MOFScript] functions
[MOFScript] functions [message #377481] Thu, 10 May 2007 11:04 Go to next message
Andy Carpenter is currently offline Andy Carpenter
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) {
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
Re: [MOFScript] functions [message #377485 is a reply to message #377481] Fri, 11 May 2007 08:01 Go to previous messageGo to next message
Gøran K. Olsen is currently offline Gøran K. Olsen
Messages: 184
Registered: July 2009
Senior Member
Hello,

There is a function in MOFScript that you can use to handle this. The
example bellow should do the work.

self.elements->forEach(element) between (',') {
element.output()
}


/G
Re: [MOFScript] functions [message #377487 is a reply to message #377485] Fri, 11 May 2007 10:25 Go to previous message
Andy Carpenter is currently offline Andy Carpenter
Messages: 145
Registered: July 2009
Senior Member
G
Re: [MOFScript] functions [message #596131 is a reply to message #377481] Fri, 11 May 2007 08:01 Go to previous message
Gøran K. Olsen is currently offline Gøran K. Olsen
Messages: 184
Registered: July 2009
Senior Member
Hello,

There is a function in MOFScript that you can use to handle this. The
example bellow should do the work.

self.elements->forEach(element) between (',') {
element.output()
}


/G
Re: [MOFScript] functions [message #596138 is a reply to message #377485] Fri, 11 May 2007 10:25 Go to previous message
Andy Carpenter is currently offline Andy Carpenter
Messages: 145
Registered: July 2009
Senior Member
G
Previous Topic:[TCS] How to do a substring ?
Next Topic:[MOFScript] undefined properties
Goto Forum:
  


Current Time: Thu Oct 02 14:47:57 GMT 2014

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

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