Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Immutable data structures

Name: Anonymous 2018-12-03 18:54

How do you implement a POP operation on a STACK without returning multiple values?

Name: Anonymous 2018-12-03 19:11

huh?
pop should only return one value

this is a very poorly-written question

Name: Anonymous 2018-12-03 19:11

also why tf would a stack be immutable

Name: Anonymous 2018-12-03 21:40

>>2
Pop in an immutable stack would return the top element + the new state of the stack.

>>1
You would not, why would you do that?
That being said, try the state monad.

Name: Anonymous 2018-12-04 0:48

>>4
Pop in an immutable stack would return the top element + the new state of the stack.
that's retarded af, just use a mutable stack instead

Name: Anonymous 2018-12-04 0:50

not sure why you wouldn't want to modify the original one, but I guess an immutable stack would just create a new stack object and populate it with the same shit in the original one, sans the top thing to be popped

I guess you could use a generic class array, like Object[], and the popped value would be index 0, and the new stack would be index 1

Name: Anonymous 2018-12-04 5:04

Like >>6 implies, an immutable stack may as well just be an immutable linked list (like Haskell lists). You can efficiently pop and push the top (aka front) element, and previous iterations of the stack will still be perfectly valid in memory.

Name: Anonymous 2018-12-04 8:31

You cannot mutate the stack. The language is purely functional with immutable objects.

Name: Anonymous 2018-12-04 10:03

>>8
my anus is purely functional and can't be mutated

Name: Anonymous 2018-12-04 10:23

x

Name: Anonymous 2018-12-04 10:24

x

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List