5
\$\begingroup\$

I'm new to this code-golfing thing and I'm very interested in CJam.

Is there a way to get all the current stack as an array? I think I can do it with something like [1$ 2$...n$] but I would have to get the stack's length and use some kind of iterator (or use a fixed length stack... useless). But is there a way to achieve this with a single operator? The thing is I want to iterate over all the stack's elements.

Sorry if the question is obvious or seems stupid, but I'm new to this and I couldn't find anything...

\$\endgroup\$
10
  • \$\begingroup\$ or use a fixed length stack... useless Oftentimes you do know how many items are going to be on the stack at a given time. \$\endgroup\$ Commented May 25, 2017 at 1:00
  • \$\begingroup\$ This would probably be more on-topic for Stack Overflow. \$\endgroup\$ Commented May 25, 2017 at 1:01
  • 2
    \$\begingroup\$ @Challenger5 Tips questions in general are perfectly on topic here. While some esoteric languages have found a way to SO, I doubt CJam questions would be well-received. \$\endgroup\$
    – Dennis
    Commented May 25, 2017 at 2:20
  • 2
    \$\begingroup\$ Welcome to PPCG! This is covered on cjam.readthedocs.io/en/latest, which you'll probably find useful if you're interested in learning CJam. By the way, once you earn 20 reputation, you'll be able to join us in chat. Simple questions like this one will be answered quickly in The Nineteenth Byte. \$\endgroup\$
    – Dennis
    Commented May 25, 2017 at 2:23
  • \$\begingroup\$ @Dennis Thanks. (That 11 below my username is actually my reputation, isn't it? idk I don't really understand how all this StackExchange thing work) \$\endgroup\$
    – Iaka Noe
    Commented May 25, 2017 at 2:26

1 Answer 1

4
\$\begingroup\$

An unmatched ] command will make the entire stack into an array.

1 2 3 4 ] -> [1 2 3 4]
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.