Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: asi14 on March 11, 2014, 11:25:35 pm

Title: Best TI-BASIC command of all time?
Post by: asi14 on March 11, 2014, 11:25:35 pm
What is your fav command in TI-BASIC? Comment for any other commands  :w00t: :w00t: :w00t: :w00t: :w00t: :w00t: :w00t:
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: DJ Omnimaga on March 12, 2014, 12:10:59 am
It's hard to tell considering some are useful in specific places while others are in others. However, it has to be getkey for me, since that's pretty much essential for most decent games.

Also let's avoid titles written in all-caps.
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: TheCoder1998 on March 12, 2014, 02:14:04 am
why is prompt included in the poll?
input is (imo) much better
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: DJ Omnimaga on March 12, 2014, 02:25:32 am
It can be smaller in some cases, though, such as if you want the "H=?" prefix or whatever displays before the ?  without having to enter a string before the var.
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: Lunar Fire on March 12, 2014, 02:35:16 am
I think a "favorite" Basic instruction is a bit of a stupid question. Those commands all serve a purpose and some are more appropriate in a specific context than another. So in a way, all of them are my favorite. Except goto. Go to hell goto. Bring your little brother Lbl along with you please.
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: DJ Omnimaga on March 12, 2014, 02:44:33 am
On the other hand, in one very rare case, Goto is actually faster than While/For-End O.O
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: Lunar Fire on March 12, 2014, 02:51:27 am
Since Goto reads from top to bottom, wouldn't this case be if the Lbl instruction is the very first?

Also, Goto seem to break flow of code and mess up the call stack, so it is not reccomended to use it. For some it is despicable to use it. I tend to keep my code free of gotos, but I know a lot of programmers use them.
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: DJ Omnimaga on March 12, 2014, 02:53:46 am
Indeed, and even then it would not be applicable in the case where you need to do For(Z,0,1000:End, for example.

But yeah I haven't used a Goto in my calc games since June 2004.
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: TheCoder1998 on March 12, 2014, 10:27:29 am
what could be a substitute for goto then?
i find it very useful
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: JWinslow23 on March 12, 2014, 11:00:57 am
Mine would be sum(. I use it all too often in my games. Examples of my code snippets with sum(:

Cookie Clicker:
Code: [Select]
If checkTmr(T
Then
C+checkTmr(T)sum(L1L3->C
startTmr->T
End

Shutdown:
Code: [Select]
Repeat K=45 and sum(L₁
My Snow Demo:
Code: [Select]
If not(sum(L1(D)+1=L1
Then
Output(int(L1(D)),100fPart(L1(D)),"
1+L1(D->L1(D
Ans+.01randInt(~1,1
If fPart(Ans) and fPart(Ans)<.17 and not(sum(Ans=L1
Ans->L1(D
Output(int(L1(D)),100fPart(L1(D)),"*
Else
If D=S
D+1->S
End


Sum is useful. :)
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: dinosteven on March 12, 2014, 11:10:47 am

Personally, I stand by the Case Against Goto: [size=78%]http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF (http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF)[/size]

...but...Quoth Xeda:



Personally, for TI-BASIC and many other languages, I find Goto is excellent. Having written several programming languages and evaluating the code for the TI-BASIC parser, Goto has one main disadvantage and one main advantage, if used properly, and one massive advantage if used improperly like a pro, and one disadvantage if used improperly like a new programmer:


Speed wise, in TI-BASIC, Goto will be slower than While, Repeat, and For(. This is because the BASIC parser stores data in its operator stack telling precisely where to jump upon looping. If I remember correctly, it stores the variable name, and the offset into the variable for where the loop starts. This is still pretty slow, and there are more complicated things that happen, too, but it basically lets the parser use a look-up table (LUT) for loops. Gotos on the other hand must search for the label in the program. If the label is near the end of a program that is >10000 bytes, for example, it will be noticeably slower jumping there than to the beginning. However, this consumes no memory.


There is a misconception that Gotos and Lbls can cause memory errors. This is not true. It is like saying guns kill people. It's not true. They may help, but ultimately, it is somebody else abusing them that causes it. In reality, While, Repeat, and For( cause the memory leaks. Remember how I said that they push data onto an operator stack? That data only get removed on completion of the loop. If you use Goto to improperly exit the loops, then that data doesn't get taken offnot necessarily true; see below and reentering that loop causes it to push again, and again, and again, eventually making you run out of RAM.


Somebody who is versed enough in the TI-BASIC language knows that this can actually be useful for creating a structure not included in TI-BASIC, but should have been -- subroutines. The parser removes an item from the operator stack once it reaches an End. So what you could do is a complicated rebranching of a While loop using Goto:
Code: [Select]


                While A>0 If remainder(A,2 Goto 1 /  | /   | /----------    | Lbl 1              | Disp 1          Disp 0 int(.5A→A       .5A→A End             End
*btw, formatting got off here
Looking at it this way, you see that it won't actually cause a memory leak because the parser doesn't care where or when it comes across an End. As long as it does, reach one, it will jump back to the start of the loop. However, in actual BASIC code, because it is linear, it might look something like the following:
Code: [Select]
While A>0 If remainder(A,2 Goto 1 Disp 0 .5A→A End Lbl 2 <<do stuff now that the loop is over>> Lbl 1 Disp 1 int(.5A→A End Goto 2   ;in case A becomes 0 because of this branch, it doesn't loop back, so we have to manually jump there.
Looking at it this way, you see that it won't actually cause a memory leak because the parser doesn't care where or when it comes across an End. As long as it does, reach one, it will jump back to the start of the loop. However, in actual BASIC code, because it is linear, it might look something like the following:


While this is by no means an efficient application of this idea, here is a program where I used that trick quite a bit to make a subroutine for sprite drawing, saving, and items menu so that I could call the routine at any point in my program without using sub programs or rewriting the routine.


Needless to say, I think Lbl and Goto are very useful. They shouldn't be used in places where While, Repeat, and For( are more efficient, but in TI-BASIC, where efficiency is key, Goto has its place.
[size=78%]






...and, in an effort to be on topic, my favorite command is seq(), with the ability to create lists of all kind, to be manipulated in many ways. It's very versatile.[/size]
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: JWinslow23 on March 12, 2014, 11:27:34 am
Dino, I too think that Goto does have its place (heck, I preferred it over a While loop in my Shutdown game, and then there was this big argument...you had to be there, I guess). It still is kinda inefficient, though; you could use loops instead on most occasions. :/

And I also think that a useful command is Ans. Ans helps for optimizations in both size and speed...it's all-around good.

Finally, I want to expand on Dino's idea of "subroutines". I actually know of code for that (use any label other than S for the subroutine, and any variable you want in the loop instead of S, just make sure the subroutine doesn't modify it!):
Code: [Select]
:ClrHome
:Disp "MAIN PROGRAM
:For(S,-1,0
:If S
:Goto S
:End
:Disp "MAIN AGAIN
:For(S,-1,0
:If S
:Goto S
:End
:Disp "BACK IN MAIN
:Return
:Lbl S
:Disp "SUBROUTINE
:End
This should display MAIN PROGRAM,SUBROUTINE,MAIN AGAIN,SUBROUTINE,BACK IN MAIN on the homescreen in 5 lines.

I have never come across a situation where I'd use this in my programs, but I would if I ever did. I recommend that to other BASIC programmers...it helps. ;)
Title: Re: BEST TI-BASIC COMMAND OF ALL TIME???
Post by: dinosteven on March 12, 2014, 11:58:06 am
Does Ans qualify as a "command", per se? Yeah, it's extremely useful for optimizations, but I'm pretty sure it's categorized as a variable.
Again, I'm anti-Goto, and that was just a copy paste from Xeda on TIBasicDev forums a while back.
Title: Re: Best TI-BASIC command of all time?
Post by: JWinslow23 on March 12, 2014, 04:31:13 pm
Does Ans qualify as a "command", per se? Yeah, it's extremely useful for optimizations, but I'm pretty sure it's categorized as a variable.
Again, I'm anti-Goto, and that was just a copy paste from Xeda on TIBasicDev forums a while back.
It should be, but it isn't. :-\
And I was wondering where I saw that before...
Title: Re: Best TI-BASIC command of all time?
Post by: tifreak on March 12, 2014, 05:18:20 pm
I'd have to say While is by far my favorite command, and I use it for everything. I figured out how to use it to replace Goto/Lbl, and allow me to incorporate subroutines into the main code so I have less sub programs in the menu.
Title: Re: Best TI-BASIC command of all time?
Post by: DJ Omnimaga on March 12, 2014, 11:14:18 pm
On a side note, although it is a bad practice due to the higher risk of data loss by accidentally pressing CLEAR and unreadability of the code, on the color model I like the ":" command separator a lot, because if you merge as many line of code together, it takes much less time to scroll through the code, especially with Doors CSE. I wouldn't recommend this if you plan to edit the code on a monochrome calc or computer, though.

By doing this on the CSE, you can save several minutes in scrolling to the very end of the source code.
Title: Re: Best TI-BASIC command of all time?
Post by: blue_bear_94 on March 12, 2014, 11:43:57 pm
My personal choices would be Repeat (such a shame that it's not in the TI-89 languages) and expr(.
Title: Re: Best TI-BASIC command of all time?
Post by: TheCoder1998 on March 13, 2014, 12:56:02 pm
you could use while instead of repeat right?
instead of "repeat a" just use "while not(a)" right?
Title: Re: Best TI-BASIC command of all time?
Post by: Sorunome on March 13, 2014, 01:20:27 pm
Repeat enters at least once, but while can also be entered zero times.
Title: Re: Best TI-BASIC command of all time?
Post by: JWinslow23 on March 13, 2014, 01:49:04 pm
We should really change this into a "favorite routine" thread!


Mine is a Day of Week calculator (Month, day, and year are M, D, and Y, respectively):
Code: [Select]
:Y-(M<3
:round(7fPart((int(23M/9)+D+4+Y+int(Ans/4)-int(Ans/ᴇ2)+int(Ans/400)-2(M≥3))/7
Title: Re: Best TI-BASIC command of all time?
Post by: DJ Omnimaga on March 13, 2014, 02:05:29 pm
We should really change this into a "favorite routine" thread!


Mine is a Day of Week calculator (Month, day, and year are M, D, and Y, respectively):
Code: [Select]
:Y-(M<3
:round(7fPart((int(23M/9)+D+4+Y+int(Ans/4)-int(Ans/ᴇ2)+int(Ans/400)-2(M≥3))/7
I'm pretty sure there are already some routine threads already. :P
Title: Re: Best TI-BASIC command of all time?
Post by: JWinslow23 on March 13, 2014, 02:25:37 pm
We should really change this into a "favorite routine" thread!


Mine is a Day of Week calculator (Month, day, and year are M, D, and Y, respectively):
Code: [Select]
:Y-(M<3
:round(7fPart((int(23M/9)+D+4+Y+int(Ans/4)-int(Ans/ᴇ2)+int(Ans/400)-2(M≥3))/7
I'm pretty sure there are already some routine threads already. :P
Still. :P
Title: Re: Best TI-BASIC command of all time?
Post by: DJ Omnimaga on March 16, 2014, 06:40:03 pm
On a side note, cumSum gotta have the worst TI-BASIC command name  of all time (I already brought that NSFW joke up before, but yeah the name looks a bit questionable) O.O

Maybe TI thought that students using that calculator would not be familiar yet with that stuff so they didn't mind using a dirty command name :P
Title: Re: Best TI-BASIC command of all time?
Post by: dinosteven on March 16, 2014, 08:53:54 pm
On a side note, cumSum gotta have the worst TI-BASIC command name  of all time (I already brought that NSFW joke up before, but yeah the name looks a bit questionable) O.O

Maybe TI thought that students using that calculator would not be familiar yet with that stuff so they didn't mind using a dirty command name :P
:P
Then again, how are you gonna shorten "cumulative" in another way?
Title: Re: Best TI-BASIC command of all time?
Post by: blue_bear_94 on March 16, 2014, 09:20:52 pm
On a side note, cumSum gotta have the worst TI-BASIC command name  of all time (I already brought that NSFW joke up before, but yeah the name looks a bit questionable) O.O

Maybe TI thought that students using that calculator would not be familiar yet with that stuff so they didn't mind using a dirty command name :P
:P
Then again, how are you gonna shorten "cumulative" in another way?
cumulSum(?

Also, TI-Basic really needs first-class functions. And first-class everything, in fact. And the calculators need moar RAM.
Title: Re: Best TI-BASIC command of all time?
Post by: bb010g on March 16, 2014, 09:40:25 pm
Also, TI-Basic really needs first-class functions. And first-class everything, in fact. And the calculators need moar RAM.

I would be ecstatic if somebody came out with a calculator that had LISP. A Scheme would be preferable (like Chichen or Racket), but any real LISP would be awesome.
Title: Re: Best TI-BASIC command of all time?
Post by: blue_bear_94 on March 16, 2014, 10:26:58 pm
Also, TI-Basic really needs first-class functions. And first-class everything, in fact. And the calculators need moar RAM.

I would be ecstatic if somebody came out with a calculator that had LISP. A Scheme would be preferable (like Chichen or Racket), but any real LISP would be awesome.

Maybe I can make one for the TI-89.


(also, the zeroes on the TI-89 look like b00bs)
Title: Re: Best TI-BASIC command of all time?
Post by: TheCoder1998 on March 17, 2014, 02:31:05 am
On a side note, cumSum gotta have the worst TI-BASIC command name  of all time (I already brought that NSFW joke up before, but yeah the name looks a bit questionable) O.O

Maybe TI thought that students using that calculator would not be familiar yet with that stuff so they didn't mind using a dirty command name :P

i never noticed that haha XD

i always thought something to make my own functions with like the symbolic functions would have been awesome (javascript can do it, why can't asm?)
Title: Re: Best TI-BASIC command of all time?
Post by: aeTIos on March 17, 2014, 03:41:05 am
DJ, you ruined my calcchildhood. D: