TechniCalc Forum


Post new topic Post reply
Author Message
GE
Unregistered

Posts:
Registered:
 Posted December 26th, 2005 09:21 AM   IP           Reply with quote Edit Post Delete post
Hello, I am again pulling my hair out in despair due to the lack of access to global variables within functions, AND of capability to call Prgms from functions, AND of the inability to access the caller's local variables from the called, AND od the inability to modify parameters passed in (passing by reference in programmer-speak).
What are you guys doing to circumvent this MAJOR flaw ? I'd even be happy with a simple way to do a GOSUB within a Function or Program.
Please Help.
  
Bhuvanesh
Moderator

Posts: 117
Registered: Jul 2004
 Posted December 27th, 2005 12:06 PM   IP           Reply with quote Edit Post Delete post
Quote:
GE wrote:
What are you guys doing to circumvent this MAJOR flaw ?


Us, as in Doug, Ray, Andrew and myself?

The second and fourth are pretty much expected if you accept the definition of a function as a routine that is not allowed to have side effects. I'm not sure what you mean by "lack of access to global variables within functions"; you can access them from functions but, again, can't modify them. The ability to get the caller's local variables might be nice, but as a workaround it should be possible to pass them as arguments to the called function (possibly with special handling, if the called function is supposed to be callable directly by the user).

If you're trying these things for a specific project, maybe post some of the code here and we can take a stab at it.
   
GE
Unregistered

Posts:
Registered:
 Posted January 4th, 2006 04:45 AM   IP           Reply with quote Edit Post Delete post
I just want to call a subroutine (as in BASIC) from within a function. GOSUB is not available, and as the main code is in a function, I can't call anything else which would access and modify 'suitably' the caller's variables.

To be more precise, it is a factoring program which uses the "wheel" kind of trial division, it tests agains divisors not multiple of 2, 3 or 5.
Here it is in 'pseudo-code' :
factors(N)
d=1, list={}
TEST(1)
TEST(1)
TEST(2)
Loop until d>sqrt(N)
TEST(2)
TEST(4)
End Loop
Return list

with TEST(a) being :
d=d+a
While d divides N
N=N/d
append d to the divisors list
End While

Note that the caller's variables N, d and list are modified within the subroutine, and that is precisely the point.
I am not considering unrolling "TEST" as a reasonable programming practice...
  
Bhuvanesh
Moderator

Posts: 117
Registered: Jul 2004
 Posted January 4th, 2006 10:11 AM   IP           Reply with quote Edit Post Delete post
One thing that would be convenient for this would be the ability to do an assignment like:

{3,1,2} -> {a,b,c}

where {a,b,c} are variables. However, because of the big limitation of not being able to use arbitrarily nested arrays, this still wouldn't work.

I'll try to think of some way to do this, but if not, Kevin Kofler has a utility called "RunProg" that allows you to run programs from functions:

http://www.tigen.org/kevin.kofler/t...rog.htm#runprog
   



Posts:
Registered:
 Posted    IP           Reply with quote Edit Post Delete post
  
TechniCalc Forum :: :: Bhuvanesh :: Impossible to access global vars within functions
Mark all forums read
Logout
All times are CDT
Forum jump:
Thread Options:
Delete thread / Open/Close thread / Rename thread / Stick thread / Move thread / Merge thread

Post new topic Post reply

Return to TechniCalc home