From BASIC to Julia

I have just recoded the first program I wrote in BASIC (~1983). It’s silly, but it has put an smile on my face:

begin
    @label L10
    println("Hello!")
    @goto L10
end

It’s BASIC, so it needs to have a GOTO. I’m pretty sure you can imagine the output.

10 Likes

You might think so, but actually some popular BASICs like BBC BASIC on 8-bit 1981 micro homecomputer had structured-programming/Pascal-like features, so no need for GOTO or GOSUB, and I see they were already outdated as of 1975, before micro/homecomputers, including 1976 Apple I (though most home computer BASICs only had such unstructured GOTOs, for way longer than 1981):

Dartmouth also introduced a dramatically updated version known as Structured BASIC (or SBASIC) in 1975, which added various structured programming concepts. SBASIC formed the basis of the ANSI-standard Standard BASIC efforts in the early 1980s.

Note in Julia @labels are local (unlike in BASIC or Fortran), making @gotos tolerable:

julia> function test()
         @label L10
         println("Hello")
       end

julia> function test2()
         @label L10
         println("Hello 2")
         @goto L10
       end
3 Likes

Oh! I was joking… I forgot to add :wink:

Anyway, thanks for your comment. I didn’t know that Structured BASIC existed.

2 Likes

How about::

begin
   10;    @label L10
   20;    println("Hello!")
   30;    @goto L10
end
9 Likes
begin
       @label L10; 
       @label L20; println("hello")
       @label L30; @goto L10
end
3 Likes

The blank line L10 is unnecessary, just @goto L20

4 Likes

Dudes, what you’re discussing is truly incredible! :rofl: Thank you so much for making me laugh :upside_down_face: :balloon:

1 Like

How about creating macros like @cls, @locate, @dim, etc… For instances print("\033c") clears the console and defining the @cls macro is straightforward. @locate may be implemented using terminal escape characters or some library like ncurses. It would be funny :slight_smile:

1 Like

A macro @basic which transforms top level integer literals into labels is a must have!

5 Likes

Semirelated confession time: on a couple occasions where I found it simpler to merge a couple methods and the first one happened to be getting away with many early returns, I just put @gotos where the returns were instead of checking if I could’ve refactored the control flow.

I have no experiences with macros but co-working with AI tools let me run this basic code:

@cls
@locate 10 10
@color 11 1
name = @input("What is your name? ")
@locate 11 10
@print("Hello, $name !")

Here is the set of macros (fill free to correct them, I am sure they are not idiomatic Julia macros):

macro cls()
    :(print("\033[2J"))
end

macro locate(row, col)
    quote
        ccol = $(esc(col))
        crow = $(esc(row))
        print("\033[$(crow);$(ccol)H")
    end
end

macro color(background, foreground)
    quote
        bc = $(esc(background))
        fc = $(esc(foreground))
        print("\033[48;5;$(bc)m")
        print("\033[38;5;$(fc)m")
    end
end

macro input(prompt)
    quote
        print($prompt)
        readline()
    end
end

macro print(str)
    quote
        cstr = $(esc(str))
        print("$cstr\n")
    end
end

with fun :slight_smile:

5 Likes

Darn it: my first “big” BASIC program is stored on punched tape, and I cannot access it anymore. I wrote a program for an Altair 8800 computer with 4kB of RAM way back in 1977. The program read in participants in speed skating competitions, and their time on 500, 1500, 5000, and 10_000 m, and then computed the score of each participant, sorted the results, and printed the result. With the limited memory, I could only fit in 15 participants. Normally, there were 16 participants who were allowed to do all 4 distances, so essentially, I had to know who would end last… (which was not too difficult).

8 Likes

There was a language called TrueBasic in the late 80s and 90s which was a commercial fully structured Basic similar to Pascal in many ways. I had the Mac version. It came with ability to plot graphs in a way very similar to running Julia in Vscode. I spent many hours examining iterated function systems as a high school student using it. Never once used a goto. There were a series of books published out of Dartmouth that taught scientific programming using it. Examining mathematical behavior of various sorts. Good times.

More info is available here: FAQ — True BASIC

3 Likes

Since we’re going down memory lane, BBC BASIC V was the best and “certainly fastest” BASIC for its time (it’s now open source).

If you want to call Julia from BASIC, then calling Julia from .NET, even from Visual Basic is possible:

I think it’s also possible to call that BASIC from Julia. Calling to or from it and/or VBA is likely most relevant by now, though interop with which (other) BASIC might be most interesting and possible easily?

Note you CAN run Julia on Commodore 64… I.e. you can boot up (modified) Linux on C64, very slowly (“in less than 48 hours”), and I’m assuming thus Julia, since they have memory expansion and virtual memory support.

When 8-bit music is brought up, that usually means analog-based chiptune, the 8-bit C64 didn’t have digital/sampled sound capability… except is kind of did by a hack (likely first computer to manage [8-bit] sampled sound. [The Amiga and more computers had 8-bit linear, digital sampled sound, and the Acorn Archimedes was way ahead of its times with 8-bit logarithmic, sort of like 14-bit linear I understand, sound, and its BBC BASIC V.]

See demo of the sound there:
https://www.reddit.com/r/c64/comments/s84yvr/can_someone_explain_how_the_c64_was_able_to/

And here what they could do at the time, first:

2 Likes