Jump to content
IGNORED

Cannot "Overload" sub-programs in TI Extended BASIC


OLD CS1

Recommended Posts

In C++ (probably C, as well, but I cannot recall off the top of my head,) you can set up multiple functions to accept calls depending upon the arguments passed.

 

This is not possible with TI Extended BASIC using the SUB command and, in fact, TI Extended BASIC starts looking for user sub-programs from the end of the program. For instance, given the code below lines 20 and 40 will return an INCORRECT ARGUMENT LIST error (error 81 in the program output,) whereas line 60 will pass just fine. The first two SUBs are ignored in favor of the last.

 

10 ON ERROR 100
20 CALL TEST
30 ON ERROR 100
40 CALL TEST(1)
50 ON ERROR 100
60 CALL TEST(2,3)
70 STOP

100 CALL ERR(A,B,C,D):: PRINT "ERROR";A;"IN LINE";D :: RETURN NEXT

200 SUB TEST :: PRINT "TEST" :: SUBEND

300 SUB TEST(A):: PRINT "TEST(A)" :: SUBEND

400 SUB TEST(A,B):: PRINT "TEST(A,B)" :: SUBEND

500 END

 

 

Does this type of sub-program overloading work with any Extended BASIC beyond TI's?

Link to comment
Share on other sites

I don't think that you can do that in Basic/XB.

That sort of things came later...

 

This is really more of an academic pursuit. Sub-program overloading, while neat, is not a practical necessity. One could easily use multiple sub-program depending upon the argument need. I just thought of this knowing that some sub-programs, even in TI BASIC, are apparently "overloaded" to accept optional arguments. For instance, HCHAR, VCHAR, and so on, then in TI Extended BASIC, COLOR is overloaded.

 

Anyone, you could duplicate optional argument behaviors using something like this:

100 SUB TEST :: code :: SUBEND

200 SUB TEST2(A) :: code :: CALL TEST :: code :: SUBEND

300 SUB TEST3(A,B) :: code :: CALL TEST2(A) :: code :: SUBEND

 

Also, if I read the addendums correctly, recursion is now illegal, which kind of sucks as there are legitimate uses for function (or sub-program) recursion. I can see why, however, since variables are local to the sub-program itself, and not local to each instance of the sub-program. So a fractal, Fibonacci, or factorial program could not use sub-programs for computations.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...