# From BASIC to Julia

**URL:** <https://discourse.julialang.org/t/from-basic-to-julia/121053>\
**Category:** Offtopic\
**Created:** [October 8, 2024, 9:17am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053 "2024-10-08T09:17:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![runjaj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/runjaj/32/23628_2.png) [@runjaj](https://discourse.julialang.org/u/runjaj)\
**Post date:** [October 8, 2024, 9:17am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/1 "2024-10-08T09:17:04Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 8, 2024, 9:42am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/2 "2024-10-08T09:42:12Z")

</div>

> [@runjaj](#):
>
> It’s BASIC, so it needs to have a GOTO.

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 BASIC](https://en.wikipedia.org/wiki/Dartmouth_BASIC)**
>
> Dartmouth BASIC is the original version of the BASIC programming language. It was designed by two professors at Dartmouth College, John G. Kemeny and Thomas E. Kurtz. With the underlying Dartmouth Time Sharing System (DTSS), it offered an interactive programming environment to all undergraduates as well as the larger university community.
> Several versions were produced at Dartmouth, implemented by undergraduate students and operating as a compile and go system. The first version ran on 1 May 196...

> Dartmouth also introduced a dramatically updated version known as **Structured BASIC** (or **SBASIC** ) in 1975, which added various [structured programming](https://en.wikipedia.org/wiki/Structured_programming) concepts. SBASIC formed the basis of the [ANSI](https://en.wikipedia.org/wiki/American_National_Standards_Institute)-standard **[Standard BASIC](https://en.wikipedia.org/wiki/Full_BASIC)** efforts in the early 1980s.

Note in Julia `@label`s are local (unlike in BASIC or Fortran), making `@goto`s tolerable:

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

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

```

---

<div class="post-metadata">

**Author:** ![runjaj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/runjaj/32/23628_2.png) [@runjaj](https://discourse.julialang.org/u/runjaj)\
**Post date:** [October 8, 2024, 9:48am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/3 "2024-10-08T09:48:02Z")

</div>

Oh! I was joking… I forgot to add 😉

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

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 8, 2024, 1:03pm UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/4 "2024-10-08T13:03:19Z")

</div>

How about::

```julia
begin
   10; @label L10
   20; println("Hello!")
   30; @goto L10
end

```

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [October 9, 2024, 12:50am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/5 "2024-10-09T00:50:03Z")

</div>

```julia
begin
       @label L10; 
       @label L20; println("hello")
       @label L30; @goto L10
end

```

---

<div class="post-metadata">

**Author:** ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)\
**Post date:** [October 9, 2024, 1:38am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/6 "2024-10-09T01:38:12Z")

</div>

The blank line L10 is unnecessary, just `@goto L20`

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [October 9, 2024, 7:59am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/7 "2024-10-09T07:59:29Z")

</div>

Dudes, what you’re discussing is truly incredible! 🤣 Thank you so much for making me laugh 🙃 🎈

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [October 9, 2024, 8:05am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/8 "2024-10-09T08:05:50Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 9, 2024, 8:16am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/9 "2024-10-09T08:16:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [October 9, 2024, 8:34am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/10 "2024-10-09T08:34:06Z")

</div>

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 `@goto`s where the `return`s were instead of checking if I could’ve refactored the control flow.

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [October 9, 2024, 6:40pm UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/11 "2024-10-09T18:40:41Z")

</div>

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

```julia
@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):

```julia
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 🙂

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 9, 2024, 8:52pm UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/12 "2024-10-09T20:52:39Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [October 14, 2024, 2:53am UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/13 "2024-10-14T02:53:10Z")

</div>

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](https://www.truebasic.com/faq)

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 17, 2024, 3:20pm UTC](https://discourse.julialang.org/t/from-basic-to-julia/121053/14 "2024-10-17T15:20:09Z")

</div>

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:

> [@Correct process to use julia code from C# or VB .NET](https://discourse.julialang.org/t/correct-process-to-use-julia-code-from-c-or-vb-net/58018):
>
> I am currently working on a projet involving julia as a base language for mathematical computations, and .NET (C# or VB) for the GUI part. I want to emphasize the fact that I am quite new to dll handling, julia and .NET (not general programming though) so sorry in advance if I same dumb things. I developed a julia package for my project where everything works fine. Now I am facing the part where I need to call this julia code from .NET. With the information provided in the documentation regar…

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.

> **[Linux On A Commodore 64](https://hackaday.com/2023/08/27/linux-on-a-commodore-64/)**
>
> We are used to seeing Linux running on almost everything, but we were a bit taken aback to see \[semu-c64\] running Linux on a Commodore 64. But between the checked-out user name and the caveat that:…

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/](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:

[![](https://global.discourse-cdn.com/julialang/original/3X/f/8/f85b95e734afe143223c0123446feb9c0148fbe7.jpeg "How Old-School Computers Played Sound Samples | MVG") ](https://www.youtube.com/watch?v=0xWyLeVnxFU&t=141)

[![](https://global.discourse-cdn.com/julialang/original/3X/c/6/c6d5954c9ecfa1e1039d8f52d1c80fa37c2afd8d.jpeg "Making 8-bit Music From Scratch at the Commodore 64 BASIC Prompt") ](https://www.youtube.com/watch?v=ly5BhGOt2vE)
