micro(A)v11
#71
Lightbulb 
Rolleyes I was trying to find the post months ago by dbox where he says "JS <> JavaScript".

Quote:Yeah if this is about User Defined Functions in MicroA, yes go for it man! Love to see that no matter how you get there.

THIS IS A PROPOSAL:

I guess it's just reserving global variables that could be used inside a "func", and are called into play for something like this:

Code: (Select All)
var one, two
str tres
callme(one, two, tres)

func callme()
print $1, $2, $3
endfn

or have a keyword (I call "param") to represent the special variables:

Code: (Select All)
param callmexa, callmeya, callmeps, yadaone, yadatwo, foobar, elisa4

func callme(callmexa, callmeya, callmeps)
print callmexa, callmeya, callmeps
endfn

The problem is those special variables might have to be given types also. Not assume they are all "var". :/

Let me try to explain to see if Aurel doesn't get confused easily.

Define variables as usual but that cannot be used in main-level code. Which would require a special keyword. Maybe (with fake "paramv" and "params" keywords) have something like this:

Code: (Select All)
paramv callmexa, callmeya
params callmeps
var a, b
str s

func callme(callmexa, callmeya, callmeps)
endfn

The only difference between "callmexa" and "a" is that "callmexa" can be accessed only in "callme" subprogram because that subprogram is specifically calling for it. If there's another func and it's not referring to "callmexa" then that parameter cannot be used.

The advantage of a system like this is that it could be restricted to conserve RAM, say to five "var", five "str" and five "ptr" variables. If you want more you beg Aurel for micro(A) code, modify it to support more and recompile.

Otherwise work on something that looks more like Perl or MS-DOS batch language or "bash" script, but which could be potentially confusing and difficult to debug.
Reply
#72
Quote:Let me try to explain to see if Aurel doesn't get confused easily.
 I am already confused Big Grin 

 But looks to me that you are not sure and thanks for proposal  Angel

there is trick
for local variable is it is not problem in declaration then in execution
i can easy add this :

Code: (Select All)
myFN()
   var a,b,c
  'do something
  delete a,b.c  ' delete local variables from variable list
endFN
but problem is when you call it

myFN(a,b,c)

so function must be declared  or  autoDeclared
Reply
#73
For my Interpreter, oh, I plan on having a Subroutine "Call Subname;arg1;arg2;arg3..."
For Functions I will have a Function Func[functionName, arg1, arg2, arg3]

Both the Call routine and the Func[ ] function will lookup the 1st argument which is block name for lines of code to execute the sub or function. So in a recursive call to my code executer something like Run( codeblock$, parameters$) will split the codeblock$ out to string array of program lines and split parameters$ string to string array of arguments to which matching values will be assigned from the actual call or Func[] call. I also probably will have to store the variable table for current code block on stack before call and pull it down again and update byref variables in that variable table before exit the sub or function call. Shared variables? probably need a separate SHARED variable table and consult that first when checking variable assignments.

Got all that? Tricky as hell I've been thinking off and on about it for 2 years!
b = b + ...
Reply
#74
Mark
If you simple have mid$ function
which is as you know with pre-defined numbers of arguments
in MID$ they are 3 ( string,  position, size)
but in Function we don't know number of arguments...right?

BUT

IF function is declared  let say DEF_FN fnName( arg1, arg2, arg3 ,....)
or auto - declared  or pre-processed then we are on the HORSE Big Grin 
or horze At 
he he i will blow --,my bad english ..sorry Smile 

so what is the first 
in pseudo-code:
1.
Code: (Select All)
IF nexttoken$  (pos+1 )  <> " ) "
  ' continue...it is function
ELSE
' it is subroutine
END IF
then :

2. extract arguments like strings
   and store it into string array or "argument list"
  count number of arguments -> nArgs

Maybe use UDT to store data about function or use arrays
i used arrays but UDT should be fine to...

Code: (Select All)
userFuncName$ ( index)         = fnName$
userFuncID % (index)            = position%  ' address in code
userFuncNumArgs% (index)  = nArgs%
for i = 1 to nArgs
userFuncArgList$ (index)   =  argName$
Next i

did i miss something ?
maybe some other members have some ideas?
Reply
#75
I don't know what you are doing to keep track of variables in micro(A). But it would have to be done in one of two ways.

An UDT which looks more or less like this:

Code: (Select All)
type vardecl
    ident as string
    kind as _byte
    scope as _byte
    isarray as _byte
end type

This is just for starters and is only for example. "ident" is the name of the variable. "kind" must be called that way, not "type" since it's a reserved word in most modern BASIC's. This decides whether to use "var", "ptr" or "str" in micro(A). "isarray" then enables an external rule for a memory pool to attach to this element of this UDT. In other words, it could be zero for a regular variable in micro(A) and otherwise, the maximum number of elements in the array.

"scope" is the important one here. It could be set to zero so all variables are global. The way to set it, however could be a pain. Some manuals like that for Free Pascal talk about "reference levels" which causes discouragement. But if the author of the interpreter expects it to be useful enough to allow nested calling of functions, this problem has to be attacked.

This "scope" thing could help in checking to protect variables in another scope. The author of the interpreter could choose how to protect the global variables inside an user-written function. Could always do it, like in Python unless "global" keyword is offered. Now creating local variables should rely on scope. When the user-defined function exits, just search the variable table for candidates with the same scope and remove them. Please do not complicate the situation LOL by seeking to replicate "STATIC" technique in QuickBASIC/Qbasic/QB64. Must rely here on global variables that preserve value between function calls.

Otherwise the suggestion is one I made earlier. Reserve a limited number of variables. Like five per type. They will be used only as parameters for the user-written functions. This is similar to how Perl and Powershell handle things. The drawback is that it limits having one user-written function from calling another one. The author of the interpreter doesn't want to keep a large amount of memory for variables that cannot be used in the main program.

I was going to disturb bplus about this a few months ago. Keep 10 variables around to be used only for user-defined functions in "Oh" interpreter. Keep another 10 variables if you really want to be ambitious, and have one "Oh" interpreter instance call another instance. Which would bring about replicating COMMAND$. Those variables should not be used for any other purpose. They should be just volatile helpers like $1, $2, $3 etc. in "gawk" and Perl, like replaceable parameters in MS-DOS batch language.
Reply
#76
Hi mnr
I will copy your reply to basic4us because i can't track on both forums
Reply
#77
Quote:I don't know what you are doing to keep track of variables in micro(A)
That means that you never look into source code of micro(A)
variable lookUp is by variableID ..id is Integer not string/name
but focus here is functions with arguments
it is not if they stored in same place where are global varibles
Code: (Select All)
example:

var  a -> global[1] = id.a  ' global or shered
var  b -> global[2] = id.b  ' local variable
i hope that you see a point
Reply
#78
Bing


Reading Thread micro(A)v11
[/url]
[url=https://staging.qb64phoenix.com/showthread.php?tid=1823]who is Bing Big Grin
Reply
#79
Right now "roquedrivel" is having problems trying to think out of strings, for a graphics program in micro(A).

There would be more to offer if "print" statement could do a monospaced font. We keep forgetting to test if it supports UTF-8.
Reply
#80
What you mean under monospaced font
another Font ?
Reply




Users browsing this thread: 5 Guest(s)