Well, I would really like to know how the Ans-stack really works.
As the guide already says, you can push the stack with sum(14), pop it with sum(15) and clear it with sum(16).
But now I run into some problems...
It gives you first of all the opportunity of using 10 stacks, so that you have e.g. Ans0. But how are they called (in program) anyways?
And will it modify the Ans-variable? Or is that somehow stored in Ans?
And how do I define the value of an element, as sum(14) just pushes it without defining values?
Thanks in advance!
Quote:
It gives you first of all the opportunity of using 10 stacks, so that you have e.g. Ans0. But how are they called (in program) anyways?

How do you mean? For pushing and popping them it's a parameter in the sum() call. As for the actual values it's just what's in Ans.
Quote:
And will it modify the Ans-variable? Or is that somehow stored in Ans?

Whatever you pop gets stored to Ans.
Quote:
And how do I define the value of an element, as sum(14) just pushes it without defining values?

It pushes whatever's in Ans. So:

Code:
1+1
sum(14)

Pushes 2 onto the stack. And later on if you do:

Code:
sum(15)

2 is now in Ans, no matter what was in it before.
Good questions, and I'm very happy to see someone interested in using the AnsStack. Merthsoft suggested including it, if I recall correctly, and I think it's a powerful language feature, but unfortunately it hasn't gained that much exposure. To understand the AnsStacks, you first have to understand what a stack is. It's a data structure that you push things to the top of, and pop things off the top of. Every time you push a number on top, the stack gets one element longer, and that number goes on top. The only way to get numbers out again is to pop, which takes the top number off of the stack and returns it.

Doors CS's AnsStacks work specifically with Ans, and they don't just do numbers - they can also work with strings, lists, and matrices. You are always pushing from the Ans variable and popping into the Ans variable, but you can't access the contents of the AnsStacks arbitrarily. Ans0 through Ans9 are ten Ans stacks, if you need more than one for some particular program, but again, you can't access them directly, so they have no name that you can type into your program. You put a value in Ans, and call sum(14) to push it. When you need it again, you call sum(15), and it's popped back into Ans.
Ah..I think I get it!
It can be really useful for some stuff. That are some great libs, the DCS libs!
For an example of it in action, check out my RPN calc:
http://www.cemetech.net/forum/viewtopic.php?p=103870#103870
I know that Ans is the 'magic' variable, capable of having many variable types. Can you do
Code:
1+2+3
sum(14)
{1,2,3}
sum(14)
[[1][2][3]] <- Sure, 68k syntax, not sure if the 8x has the same syntax
sum(14)
"1+2+3"
sum(14)
1+i
sum(14)
Just wondering if all types of data are accepted at the same time.
That code will work perfectly as written with an AnsStack. When you start popping off the AnsStack, you'll get a complex Ans, then a string Ans, then a real matrix Ans, then a real list Ans, and finally a real Ans.
I would like to note that this command is really useful when passing arguments to and from subroutines where you don't want to tie up your variables Smile It makes BASIC seem more ASMish
Xeda112358 wrote:
I would like to note that this command is really useful when passing arguments to and from subroutines where you don't want to tie up your variables Smile It makes BASIC seem more ASMish
Thanks! That was one of the intents of this particular feature. Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement