+OLD CS1 Posted January 31, 2011 Share Posted January 31, 2011 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? Quote Link to comment Share on other sites More sharing options...
kl99 Posted January 31, 2011 Share Posted January 31, 2011 I don't think that you can do that in Basic/XB. That sort of things came later... Quote Link to comment Share on other sites More sharing options...
+OLD CS1 Posted January 31, 2011 Author Share Posted January 31, 2011 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. Quote Link to comment Share on other sites More sharing options...
Tursi Posted February 1, 2011 Share Posted February 1, 2011 Yep, and overloading doesn't work in C either, just C++ Quote Link to comment Share on other sites More sharing options...
+OLD CS1 Posted February 4, 2011 Author Share Posted February 4, 2011 What Extended BASIC modules are still available corporeally? (Besides the TI cart, of which I now have three.) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.