Page 1 of 1

No user defined functions.

Posted: Thu Aug 04, 2016 1:47 pm
by johnnyrockets
Hi all,

From reading my trusty T/S 1000 User Manual last night I came across the sentence, "Sinclair BASIC lacks user-defined functions".

This was a bit of a surprise to me. I was trying to decide how difficult that would make things.

Not sure, but it could make things more challenging in some respects.


JR

Re: No user defined functions.

Posted: Thu Aug 04, 2016 8:12 pm
by swensont
For functions and procedures, you have to use GOSUB.

If you have function - func(y)

10 let x = func(10)

Assume the code for the function starts at line 1000, this is how you would run it:

let y = 10
gosub 1000
print x

you would just make sure that the function would set the results into variable X,
or it could change the value of Y to be the return value.

I've seen some example programs where they will do this:
let func = 1000
and then do
gosub func

Re: No user defined functions.

Posted: Fri Aug 05, 2016 8:17 am
by mrtinb
johnnyrockets wrote:From reading my trusty T/S 1000 User Manual last night I came across the sentence, "Sinclair BASIC lacks user-defined functions.
User Manual page 191:
ZX81 BASIC lacks READ, DATA & RESTORE (but see exercise 3 of chapter 22 concerning this), user-defined functions (FN & DEF; but VAL can sometimes be used), & multi-statement lines.
User Manual page 44:
VAL

This is Applied to a string, & the result is its length. For instance LEN "CHEESE" = 6.
This applied to a string, & the result is what that string gives when evaluated as an arithmetic expression. For instance (if A = 9), VAL "1/2+SQRA" = 3.5. If the string to which VAL is applied contains variables, then two rules must be obeyed.

If the VAL function is part of a larger expression, it must be the first item; e.g. 10 LET X = 7+VAL "Y" must be changed to 10 LET X = VAL "Y" +7.

VAL can only appear in the first coordinate of a PRINT AT, PLOT or UNPLOT statement (see Chapter 17 and 18) e.g. 10 PLOT 5, VAL "X" must be changed to
10 LET Y = VAL "X" 15 PLOT 5, Y