100 PROC tl$(x$(),5):STOP
110 DEFPROC tl$(REF
    input$(),index=1)
120 input$(index) =
    input$(index)(2 TO)
130 ENDPROC

On the example above index is not passed by reference and therefore it can have a default value. Note that integer variables and arrays cannot be passed by reference!!!

Reading parameters with DATA and READ

A PROC may call a DEFPROC with more parameters than the DEFPROC requires. In this case, if the DEFPROC has the keyword DATA as its final parameter, the procedure may read the additional parameters one at a time using READ. The new function DATA (see also Chapter 5) can be used to determine if there are further PROC parameters left to read. As an example:

100 PROC printem(“Digits”,0,1,2,
    3,4,5,6,7,8,9):STOP
110 DEFPROC printem(name$, DATA)
115    LOCAL n
120 PRINT name$
130   REPEAT:WHILE DATA
140 READ n:PRINT n
150 REPEAT UNTIL 0
160 RETURN

Trapping errors locally

As well as (or instead of) having a global error-trapping routine for your program as exhibited at the end of Chapter 1, each procedure, subroutine and repeat loop may have its own local error-trapping routine, simply by using the ON ERROR command within it.

When an error occurs within a repeat loop, subroutine or procedure, it will be trapped by its own ON ERROR routine if there is one. If not, the error will be passed out to the next level and trapped by any ON ERROR routine there and so on. Only if there is no ON ERROR at any level above the command that caused the error will a normal error report be generated. For example:

 10 ON ERROR PRINT "Outer error
    handler!":ERROR
 20 REPEAT
 30   PRINT "Starting..."
 40   ON ERROR PRINT "Oops!":ON
    ERROR:STOP
 50   GO SUB 100
 60   PRINT "Iterating..."
 70   ON ERROR
 80 REPEAT UNTIL 0
 90 STOP
100 ON ERROR PRINT "Bad
    pigs!":RETURN

ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.