Results
|
Choice
|
Votes
|
|
Percent
|
Buy another calculator
|
7
|
6.1%
|
|
Buy two more calculators
|
1
|
0.9%
|
|
Buy three more calculators
|
5
|
4.4%
|
|
1920x1080
|
21
|
18.4%
|
|
Become a better programmer
|
80
|
70.2%
|
|
|
Re: What is your New Year's resolution?
|
lifeiscalc
|
Become a better programmer has been my resolution for the past 5 years... It is something I will do anyway, so it is a good resolution.
|
Reply to this comment
|
2 January 2009, 15:46 GMT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Re: Re: Re: Re: What is your New Year's resolution?
|
Rob van Wijk
(Web Page)
|
To answer his other question: yes, something like While ... Goto A ... End will cause the exact same error, for similar reasons.
== Solution 1 ==
When jumping out of an If ... Then block, embed the target label into a dummy If ... Then block:
:If 0:Then
:Lbl X
:End
If you're jumping out of nested logic, nest the dummies accordingly. I learned this trick from a program which had the following code:
:If 0:Then
:If 0:Then
:Lbl X
:End:End
== Solution 2 ==
Don't use Goto, it is evil (or "harmful", depending on who you ask :P ). Check the page I linked.
== On a slightly related note ==
Hmm, need to dust of an Z80-calc, because now suddenly I wonder what the following code would do:
:While 1
:Disp "1"
:Goto 2
:Disp "3"
:Stop
:End
:Lbl 2
:Disp "2"
:End
If this does what I think (hope) it will do, that would mean we could (hackishly) implement procedure calls!
|
Reply to this comment
|
23 January 2009, 14:32 GMT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re(10): What is your New Year's resolution?
|
Rob van Wijk
|
> One technique is to have a single program call itself and use a variable of some sort (or maybe Ans) to indicate which routine to run.
You really don't like headaches, do you? You won't use my wonderfully contrived, possibly-unstable hack which will strip any remaining readability from your program just because you've got a pretty straight-forward, completely clean and kinda readable alternative...? :(
Seriously though, thank you for the advice Travis! It will require a little bit of mucking about to determine whether the program was just started for the first time, or if it was called to perform a subroutine, but that's the only downside as far as I can see. (A "wee bit less" than the downsides of my hack, to put it mildly.)
To determine whether your program just started, I suggest the following:
:If Ans=sqrt(42)
:Then
: [start program]
: [foo]
: [bar]
: 1->Z:sqrt(42)
: prgmSELF
: [more stuff]
:Else
: [determine which procedure to start, based on value of Z]
:End
Just choose a value that's easy to calculate to denote your program is already running. By putting it in Ans (instead of a variable which keeps it value until explicitly overwritten), you can be almost sure it won't be there by accident. For instance, a user has to break your program using On, at the exact moment after Ans was assigned, but before the next expression is evaluated and then immediately start the program again to accidentally (doing it on purpose is pretty easy) make the program think it was already running.
|
Reply to this comment
|
31 January 2009, 23:24 GMT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Re: Re: Re: Re: Re: What is your New Year's resolution?
|
Rob van Wijk
|
Argh, the interpreter (at least the one in an 83) is just a little too smart... :( Executing the following program
:ClrHome
:Disp "A"
:1->Z
:While Z
:Goto 2
:End
:Disp "C"
:Stop
:Lbl 2
:Disp "B"
:0->Z
:End
:Disp "OOPS"
will output A, B, OOPS. When checking the condition again, it will remember where it found the End. So, to use a procedure, the following hack is needed:
:ClrHome
:Disp "A"
:2->Z
:While Z
:If Z=2
:Goto 2
:0->Z
:End
:Disp "C"
:Stop
:Lbl 2
:Disp "B"
:1->Z
:End
This /will/ output A, B, C. So, here's the general recipe for a procedure:
:SomeCode1
:Call Proc
:SomeCode2
:Stop
:CodeForProc
will turn into
:SomeCode1
:2->dummy
:While dummy
:If dummy=2
:Goto Proc
:0->dummy
:End
:SomeCode2
:Stop
:Lbl Proc
:CodeForProc
:1->dummy
:End
Pro:
- You get the functionality of procedures (or, using (for instance) Ans, functions).
Con:
- Procedure needs to know which dummy to use
- Becomes a horrible mess if you want to allow one procedure to call another (you'd need separate dummies).
- The "horrible mess" mentioned above will seem peanuts when you want to allow a procedure to call itself (maybe use a list of dummies and use one variable as a "stack pointer" telling which item in the list to use??).
Conclusion: proof-of-concept: yes, usable in real life: no :(
[ps. This is not off-topic of course; I voted I wanted to become a better programmer ;) ]
|
Reply to this comment
|
25 January 2009, 19:29 GMT
|
|
Re: What is your New Year's resolution?
|
mdsb
(Web Page)
|
Voted to get another calculator though it is not at the top of what I would wish for this year. The top of my plans relate to reading.
A 92+ would be the calculator I would prefer.
|
Reply to this comment
|
2 January 2009, 22:04 GMT
|
|
Re: What is your New Year's resolution?
|
The_One_Guy
|
There's no doubt that I will become a better programmer with Computer Science as my major, but I may, sadly, be moving out of the relm of calculators and on to bigger things.
|
Reply to this comment
|
4 January 2009, 13:38 GMT
|
|
1 2 3
You can change the number of comments per page in Account Preferences.
|