This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
Author Message
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 23 Jan 2009 06:56:12 am    Post subject:

the program:
goto S
lbl 1
//subroutine 1
end

lbl 2
//subroutine 2
end

lbl S //start
//all other code


now, to call a subroutine, use this code: (17 bytes)
2→A
while A
DS<(A,1
goto 1 //replace 1 whit the subroutine's number
end


what do you guys think??


Last edited by Guest on 11 Jul 2010 06:33:21 pm; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 23 Jan 2009 06:00:46 pm    Post subject:

It's good that you found this out – it shows that you're really understanding the way the interpreter works. It's also good to keep such "subroutines" at the top of the program, since all Goto's would find the labels up there much faster. However, since one of these blocks is liable to get called prematurely (being the first thing encountered in a program), we'll need to take some precautions.

We could use If rand=.7455607728 as a means of conditionally activating the subroutine, and then store 1 to rand somewhere else in the program as a way of telling the calculator that it's time for that particular routine to be run. A second subroutine can be set up immediately after the first one, with If rand=.4911215451 being a different door, and 2→rand being the key to unlock it, and so forth. The cool thing about this is that when rand is run twice, the number will be different. So, each routine will only be accessed once until its respective seed is reproduced.

I believe a similar implementation is written into the subprograms article on TI|BD.


Last edited by Guest on 11 Jul 2010 06:33:36 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 24 Jan 2009 01:11:49 am    Post subject:

I'd actually stay away from storing to rand unless it's really necessary. Resetting the seed often makes programs that rely on random numbers disappointingly predictable.
Back to top
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 24 Jan 2009 05:04:05 pm    Post subject:

a, this is the second time i found out someting that did already exist :hmpf:

annyway... thanks
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 24 Jan 2009 05:07:17 pm    Post subject:

darkstone knight wrote:
damn, this is the second time i found out someting that did already exist :hmpf:

annyway... thanks

At least it means you're probably on the right track :biggrin:
Back to top
elfprince13
Retired


Super Elite (Last Title)


Joined: 11 Apr 2005
Posts: 3500

Posted: 25 Jan 2009 04:44:44 pm    Post subject:

you can use lists as a function stack if you want to properly implement variable scope.
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 25 Jan 2009 10:44:41 pm    Post subject:

This subroutine jump method got me thinking... Since putting DelVar in front of a loop will make the interpreter skip it when it's in skip mode, could this be used in anyway. Well this is the best I could come up with. It's not the prettiest method, but there might be a few situations where it could be useful.


Code:
0→X
Lbl 0
If X
Then
DelVarYRepeat X
Output(1,1,"Hello World
End
If X
End
If not(X
End
Output(7,1,"This will only
Output(8,1,"run once!
Repeat Ans
If Ans
Goto 0
1
End


Last edited by Guest on 25 Jan 2009 10:45:27 pm; edited 1 time in total
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 30 Jan 2009 05:16:29 pm    Post subject:

I discovered a possible speeder way to pass subroutines in the beginning of code. Specially in giant programs, I think.
If 0
Then
lbl 1
//subroutine 1
end
lbl 2
//subroutine 2
end
End

Passing the If block may be better than Goto... But overkill the use of If <strange variable or rand>=<igually strange value>...


Last edited by Guest on 30 Jan 2009 05:17:36 pm; edited 1 time in total
Back to top
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 30 Jan 2009 05:23:18 pm    Post subject:

it doesnt actualy return to the place where you called it
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 30 Jan 2009 05:28:16 pm    Post subject:

darkstone knight wrote:
it doesnt actualy return to the place where you called it
Actually I leave it as concern to the programmer. He can use your subroutine routine, for example.
I just thrown that as a little information. And is only 1 byte trade off with speed when running the beginning of the code. And maybe has other uses but I just guess that saves some bytes. Actually this serves well in my math huge program. Razz
Several EDIT's made... Last one!


Last edited by Guest on 30 Jan 2009 05:40:59 pm; edited 1 time in total
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 01 Feb 2009 02:37:03 pm    Post subject:

While 0 is a bit better than If 0:Then. Smile

Last edited by Guest on 11 Jul 2010 06:34:34 pm; edited 1 time in total
Back to top
Harrierfalcon
The Raptor of Calcs


Super Elite (Last Title)


Joined: 25 Oct 2006
Posts: 2535

Posted: 03 Feb 2009 09:25:31 pm    Post subject:

I typically do this for internal subroutines.


PROGRAM:A
:If min(H!={1,2,3,4,5...n
:/pi/→H
:While H=1
:...
:Return
:End
:While H=2
:...
:Return
:End
:...
:While H=n
:...
:Return
:End
:...
:3→H
:prgmA


I have no idea if this is the most efficient way, but it makes the most sense to me, as it 1) Doesn't involve icky goto/lbls and 2) only requires two lines--instead of yet another loop of some sort--to call the subroutine.


Last edited by Guest on 11 Jul 2010 06:33:08 pm; edited 1 time in total
Back to top
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 04 Feb 2009 04:25:22 pm    Post subject:

memory leaks, ehh?
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 05 Feb 2009 03:53:30 pm    Post subject:

darkstone knight wrote:
memory leaks, ehh?

I think Return command solves that issue. Not sure...
Back to top
Harrierfalcon
The Raptor of Calcs


Super Elite (Last Title)


Joined: 25 Oct 2006
Posts: 2535

Posted: 05 Feb 2009 04:10:04 pm    Post subject:

It does. We have vurrobin to thank for that, IIRC.
Back to top
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 05 Feb 2009 04:50:48 pm    Post subject:

only issue i can see, that the program does kinda weird if H is set at the beginning of the routine...

mayebe if you use a var, like X, it will get changed that often it doesn't really matter
Back to top
Display posts from previous:   
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
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement