No user defined functions.

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
johnnyrockets
Posts: 34
Joined: Tue May 03, 2016 12:42 pm

No user defined functions.

Post by johnnyrockets » Thu Aug 04, 2016 1:47 pm

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

swensont
Posts: 61
Joined: Tue Jan 18, 2011 4:55 am
Location: SF Bay Area

Re: No user defined functions.

Post by swensont » Thu Aug 04, 2016 8:12 pm

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

User avatar
mrtinb
Posts: 1062
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: No user defined functions.

Post by mrtinb » Fri Aug 05, 2016 8:17 am

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
Martin
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube

Post Reply