Writing to a list?

Rishi Rajalingham's Avatar

Rishi Rajalingham

25 Jan, 2016 08:24 PM

Hi Chris,
Sorry for the torrent of questions lately...
I know you've added list support for the expression parser, but is it also possible to write to a list? In other words, can I initialize a list as "tmp = [0,0,0]", and at some state edit this variable based on another (indexing variable), like "tmp[index] = 1".

I tried this and got an error, so my guess is this is not currently implemented. I thought a not so elegant way around this would be a bunch of variables for each list entry, e.g. "tmp0 = 0; tmp1 = 0; tmp2 = 0;" and then write into them as "tmp${index} = 1" but this kind of string manipulation seems to also not yet be supported.

Am I correct that these kinds of list/string manipulations are not yet supported, or am I simply doing something wrong? just thought I'd check in with you before going to the ultimately uglier solution.

Thanks
Rishi

  1. 1 Posted by Rishi Rajalingh... on 25 Jan, 2016 08:35 PM

    Rishi Rajalingham's Avatar

    Hi Chris,
    Please ignore this. I just realized you've added some functionality to run python code inside the mworks experiment, which is a great workaround for all of these kinds of issues. Thanks a lot for that, it's a great feature.
    Rishi

  2. Support Staff 2 Posted by Christopher Sta... on 25 Jan, 2016 08:44 PM

    Christopher Stawarz's Avatar

    Hi Rishi,

    Am I correct that these kinds of list/string manipulations are not yet supported, or am I simply doing something wrong?

    You're correct: Assignment to lists (and dictionaries) is not yet implemented, but it is on my to-do list.

    I just realized you've added some functionality to run python code inside the mworks experiment, which is a great workaround for all of these kinds of issues.

    Yes, that's probably what I would have recommended, had you not thought of it first :)

    Cheers,
    Chris

  3. Christopher Stawarz closed this discussion on 28 Jan, 2016 02:58 PM.

  4. Support Staff 3 Posted by Christopher Sta... on 30 Mar, 2016 05:16 PM

    Christopher Stawarz's Avatar

    Hi Rishi,

    Assignment to indices/keys of list/dictionary-valued variables is now supported in the nightly build. For more info, see this discussion.

    Cheers,
    Chris

  5. Christopher Stawarz closed this discussion on 11 Apr, 2016 01:49 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac