6

My BASIC is almost working, the almost being the DEF FN. Just so I don't paint myself into a corner, is there any "mainstream" BASIC from the 8-bit era that allowed user-defined string functions?

I'm mainly using "The Basic Language" from BASIC Computer Games as my guide to the language, and it doesn't really say much on the topic. All use of DEF in the book is always math. Commodore BASICs definitely don't support string functions, the right-hand-side must be a mathematical expression, and I suspect this is true for most others derived from it.

Are there any major 8-bit dialects that supported this - TRS-80, Coco, TI-99, Sinclair, BBC, etc? Not trying to do GW or even MSX, but I would be curious to know if they did.

4
  • 4
    The title does not match the body. – JdeBP Oct 18 '20 at 11:06
  • 2
    Right. Are you asking for MS BASICs in particular or home computer BASICs in general? – tofro Oct 18 '20 at 11:39
  • I was going to post that GWBASIC does, but that's a 16-bit implementation, not 8-bit. – Jeff Zeitlin Oct 18 '20 at 18:26
  • IIRC, MSX BASIC doesn't have user-defined functions at all. – Tonny Oct 19 '20 at 11:28
11

BBC BASIC does. Example from the manual:

100 DEF FNMID(A$)
110 LOCAL L
120 L=LEN(A$)
140 =MID$(A$,L/2,1)
13
  • 3
    Sinclair basic does too. – Jasen Oct 18 '20 at 4:14
  • I thought Sinclair's had EVAL? – Mark Williams Oct 18 '20 at 8:35
  • Sinclair's "EVAL" was VAL() or VAL$(). – Martin Maly Oct 18 '20 at 9:47
  • Interesting, OK then I'll make sure it can do that. What does line 140 do with the result? Is this a multi-line DEF and the = is return? – Maury Markowitz Oct 18 '20 at 14:34
  • 1
    @TimLocke - Locomotive BASIC does. It's not MS derived, more MS inspired – scruss Oct 18 '20 at 15:23
5

Locomotive BASIC does support string functions (as do MSX BASIC 1.0 and BASIC-80 Rev. 5.2):

10 DEF FNa(x)=x/2
20 DEF FNb$(a$)=LEFT$(a$,1)
30 PRINT FNa(10)
40 PRINT FNb$("phweeen")
Ready
run
 5
p
Ready
1
  • Nice! I looked it up in the manual but didn't see any mention of strings in relation to user defined functions. – Tim Locke Oct 18 '20 at 16:01
2

TI-99/4A definitely did. It had DEF for numeric and string functions, in normal TI-Basic and in TI-Extended Basic. Excerpt from the User manual.

DEFine 

    { numeric-function-name |(parameter)| = numeric-expression } 
DEF { string-functlon-name|(parameter)| = string$-expresslon }

The DEFine statement allows you to define your own functions to use within a program.
The function-name you specify may be any valid variable name. If you specify a 
parameter following the function-name. the parameter must be enclosed in parentheses
and may be any valid variable name. Note that if the expression you specify evaluates
to a string result. the (unction-name you use must be string variable name (i.e .. 
the last character must be a dollar sign. $). 
[..]
User·s Reference Guide 
Examples: 
>NEW 
>100 REM TAKE A NAME AND PRINT IT BACKWARDS 
>110 DEF BACK$(Xl=SEG$(NAME$ , x, 1 ) 
>120 INPUT "NAME? ":NAME$ 
>130 FOR I=LEN(NAME$) TO 1 STEP -1 
>140 BNAME$=BNAME$&BACK$(I) 
>150 NEXT I
>160 PRINT NAME$: BNAMES 
>170 END 
>RUN 
NAME? ROBOT 
ROBOT 
TOBOR 

** DONE **

2
  • The TI-99/4A wasn't 8-bit, though – scruss Oct 19 '20 at 13:56
  • Technically true but without any advantage compared to 8 bit machines.It had only 64K of address range. Except for 256 bytes SRAM and 8 Kb ROMS, everything was connected on a (slow) 8 bit bus. An MSX-1 trounces the TI. – Patrick Schlüter Oct 19 '20 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.