INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Evaluating an expression on each item of a list  (Read 1316 times)

tiberiuspv

  • Recent member
  • *
  • Posts: 49
Evaluating an expression on each item of a list
« on: March 16, 2013, 07:06:13 pm »

Is there a way to evaluate an expression for each item of a list and collect the result into a list? The only method I have seen is to unroll the loop by hand, but this limits you to a fairly small number of items in the list, and is very cumbersome to write and change.

Making each MC expression function handle the list case would be cumbersome for the code writers and painful to QA. A clean (and simple) solution would be to provide a list iterator function looking like this:
        ListForEach(List, expression)
where a new well-known fixed field name (e.g. [ListItem]) is usable inside the expression, just like [R1]..[R9] after a regex. You can of course make it fancier by adding input and output delimiters as in ListCombine.

Here is the exact problem I'm trying to solve. In classical music, artists play a specific instrument (or have a specific voice type) and, for operas, have a role. I'm trying to maintain a single field which contains a list of those triplets (something like {instrument}:{name}={role}; ...), and derive as computed fields in MediaCenter various combinations, such as {name}; ...; {name} for just the artists names, {instrument}\{name};... to lookup, say, all the pianists, or {role}\\{name}; ... to find all the singers which have played a specific role. This is pretty obvious to do with ListForEach and Regex.

Am I missing the obvious? If not, I think this would be a very nice addition to some future version of MC.

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Evaluating an expression on each item of a list
« Reply #1 on: March 16, 2013, 07:37:12 pm »

This has been requested, but it is low priority.  A generalized solution for your particular needs here is RE-based global substitution.

For simple cases, there are workarounds.
Logged
The opinions I express represent my own folly.

tiberiuspv

  • Recent member
  • *
  • Posts: 49
Re: Evaluating an expression on each item of a list
« Reply #2 on: March 16, 2013, 09:58:40 pm »

RE-based global substitution would also solve the problem, it's just substantially more complex. The list iterator is fairly trivial and a good general tool (but less powerful). Maybe some day...

In the meantime, the simplest way I can find is to do a series of regex with intermediate fields. This is a bit brutal, but it's easy to maintain as the intermediate computed fields have the same expression except for the input variable name. From what I have seen of the recent performance optimization of expressions, that should not be too slow.

Side note: I can't follow your link to your wish list - I get an error "The topic or board you are looking for appears to be either missing or off limits to you".
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Evaluating an expression on each item of a list
« Reply #3 on: March 16, 2013, 10:23:36 pm »

I keep forgetting the link is in a beta thread.  I've removed the link.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up