Avoid a new scope, I guess? (which is usually, if not always, a bad/inconvenient thing)
Not really.
DEF vs. GOSUB
If you have used GOSUB before, DEF isn't really that different. The only major difference is:- GOSUB is not used in programming languages anymore
- DEF is used in almost all programming languages
SPEAK "Hello, world!" DEF SPEAK S$ FOR I=0 TO LEN(S$)-1 VSYNC 5 ?S$[I]; BEEP NEXT VSYNC 60 END 'vs GOSUB: S$="Hello, world!" GOSUB @SPEAK @SPEAK FOR I=0 TO LEN(S$)-1 VSYNC 5 ?S$[I]; BEEP NEXT VSYNC 60 RETURNAlso, if the next line of code is a DEF, it automatically starts ignoring what code is inside the DEF, unlike GOSUB, which would run through the code until it hits a RETURN and gives an error.
How to use DEF
There are 3 different DEF types:- DEF name(v1,v2,...)
- Takes: up to 255 values, or even 0 values.
- Gives back: 1 value.
- DEF name v1,v2,...
- Takes: up to 255 values, or even 0 values.
- Gives back: nothing.
- DEF name v1,v2,... OUT o1,o2
- Takes: up to 255 values, or even 0 values.
- Gives back: up to 255 values.
DEF HELLOWORLD S$ PRINT S$ BEEP WAIT 30 PRINT "Hello World!" ENDwill be finished soon...