Basically, It’s BASIC

The BASIC language may be considered old-hat here in 2025, and the days when a computer came as a matter of course with a BASIC interpreter are far behind us, but it can still provide many hours of challenge and fun. Even with our love of all things 8-bit, though, we’re still somewhat blown away by [Matthew Begg]’s BASIC interpreter written in 10 lines of BASIC. It’s an entry in the BASIC 10-liner competition, and it’s written to run on a Sinclair ZX Spectrum.

The listing can be viewed as a PNG file on the linked page. It is enough to cause even the most seasoned retrocomputer enthusiasts a headache because, as you might expect, it pushes the limits of the language and the Sinclair interpreter.  It implements Tiny Basic as a subset of the more full-featured BASICs, and he’s the first to admit it’s not fast by any means. He gives a line-by-line explanation, and yes, it’s about as far away from the simple Frogger clones we remember bashing in on our Sinclairs as it’s possible to get.

We love it that there are still boundaries to be pushed, even on machines over four decades old, and especially that this one exceeds what we thought was a pretty good knowledge of Sinclair BASIC. Does this language still have a place in the world? We always look forward to the BASIC 10-liner competition.

Header: background by Bill Bertram, CC BY-SA 2.5.

27 thoughts on “Basically, It’s BASIC

  1. Come on … most 8-bitters’ BASIC already only was a Tiny-BASIC compared to the original. (Original) BASIC’s reputation probably will never recover from that!

    1. +1

      Especially the C64 Basic was such a horrible offender here, I think.
      It created a generation of bad-Basic lovers that never progresssed to level of Amiga Basic, Locomotive Basic or Quick Basic/Turbo Basic.
      Sure, it could be fixed by Simons’ Basic, but the plain v2 Basic was as bad as the Basic of that VC20.
      In my opinion, Commodore should have included free copies of Simons’ Basic with all new C64/C128 in order to undo the harm it had done.

      1. Jack Tramiell was the CEO of commodore at the time and he was a notorious penny pincher. You still have the license to PET Basic from Microsoft, so he just ported it to the commodore 64 for free. And his brain, if you were getting 64k of ram, which was massive at the time, you can afford to get a better BASIC on your own.

  2. Posting source code listing as a png image makes it mostly gibberish. Looks like lots of statements are concatenated on those lines.
    And what is a “line”? You probably can write a C compiler on one line of C source code. But I don’t endeavor in that direction, I prefer line breaks and readability over obfuscation and “puzzling”.

      1. Yeah – the rules of the BASIC 10 liner contest have various character limits. The ‘Tools’ category allows up to 256 characters per line. And Sinclair BASIC is tokenised, so it stores commands in only one character. Atari and Commodore BASIC can also use shortened statements like ‘?’ for PRINT, but it can make for some difficult to read code. Some of the other categories in the competition are even more limited – 80 or 120 characters per line. You can follow the links in the article and try TinyBasic in a Spectrum emulator!

  3. I started with BASIC, and got quite good- and very efficient- at it. Altair, Imsai, PDP, Model I… I’ve always felt BASIC got a bad rap. Sure, it allows you to write terrible spaghetti code. But you don’t have to. And the fact that the terrible spaghetti code runs and works I think is a testament to just how GOOD the language is. Python seems to me like a semi-ripoff of BASIC.

    1. MBASIC/BASIC-80 on CP/M was one of the better Basics already.
      Together with BASCOM someone could easily create standalone executables for the platform. C64 Basic on other hand.. Ew.

    2. It’s still my favorite language of all time. It’s probably just because it was my first, but I just feel very at home with it. I’m very comfortable with how it works, and it works well if you do it right.

  4. Impressive + Retro = impressively retro! (And the “IDE” seems nearly air-gapped from the modern world.)
    Yes, of course a bunch of BASIC statements were squeezed into one line. That was legal BASIC, and that’s how the author pulled off this extreme feat in “only 10 lines.” Presumably lines were of finite length.
    According to various, surprisingly active Sinclaire forums, POKE was used to turn on Caps-lock or something less-than-devious.
    The code would be most fun to analyze if someone (or the original author) could kindly turn the PNG image “listing” into text, so we can reformat it for readability. (I’d suggest OCR, but surely half of those lower-case b’s would turn into 6’s)

    1. It is an entry for the annual BASIC 10-liner contest. The ‘tools’ category has a 256-characters per line limit, but tokenised commands are stored as 1 character so the lines can appear longer than that for Spectrum listings. Here’s the code in text format:

      1 BRIGHT 0: BORDER 0: PAPER 0: INK 4: CLS : DEF FN n(w$)=w$>=”0″ AND w$<="9":
      DEF FN c(x)=214+xCODE c$(1): DEF FN h()=h*(h> l)+l*(l>=h): POKE 23658,8: DIM
      k$(32,6): DIM j(32): DIM j$(32): DIM l$(256,50): DIM p$(256,50): DIM b$(20): DIM
      c(256): DIM v(36): DIM p(256): DIM f(26,2): READ t$,u,h,i: FOR n=1 TO 30: READ
      z$,z: LET k$(n)=z$: LET j(n)=LEN z$: LET j$(n)=CHR$ (214+z): NEXT n: PRINT t$””
      READY”
      2 LET i=1: GO SUB 10: LET l=0: FOR z=s$=”” TO 0: FOR y=s$”RUN” TO 0: FOR l=
      1 TO h: FOR x=l$(l,1)=” ” TO 0: LET c$=l$(l): GO SUB 3: NEXT x: NEXT l: PRINT :
      GO TO 2: NEXT y: FOR y=FN n(s$(1)) TO 0: GO SUB 8: GO SUB 3 : GO TO 2: NEXT y: F
      OR y=LEN s$>3 TO 0: LET l$(VAL s$)=””: GO TO 2: NEXT y: FOR y=1 TO LEN s$: FOR x
      =FN n(s$(y)) TO 0: LET l=VAL s$( TO y-1): LET s$=s$(y TO ): LET y=1e9: NEXT x: N
      EXT y: GO SUB 8: LET l$(l)=c$: LET p$(l)=s$: LET p(l)=LEN s$: LET h=FN h(): NEXT
      z: GO TO 2
      3 FOR n=FN c(35) TO 0: POKE 23692,255: PRINT ‘”COMMANDS””: FOR m=1 TO 21: PR
      INT k$(m),: NEXT m: PRINT ” : NEXT n: FOR n=FN c(9) TO 0: POKE 23658,0: STOP :
      NEXT n: FOR n=FN c(37) TO 0: CLS : NEXT n: FOR n=FN c(12) TO 0: PRINT “END “;l’:
      GO TO 2: NEXT n: FOR n=FN c(22) TO 0: LET l=VAL c$(2 TO )-1: NEXT n: FOR n=FN c
      (24) TO 0: LET i=2: GO SUB 10: FOR m=s$=”” TO 0: LET v(VAL c$(4 TO 4+(c$(5)”)”
      )))=VAL s$: NEXT m: NEXT n: FOR n=FN c(39) TO 0: DIM v(36): NEXT n
      4 FOR n=FN c(26) TO 0: POKE 23692,255: FOR m=1 TO h: FOR o=l$(m,1)=” ” OR m<V
      AL ("0"+(c$+b$)(2 TO )) TO 0: PRINT m;p$(m)( TO p(m)): NEXT o: NEXT m: NEXT n: F
      OR n=FN c(16) TO 0: RUN : NEXT n: FOR n=FN c(3) TO 0: INK VAL c$(2): CLS : NEXT
      n: FOR n=FN c(23) TO 0: LET v(27)=v(27)+1: LET v(27+v(27))=l: LET l=VAL c$(2 TO
      )-1: NEXT n: FOR n=FN c(40) OR v(27)<1 TO 0: LET l=v(v(27)+27): LET v(27)=v(27)-
      1: NEXT l: NEXT n
      5 FOR n=FN c(31) TO 0: LET c$=c$+" ": POKE 23692,255: FOR m=(LEN c$) TO 1 STE
      P -1: LET z=m*(c$(m)” “): LET m=m*(c$(m)=” “): NEXT m : LET y=c$(z)”;”: FOR
      m=NOT (c$(2)=CHR$ 34 OR z<2) TO 0: PRINT c$(3 TO z-2+y);: NEXT m : FOR m=NOT (c$
      (2)CHR$ 34 AND z>1) TO 0: PRINT VAL c$(2 TO z-1+y);: NEXT m: FOR m=NOT y TO 0:
      PRINT : NEXT m: NEXT n: FOR n=FN c(34) TO 0: SAVE “a” DATA l$(): SAVE “b” DATA
      p$(): SAVE “c” DATA p(): DATA “TINYBASIC V1.0”
      6 NEXT n: FOR n=FN c(25) TO 0: LOAD “a” DATA l$(): LOAD “b” DATA p$(): LOAD ”
      c” DATA p(): CLS : LET h=256: NEXT n: FOR n=FN c(1) TO 0: BEEP .2,VAL c$(2 TO ):
      NEXT n: FOR n=FN c(36) TO 0: FOR m=2 TO LEN c$: FOR o=c$(m)CHR$ 203 TO 0: LET
      z=m: LET m=99: NEXT o: NEXT m: FOR m=NOT VAL c$(2 TO z-1) TO 0: LET c$=c$(z+1 T
      O ): GO TO 3: NEXT m: NEXT n: FOR n=INKEY$CHR$ 226 TO 0: PRINT “BRK AT “;l’: G
      O TO 2: NEXT n: DATA 0,1,1,”BEEP”,1,”CLEAR”
      7 FOR n=FN c(27) TO 0: LET z=c$(5)”)”: LET v(VAL c$(4 TO 4+z))=VAL c$(7+z T
      O ): NEXT n: FOR n=FN c(21) TO 0: LET u=u+1: LET z=c$(5)”)”: LET y=VAL c$(4 TO
      4+z): LET v(y)=VAL c$(7+z): LET f(y,1)=VAL c$(9+z TO ): LET f(y,2)=l: NEXT n: F
      OR n=FN c(29) TO 0: LET y=c$(5)”)”: LET z=VAL c$(4 TO 4+y): LET v(z)=v(z)+1: L
      ET m=v(z)> f(z,1): LET l=l*m+f(z,2)*NOT m: LET u=u-m: NEXT n: RETURN : DATA 39,”
      CLS”
      8 LET d$=””: LET s=0: FOR n=1 TO LEN s$: LET z$=s$(n): FOR m=z$CHR$ 34 TO 0
      LET s=NOT s: NEXT m: FOR m=z$=” ” AND NOT s TO 0: FOR o=1 TO 30: FOR q=(s$+b$)
      (n TO n+j(o)-1)<>k$(o, TO j(o)) OR s=1 TO 0: LET d$=d$+j$(o): LET n=n+j(o)-1: LE
      T z$=””: NEXT n: NEXT q: NEXT o: LET d$=d$+z$: NEXT m: NEXT n: LET c$=””: LET s=
      0: FOR n=1 TO LEN d$: LET z$=d$(n): FOR m=z$<>CHR$ 34 TO 0: LET s=NOT s: NEXT m:
      FOR m=NOT (s=0 AND z$>=”A” AND z$<=”Z”) TO 0
      9 LET c$=c$+”V(“+STR$ (CODE z$-64)+”)”: LET z$=””: NEXT n: NEXT m: LET c$=c$+
      z$: NEXT n: RETURN : DATA 37,”END”,12,”EXIT”,9,”FOR”,21,”GOTO”,22,”GOSUB”,23,”HE
      LP”,35,”IF”,36,”INPUT”,24,”LET”,27,”LIST”,26,”LOAD”,25,”MODE”,3,”NEXT”,29,”NEW”,
      16,”PRINT”,31,”REM”,20,”RETURN”,40,”SAVE”,34,”ABS”,-25,”AND”,-16
      10 LET s$=””: PRINT FLASH 1;” “;: FOR n=1 TO 1e9: PAUSE 0: LET i$=INKEY$: FOR
      m=(i$<” (“(1) OR i$>”`9″(i)) TO 0: LET s$=s$+i$: PRINT CHR$ 8+i$; FLASH 1;” “;:
      NEXT m: FOR m=i$<>CHR$ 12 OR s$=”” TO 0: LET s$=s$( TO -1+LEN s$): PRINT CHR$ 8+
      ” “;CHR$ 8+CHR$ 8; FLASH 1;” “;: NEXT m: LET n=n+1e9*(i$=CHR$ 13): NEXT n: PRINT
      CHR$ 8+” “: RETURN : DATA “INT”,-28,”NOT”,-19,”OR”,-17,”PI”,-47,”RND”,-49,”TO”,
      -10,”THEN”,-11

    2. I tried two free OCR tools I found on the web, and both failed miserably, even though the PNG “listing” is the cleanest, sharpest bitmapped character data you could every dream of. These days OCR vendors are pitching AI and language recognition–everything we don’t need to convert essentially a screenshot worth of code, where punctuation is more important than letters, into text (the original BASIC code).

      1. The author included a .tap file which you can easily upload into an emulator and get it that way. There are also tools that will dissect that file and get the source code out of it.

  5. Both standalone BAICs and Forths are hosted by a single task OS.

    fig Forth 8080 OS much more modular than BASICs, imo.

    gcc c compiler the ‘way to go’ … along with a 8080 fig Forth single task OS
    in 2025?

    What is Debian?.

    AI Overview.

    Debian is a free, open-source operating system (OS) based on the Linux kernel.
    It’s developed by the Debian Project, a group of volunteers who work
    to create and maintain the system.

    how many line of code in debian?

    AI Overview.

    According to recent reports, Debian contains over 1.3 billion lines of code,
    with one source stating that Debian 12 specifically has
    over 1,341,564,204 lines of code.

    Large scale:

    Due to the vast number of packages and applications included,
    Debian has a massive codebase, reaching into the billions of lines of code.

  6. Any computer that ships with Office still has a BASIC interpreter. I suspect that it is still by far the most widely available programming language, even if it’s rarely used.

  7. I just completed writing a dos like command line interface with a line based Basic interpreter mainly for use with the RPI Pico/Pico 2 . Written in Python. It uses syntax pulled from Commodore/gwbasic/radioshack/apple basic with a lot of my own commands. And when run on a Linux box, graphics is supported (via pygame as the back end library) for plotting (plot/hplot commands, as well as my extentions for circles, rectangles, text, etc.). Again mainly to support ‘old’ basic programmers. Obviously never truly complete, but it runs a lot of ‘old’ (Not vb style) text basic games, and graphics programs and such you can pull off the web. Great way to ‘test’ compatibility. Why? Just because it was fun to do. It all started with wanting to design a DOS like command line interface to serially access running Picos. With an A: and B: drives (directories behind the scenes) to hold files as needed like in the old days, then oh, lets get batch files working, then what about edlin to modify files on the fly? Wrote that. Then might as well implement all the dos File commands, and then … Hmmm, why not a Basic interpreter too? Haven’t wrote a interpreter in a long time… So it snowballed down hill. Usually does!

    1. Typo: “Again mainly to support ‘old’ basic programmers.” -> Again mainly to support ‘old’ basic programs and my own little basic programs to interface to Pico hardware/disk.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.