7

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.

5
  • 4
    The title does not match the body.
    – JdeBP
    Oct 18 '20 at 11:06
  • 3
    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. Oct 18 '20 at 18:26
  • IIRC, MSX BASIC doesn't have user-defined functions at all.
    – Tonny
    Oct 19 '20 at 11:28
  • @Tonny - yes, it did.
    – scruss
    Jun 16 at 14:59
14

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? Oct 18 '20 at 8:35
  • 2
    Sinclair's "EVAL" was VAL() or VAL$(). Oct 18 '20 at 9:47
  • 1
    @TimLocke - Locomotive BASIC does. It's not MS derived, more MS inspired
    – scruss
    Oct 18 '20 at 15:23
  • 1
    @MauryMarkowitz, it's not so random. Bill Gates wasn't a fan of the MOS 6502 or the 8-bit Motorola CPUs. He only made them good enough that they would sell and he would make money. He liked the Intel CPUs and the Zilog Z80 which was based on the Intel 8008, so they got the extra features. Perhaps he saw them as business processors. The C128 has the 6502. The Tandy Model 100 ran on the Intel 8085, BASIC-80 ran on the Intel 8080 and Zilog Z80, and MSX BASIC ran on the Zilog Z80. Also, Microsoft's first product was designed for the Intel 8080 and the 6502 and Motorola versions were afterthoughts.
    – Tim Locke
    Oct 18 '20 at 20:16
8

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
3

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
  • 1
    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. Oct 19 '20 at 14:14
1

Dartmouth BASIC, 5th Edition (1970) allowed user-defined string functions with string arguments. It ran on a mainframe though, not an 8-bit microcomputer.

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.