Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: cooliojazz on April 14, 2011, 11:32:41 am

Title: Basic Subroutines
Post by: cooliojazz on April 14, 2011, 11:32:41 am
I was writing a program, and I decided it would be easier to write with subroutines, so I came up with
Code: [Select]
.Sub call to 0
1→N
While N
If Ans:Goto 0
0→N
End

Lbl 0
.Sub Code
0:End

But the sub call being still like 3 lines when it's "compressed" onto one line is almost as long as the code I wanted to put in the subroutine.  Can anyone think of a smaller way to create a subroutine call in basic?
Title: Re: Basic Subroutines
Post by: AngelFish on April 14, 2011, 11:36:18 am
Hm, that's an interesting way to do it. Very nice. I don't think you'll get it much smaller though.
Title: Re: Basic Subroutines
Post by: cooliojazz on April 15, 2011, 11:11:52 am
You don't think so? :(
Title: Re: Basic Subroutines
Post by: Broseph Radson on April 15, 2011, 12:07:37 pm
Wow thats cool

EDIT:
Code: [Select]
For(A,1,4,3)
sub("ABCDEF",A,3)->Str1
1->N
While N
If Ans:Goto 0
0->N
End
End
Return

Lbl 0
Disp Str1
0:End

I didnt know you could do that ;D
Title: Re: Basic Subroutines
Post by: DJ Omnimaga on April 15, 2011, 05:23:31 pm
Wat? O.o
Title: Re: Basic Subroutines
Post by: Broseph Radson on April 19, 2011, 11:48:59 am
It stores the first half of "ABCDEF" to Str1 then calls the subroutine to display it, then it stores the second half of "ABCDEF" to Str1 and does the same thing.

Produces the output:
Code: [Select]
ABC
DEF
              Done
Title: Re: Basic Subroutines
Post by: meishe91 on April 19, 2011, 02:03:27 pm
I don't think he was talking about yours. I think there was a post between yours and his that got deleted, if I remember correctly, that was kind of odd.
Title: Re: Basic Subroutines
Post by: Broseph Radson on April 20, 2011, 01:42:27 pm
Oh heh
Title: Re: Basic Subroutines
Post by: ZippyDee on April 20, 2011, 03:19:25 pm
Good idea, however I believe due to a bug in the way TI-BASIC functions, that will cause a huge memory leak...
Title: Re: Basic Subroutines
Post by: Broseph Radson on April 22, 2011, 10:25:15 am
Oh... :(
Title: Re: Basic Subroutines
Post by: Builderboy on April 22, 2011, 10:30:25 am
Broseph Radsons code will not produce a memory leak, he correctly matches both sets of Ends to their corresponding starting loops, and if he ever exits a loop with a Goto, he uses a carefully placed End to make sure the code returns to the same scope of the program, preventing the memory leak from growing.  In essence, he actually exploits the memory leak you talk about, and accounts for it such that it doesn't build up :)
Title: Re: Basic Subroutines
Post by: Broseph Radson on April 22, 2011, 10:46:53 am
Cool ;D