Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Curious About: Cyclinglink assigns value to simple-object property

So just like the title says, I spent the day working on a widget that behaves the same way as a <<cyclinglink>>, and will also assign a value to a simple object's property, (in this case, $senses.smell.desc).

I got it working, fine, but I was curious about a quirk I stumbled over along the way.

This doesn't work:
@<;</widget>>

But this does:
@<;</widget>>

I've tried a bunch of different variations, and finally, while typing this all out, I found the only way I can get it to print out (let alone, work) correctly.

A works. B doesn't.
A.
<<= _arr>>
<<set _arr = _arr.push(_arr.shift())>>
<<set _arr = $args>> /% reinitialize? %/
<<= _arr>>

B.
<<= _arr>>
<<set _arr = _arr.push(_arr.shift())>>
<<= _arr>>

I'm curious what's happening to _arr here, because it seems to me that in the process of 'talking to' the $args, _arr is getting turned into an integer, which appears to be the length of $args at the time that the macro was called. (which might explain why it changes to 5 on the first recursion, then to 1 on the second and all subsequent recursions)

Comments

  • Small edit: I say that this does the same thing as a cyclinglink, which is incorrect. If you're trying to assign to variables, I'm not sure if you can use the $ prefix, haven't tested it, not what it's for. Anyway. Now that that's been clarified.
  • edited October 2016
    Oh man. I've been looking at this for half an hour. Then I saw it:
    <<set _arr = _arr.push(_arr.shift())>>
    

    This line isn't right. It should be:
    <<set _arr.push(_arr.shift())>>
    

    What you were doing was overwriting array with the return value of push (which is the length of the array, not its content as you expected). Hence _arr becoming an int. You should have just been pushing.
  • ahhh!!!! Okay! that makes a lot of sense! <3 Thanks so much for your help! I have learned something new, AND I get to move back to my comfort zone of accessing temp variables instead of the args directly.
Sign In or Register to comment.