|
|
|||||||
Calling functions like this is OK:- $ = SomeFunction($params) But it would be neat to allow procedures to be defined. e.g. DoSomething($fred, 2) Would call the following routine to add 2 to the value of $fred PROCEDURE DoSomething($param1, $param2) $param1 = $param1 + $param2 ENDPROCEDURE Where parameters can be passed either by reference or value. Regards, Bill |
||||||||
|
|
|||||||
Not sure what extra functionality you are looking for. Functions that don't return anything are procedures, so the following will already work for example: Code: HelloWorld HelloWorld() HelloWorld("Foo") Function HelloWorld(Optional $s) "Hello "+$s+@CRLF EndFunction Pass-by-reference is regularly requested, and I'll second it (again). |
||||||||
|
|
|||||||
Bill's referring to "indirection", where the UDF would identify the name of the variable to modify, instead of either passing and returning, or using a Global. Using his example, the "procedure" would use "$Fred" as its LValue, and use $Fred + 2 as its RValue, after determining that $Param1 contained "$Fred" and Param2 contained the value "2". That would add two to the variable $Fred without returning anything. Similar result to Code: $Fred = MyFunc($Fred, 2) Function MyFunc($P1, $P2) $MyFunc = $P1 + $P2 EndFunction I don't see a lot of use for this right away, and we could probably get crafty and use Execute to accomplish this. Glenn |
||||||||
|
|
|||||||
Well, that's pass by reference yes-no? My point is that it doesn't require a new construct in the language, it simply requires the oft-requested support for pass by reference (or pointer for the old school). |
||||||||
|
|
|||||||
I was only asking for a way of making a call to a routine or Procedure a bit neater. I want to do something or lots of things without necessarily needing to return a value. DoSomething(Params) Is much nicer than:- Gosub "DoSomething" ; using Global variables or $ = DoSomething($params) If you currently call a Function without assigning its value to a variable, it prints the returned value to the console. Messy! Cheers anyway, |
||||||||
|
|
|||||||
That's trickier. If your function does not return a value then it is equivalent to a VB Sub and you don't need to assign the function to a value. This functionality is already present. The problem is that the implied action in KiXtart is to output the content of the stack to the console - this is how normal output works. In other words, if there is data on the stack and there is no operator left to perform an action on it then the intention is to display it. Now, we could work around this by implementing a specific "PRINT" command to display output to the console or maybe introduce a suppression operator so for example if you preceded an expression (or function) with say the "#" character it suppresses the implied print action. Seems like a lot of effort to avoid typing "$=" in front of a function to discard the output |
||||||||
|
|
|||||||
to avoid 0 shown on the screen, you can have a template of function like that : Code: function MyFunction(....) $MyFunction = "" .. .. endfunction In this case, this is not 0 that is printed to screen but an empty string !!! No need to change KiXtart syntax. |
||||||||
|
|
|||||||
No need to initialise the function return to "" - in fact it is better if you don't as the return will be type "Empty" which is more correct than a zero length string. Code: Foo Bar "Foo returns '" Foo "' Type=" VarTypeName(Foo) ? "Bar returns '" Bar "' Type=" VarTypeName(Bar) ? Function Foo() EndFunction Function Bar() $Bar="" EndFunction Quote: D:\temp>kix32 nr.kix Foo returns '' Type=Empty Bar returns '' Type=String |
||||||||
|
|
|||||||
Thanks Guys. I wonder if it'll work on my old BBC Micro, Sinclair Spectrum and Transam Triton ? Don't eat too much chocolate over Easter. Regards, |
||||||||
|
|
|||||||
Originally Posted By: BillBarnard I wonder if it'll work on my old BBC Micro, Sinclair Spectrum and Transam Triton ? Wish I still had my MS BASIC on paper tape.. Glenn |