RE: Eu's poor design
- Posted by Andreas Rumpf <pfropfen at gmx.net> Aug 17, 2003
- 467 views
jbrown105 at speedymail.org wrote: > > > On Sun, Aug 17, 2003 at 07:41:01PM +0000, Andreas Rumpf wrote: > > > > > > > (making a stack in Eu is easy) > > Let's see the stack in Eu: > > > > sequence stack > > stack = {} > > > > function push(sequence stack, object item) > > return stack = append(stack, item) > > this is wrong, btw. should be: > > stack = append(stack, item) > return stack Yes, as I said I should stop coding in topica windows. > > > end function > > > > function pop(sequence stack) -- returns stack without top > > No, the pop removes the top of the stack, and then returns the part it > removed. Not necessarily. > > > return stack[1..length(stack)-1] > > end function > > > > function topOfStack(sequence stack) > > return stack[length(stack)] > > end function > > > > Yes, quite easy. But what if I want to make it easier and more > > efficient? (Using push()/pop() that modify the stack directly!) Guess > > what, it can't be done in Eu. > > Wrong. > > sequence stack > stack = {} > > procedure push(object item) > stack = append(stack, item) > end procedure > function pop() > object item > item = stack[length(stack)] > stack = stack[1..length(stack)-1] > return item > end function > > or with your version of pop() and topOfStack() (which is wrong btw) > > function pop() > return stack[1..length(stack)-1] > end function > function topOfStack() > return stack[length(stack)] > end function So, you used a global variable... (And proved one of my earlier posts...) What if I want to have 2 different stacks? - Use a sequence of stacks and pass the routines the index of the stack to work with. This is a solution. But it simulates pbr! So why not have it directly? > > Again, in Pascal/C/etc. I have choice how to implement certain things! > > You can't even write a swap() routine, because of lack of pbr! > > Well C has no pbr. It has simulated pbr via pointers. Ok, forget about C. What about Basic/Ada/C++? > > Yes, the inability to have a swap() routine is annoying. Very much so. > Of course this could also be solved via macros ... > > object tmp > macro swap(a,b) tmp = a a = b b = tmp > ... > swap(var_one, var_two) > > but only because the macro is rewritten as > > tmp = var_one var_one = var_two var_two = tmp > > so even the macro simulates pass-by-reference! Let's implement a macro facility instead of pbr! (Irony)