Using LOCAL to label a LOCAL subroutine seems a bit unnecessary in U2, since
the names of subroutines are ignored by the run environment, which only
looks at the name used for cataloging the routine.

Regardless, if I interpret this correctly, I think that requiring variables
in LOCAL subroutines be declared as PRIVATE in order to be locally scoped is
a mistake.  Local scoping within a subroutine ought to be the default.

Likewise, any labels outside of a LOCAL subroutine ought to be out of scope
of the subroutine itself.  So the syntax of "gosub name(a, b)" for calling a
local subroutine is confusing, since "name" may be another local subroutine
within the file, but "gosub" ought to be confined to labels within a given
program, function, or subroutine. (imho).  I prefer "call" for calling local
subroutines.

But if variables are local (to a local subroutine) by default, then there
needs to be some manner of declaring variables, inserts, and commons as
global to the file.  My (admittedly Fortran or C like ) proposal for this
was to declare them before the first PROGRAM, SUBROUTINE, or FUNCTION
statement within a file, and I certainly see the possibility for some
ambiguity in doing this; it just seemed like an easy way to avoid the
PRIVATE and PUBLIC modifiers in a time tested manner.  

The problem that develops is when there is code preceding a subroutine
declaration:  Should that be considered the (no argument) subroutine by the
run machine, or should it be considered as part of a global declaration?  A
possible solution would be to define a "global" block as in the following
example, where the actual cataloged subroutine would be MYSUB, but the
GLOBAL code would be executed before the the code under MYSUB was invoked. 
The first declared subroutine would be the entry point, unless there was
"undeclared" code before the subroutine (for compatibility).

I would just as soon not have to go back and add PUBLIC to all the insert
files we have.

GLOBAL
   $INCLUDE BLAH
   DEFFUN MYSUBSUB( ARG ) CALLING MYSUBSUB
   COMMON /BLAT/ BLAT1
   VAR1 = 10
END

SUBROUTINE MYSUB( ARG1, ARG2 )
  ARG1 = BLAT1 + MYSUBSUB(ARG2)
END

SUBROUTINE MYSUBSUB( ARG1, ARG2)
  ARG1 = ARG2 + VAR1
END

The bottom line, of course, is that IBM is going to come up with their own
solution, if at all, and they have only the slightest inclination  to match
QM's syntax or listen to any individual customer.

btw, Although I have not read much of the QM documentation,but I have been
wanting some sort of CLASS definition in Basic for about 20 years (And I am
not exaggerating).




Martin Phillips wrote:
> 
>> I'd really appreciate a way to write an internal function which
>> can have parameters and can contain it's own local variables
>> (although global variables would be OK).
> 
> This is an excellent idea. We did it for the QM multivalue database
> product 
> a year or so back and it is very useful. Hopefully, if IBM decide to take
> up 
> this suggestion, they will use our implementation as the de facto 
> specification of the user interface rather than "reinvent the wheel".
> 
> We have
>    LOCAL SUBROUTINE name(arg1, arg2, ...)
>       PRIVATE var, var2(10,5)
>       ... do something...
>    END
> entered using
>    GOSUB name(X,Y)
> 
> and
> 
>    LOCAL FUNCTION name(arg1, arg2, ...)
>       PRIVATE var, var2(10,5)
>       ... do something...
>       RETURN value
>    END
> declared with
>    DEFFUN name(a,b) LOCAL
> and used in exactly the same way as external functions.
> 
> The private variables are truly stacked to allow recursive calls each with 
> their own variables. We even allow variable length argument lists.
> 
> You never know, if IBM take up this one, they may then look at our object 
> oriented programming extensions which are incredibly useful (see the next 
> issue of Spectrum Magazine for the first of two articles on this topic).
> 
> 
> Martin Phillips
> Ladybridge Systems Ltd
> 17b Coldstream Lane, Hardingstone, Northampton, NN4 6DB
> +44-(0)1604-709200 
> -------
> u2-users mailing list
> u2-users@listserver.u2ug.org
> To unsubscribe please visit http://listserver.u2ug.org/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/-BB--Internal-functions-in-Basic-tf2837863.html#a8027883
Sent from the U2 - Users mailing list archive at Nabble.com.
-------
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to