Dump stack to array



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...

Iaka Noe

Posted 2017-05-25T00:36:01.600

Reputation: 133

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. – Esolanging Fruit – 2017-05-25T01:00:57.147

This would probably be more on-topic for Stack Overflow. – Esolanging Fruit – 2017-05-25T01:01:21.997

2@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. – Dennis – 2017-05-25T02:20:07.510


Welcome to PPCG! This is covered on https://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.

– Dennis – 2017-05-25T02:23:05.990

@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) – Iaka Noe – 2017-05-25T02:26:45.473

Yes, it is. You can also see your reputation in your profile.

– Dennis – 2017-05-25T02:29:03.290

@Dennis What do you mean by well-recieved? AFAIK it's on-topic, but I don't think it would be answered. – Esolanging Fruit – 2017-05-25T02:30:48.713

@Challenger5 Get downvoted or, worse, left unanswered. If it's unlikely to get answered on SO, there really is no reason to post it there. – Dennis – 2017-05-25T02:33:54.867

@Dennis What happened to the [esoteric] tag? – Esolanging Fruit – 2017-05-25T02:34:47.723

@Challenger5 Mind joining me in TNB? – Dennis – 2017-05-25T02:36:31.540



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

1 2 3 4 ] -> [1 2 3 4]

Esolanging Fruit

Posted 2017-05-25T00:36:01.600

Reputation: 13 542