Comments by Larry Gilbert
cond
within a function defined with def
causes invalid results in all cases, not just in cases where the function is recursive.The doc says that the 'reverse' operator takes an array and returns a new array with the elements reversed. But whenever I try to use it, it's as if it doesn't even exist in the language. In other words, what I end up with on the stack is not a reversed array but the word 'reverse' and a copy of the array I'm trying to reverse!
Help?
Hello Fergus,
I appreciate your help with this! I'll admit that the initial learning curve has been steep for me. It's been so long since I did anything with Polish notation that I'm basically starting over (but I'm learning to appreciate it again, too).
I will study your new example of the cond operator more closely. For right now, here is some code that I think will illustrate the problem I'm having with the reverse operator. And it may either be a bug or just my misunderstanding of how things should work.
set arrayvar ray a1 1 1; set reversedarray reverse #arrayvar; dump; exit;
What I was expecting to see in the dump was reversedarray having the same contents as arrayvar, but in reversed order. Instead, I get this:
[reversedarray] => Array ( [0] => Array ( [0] => b2 [1] => c3 [2] => d4 [3] => e5 [4] => f6 [5] => g7 [6] => h8 ) [1] => reverse )
I have another question, and I'm sorry if this is a trivial one.
I would like to use the shift
command, but it doesn't seem to accept an array, and I need to be able to give it a list of coordinates from an array. Is there any operator that will empty an array and put all of its contents back onto the stack? In other words, is there something that does the inverse of array
?
I hope I am not being a pain yet... Unfortunately, I still can't get things to work the way we expect. I think the point of failure is with the list operator (or how I'm using it). This snippet should reproduce the problem. It ends with strcoords
being empty--not an empty array, just nothing.
set arraycoords ray 0 1; set strcoords list var arraycoords; dump; shift #strcoords;
It still doesn't look like shift will take an array or a 'list'-ed string, but please don't worry about changing that urgently. I've had enough time to think about what I wanted to use shift for, and I think I can do it with a custom, recursive subroutine instead. If you think it needs 'fixing,' go ahead and fix it, but there is no need to do so on my account.
Thanks again for Game Courier. I haven't seen anything quite like it anywhere else on the Web.
9 comments displayed
Permalink to the exact comments currently displayed.