A few users suggested that Doors CS contain functions for a stack-type feature. It was originally suggested that it let you push and pop the value of Ans for real and complex numbers. I had originally put it off, but since I've more or less completed the major features and bug-fixes of Doors CS as of DCS 6.8 beta, I figured I might as well implement the Ans stack. It took me somewhere between 300 and 400 bytes, and supports the following variable types:

:: Real Number
:: Complex Number
:: Real List
:: Complex List
:: String
:: Real Matrix

Unfortunately, there's no _CreateTempCMat ROMcall that I could find in any published documentation, so I didn't allow complex matrices. Enjoy this demo code and screenshot of pushing and popping all the different allowable data types.

BASIC Code wrote:
:[[1,100
:sum(14
:{1,3,9
:sum(14
:{1i,1+3i,1.1+9.4i
:sum(14
:"TESTING...
:sum(14
:133337
:sum(14
:"CPLX ^, REAL v
:sum(14
:123+88.9i
:sum(14
:44444444
:For(X,1,7
:sum(15
:Disp Ans
:End
Generated by SourceCoder, © 2005-2010 Cemetech


Note that as per the DCSBLibVersion (sum(5)) routine, only DCSB versions 3 and higher have sum(14) and sum(15) (PushAnsStack and PopAnsStack, respectively).

Nice. I'll think of a use for it soon enough Smile
What are the size limits, and what is returned if the stack is empty? Does the stack persist? It there a way to empty the stack completely?
merthsoft wrote:
What are the size limits, and what is returned if the stack is empty? Does the stack persist? It there a way to empty the stack completely?
Size limits: Free memory. If the stack is empty, Ans is retained as-is. The stack persists. There is no way to empty the stack currently; I will add that as sum(16), because that's pretty important if some other programmer failed to empty the stack properly.
KermMartian wrote:
There is no way to empty the stack currently; I will add that as sum(16), because that's pretty important if some other programmer failed to empty the stack properly.
Great, I see that being a pretty useful feature. The stack in general is pretty useful.
merthsoft wrote:
KermMartian wrote:
There is no way to empty the stack currently; I will add that as sum(16), because that's pretty important if some other programmer failed to empty the stack properly.
Great, I see that being a pretty useful feature. The stack in general is pretty useful.
Haha, most certainly agreed. I can see this helping to remove a lot of variable use in some programs.
How hard would it be/would you add a feature that allows you to swap items in the stack?
Like if you're stack is {1, 2, 3} and you say swap() it's {1, 3, 2} and if you say swap(2) it becomes {2, 3 1}?
merthsoft wrote:
How hard would it be/would you add a feature that allows you to swap items in the stack?
Like if you're stack is {1, 2, 3} and you say swap() it's {1, 3, 2} and if you say swap(2) it becomes {2, 3 1}?
Fairly non-trivial, but I'll consider it. What would something like that be useful for, Merth?
One use I envision for the AnsStack is to make an RPN program Smile
calcdude84se wrote:
One use I envision for the AnsStack is to make an RPN program Smile
Yeah, I was actually thinking of doing that myself as a demo. Think that would be a good idea.
KermMartian wrote:
merthsoft wrote:
How hard would it be/would you add a feature that allows you to swap items in the stack?
Like if you're stack is {1, 2, 3} and you say swap() it's {1, 3, 2} and if you say swap(2) it becomes {2, 3 1}?
Fairly non-trivial, but I'll consider it. What would something like that be useful for, Merth?

Do you remember that stack-based assembly language my friend had made? Well, I made Conway's Game of Life with it, and swap() was one of the most useful functions. I can think of ways to implement it in BASIC, but this'll be quicker. I'm not sure off the top of my head how this would be used in this context, but I like the idea of having it around.
I do indeed remember that. I'm still somewhat hesitant to implement swapping though; I think I'll leave it up to a programmer that needs that to implement swapping as they see fit for their application. I will add sum(16) as a ClearAnsStack command though.
That's perfectly reasonable.
merthsoft wrote:
That's perfectly reasonable.
Glad to hear it. I'm going to declare the AnsStack done for now, until someone gets to test it; it now has sum(14), PushAnsStack, sum(15), PopAnsStack, and sum(16), ClearAnsStack. I don't suppose one of you would be interested in trying to use it for an RPN calculator?
KermMartian wrote:
merthsoft wrote:
That's perfectly reasonable.
Glad to hear it. I'm going to declare the AnsStack done for now, until someone gets to test it; it now has sum(14), PushAnsStack, sum(15), PopAnsStack, and sum(16), ClearAnsStack. I don't suppose one of you would be interested in trying to use it for an RPN calculator?
I'll do some testing. I can try the RPN calc.
Thanks Merth, much appreciated. Here's the .8xk for you to try out (and the rest of you are of course welcome to try it as well). The usual stability caveats for betas apply, of course.

http://www.cemetech.net/files/dcs6.8.2_beta.8xk
Alright, I've made an RPN calculator. I put the logic for each type of command in a different program (this makes it easier, in my mind, to add features).
Here's a screen shot:

There's no error checking right now (like if the stack is empty, etc.), but it works. Also, there's a bug in DCS that if you try to do expr("-") or anything that's not a number, really, the calc crashes, so be extra careful when using this.
Currently supported operators are:
+ - * / ^ !
these do what you'd expect
++ --
increment and decrement operators
R
Repeat the last command
P
Peek at the top item of the stack
T
Toss the top item of the stack
C
Copy the top item of the stack

More to come!

And source coder should update those posts under soon.


The main program (RPN):http://sc.cemetech.net/?xpi=660c5011922907aa05856cfa51a2fbb5
The logic (RPNL):http://sc.cemetech.net/?xpi=f59ab6127f3e94ae42f6bfab31774a9b
RPN
KermMartian has just edited this program. The source code now reads:
BASIC Code wrote:
:sum(16
:"EOS
:sum(14
:Disp "'Q' to quit
:Input ":",Str1
:While Str1≠"Q
:If sub(Str1,length(Str1),1)≠",
:Str1+",→Str1
:1→I
:inString(Str1,",→J
:While J
:sub(Str1,I,J-I→Str2
:prgmRPNL
:sum(14
:J+1→I
:inString(Str1,",",I→J
:End
:sum(15
:Disp Ans
:sum(14
:Input ":",Str1
:End
:sum(16
Generated by SourceCoder, © 2005-2010 Cemetech
This is an automatic post from SourceCoder 2. Report abuse to admin@cemetech.net . You can disable these posts by unchecking the "Post on Update" box in the file's permissions.
RPNL
KermMartian has just edited this program. The source code now reads:
BASIC Code wrote:
:If Str2="+
:Then
:sum(15)+sum(15
:Else
:If Str2="-
:Then
:sum(15→A
:sum(15)-A
:Else
:If Str2="*
:Then
:sum(15)*sum(15
:Else
:If Str2="/
:Then
:sum(15→A
:sum(15)/A
:Else
:If Str2="!
:Then
:sum(15)!
:Else
:If Str2="^
:Then
:sum(15→A
:sum(15)^A
:Else
:expr(Str2
:End
Generated by SourceCoder, © 2005-2010 Cemetech
This is an automatic post from SourceCoder 2. Report abuse to admin@cemetech.net . You can disable these posts by unchecking the "Post on Update" box in the file's permissions.
RPN
merthsoft has just edited this program. The source code now reads:
BASIC Code wrote:
:If 1337≠det([[42
:Then
:Disp "Please install
:Disp "DCS7
:End
:If 2>sum(5
:Then
:Disp "Please install
:Disp "DCS7
:End
:sum(16
:"EOS
:sum(14
:Disp "'Q' to quit
:Input ":",Str1
:While Str1≠"Q
:If sub(Str1,length(Str1),1)≠",
:Str1+",→Str1
:1→I
:inString(Str1,",→J
:While J
:sub(Str1,I,J-I→Str2
:prgmRPNL
:If P=0
:sum(14
:J+1→I
:inString(Str1,",",I→J
:End
:sum(15
:Disp Ans
:sum(14
:Input ":",Str1
:End
:sum(16
Generated by SourceCoder, © 2005-2010 Cemetech
This is an automatic post from SourceCoder 2. Report abuse to admin@cemetech.net . You can disable these posts by unchecking the "Post on Update" box in the file's permissions.
  
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 2
» 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