Phillip Trelford's Array

POKE 36879,255

Pimping BASIC with lower casing & JSON literals

Back on April Fool’s day Anthony Green published a funny article “How ‘Roslyn# Finally Unshackled Visual Basic From The Tyranny of the Pretty-Lister”, showing VB.Net with lower case keywords, and how it made it look cooler. And more recently Mads Torgersen gave an “Early View of C# 7” demonstrating pattern matching, a feature that didn’t make it into C# 6, and syntax for tuples.

Taking some inspiration from this I thought I’d add some new extensions to my own language project, Fun Basic (try it free on the Windows Store). But Fun Basic already supports lower case keywords and tuples with pattern matching (which I implemented about 2 years ago), so instead over the last week I’ve added some different language features including cleaner aesthetics for BASIC and JSON literal support.

Hipster BASIC

People often complain about the verbosity of VB.Net, I see two parts to this:

  • End statements – End If, End While, End Select, etc.
  • Casing – Dim is the same length as var, but var just looks smaller

Fun Basic now lets you write `end` and it will infer the type of end for you:

 while i < 10
    i = i - 1

With the lower case keywords & simple end statement you could easily mistake this syntax for Ruby code.

JSON literals

VB.Net has XML literal support, which was a cool feature at the time, but these days XML is more associated with big enterprise, and all the hipsters are using JSON. With that in mind I’ve added JSON literal support to Fun BASIC:

name = "Phil"
age = 27
phil = {"name":name, "age":age}

This allows you to build up strings to send to web based services.

The syntax is also quite close to record syntax in ML, OCaml, F#, TypeScript etc.

Pattern matching

JSON literals are cool, but most of the time you’re using it the other way around, and consuming JSON from an API. For this I’ve added pattern matching over JSON literals.

For example say we want to get the temperature and humidity in London, we can use the Open Weather API, which spits back:

 "weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],
 "base":"cmc stations",

With the new Fun Basic pattern matching syntax we can easily extract the values of temp and humidity:

london = ",uk&appid=2de143494c0b295cca9337e1e96b00e0"
weather = Web.Get(london)
{"main":{"temp":temp, "humidity":humidity}} = weather

We can also use the pattern matching in a select case statement:

function ageGroup(person)
  select case person
    case { "age": Is >= 18 }
       return "Adult"
    case else
       return "Child"

sean = {"name":"sean", "age":9}


Both features were easy to implement (JSON literals took me the morning), and feel quite natural in the setting of BASIC, you can try them out now in Fun Basic, who knows one day we might see them in mainstream enterprise languages Smile

Introducing FunSharp

FunSharp is a new cross-platform open source graphics library, based on Small Basic’s library, with a typed API crafted for the sharp languages, F# and C#.

Drawing graphics is quick and easy:


And when you ask FunSharp to draw graphics it will just go and open a window to view it for you:


FunSharp provides similar functionality to Python’s PyGame, used for developing games, and Processing used for visual art.

You can call FunSharp immediately from the F# REPL or build full-blown applications using F# and C#.

It’s an ideal library for beginners or anyone who just wants  to get stuff on the screen quickly.

With this in mind FunSharp works seamlessly on Raspberry Pi, Linux and Windows.

Getting Started

If you haven’t already, you’ll need to install F# on your machine, follow these instructions:

  • Linux (for Raspbian follow the Debian instructions)
  • Windows (install Xamarin Studio or Visual Studio)

Get the FunSharp source from GitHub using Clone or Download Zip, then load the FunSharp solution into MonoDevelop or Visual Studio and starting playing with the samples.


  • FunSharp is built on Mono’s cross platform graphics libraries Xwt and Gtk# libraries which must be referenced.
  • currently apps must run in 32-bit mode.


FunSharp has a Turtle module, which can be used to make fun shapes:

Turtle.X <- 150.
Turtle.Y <- 150.
for i in 0..5..200 do




FunSharp can be used to make games quickly and easily. I’ve ported several games written for Small Basic requiring only minor modifications:


Have fun!


This week I ran a half-day hands on games development session at the Progressive .Net Tutorials hosted by Skills Matter in London. I believe this was the last conference to be held in Goswell Road before the big move to an exciting new venue.

My session was on mobile games development with F# as the implementation language:

Here’s a quick peek inside the room:

The session tasks were around 2 themes:

  • implement a times table question and answer game (think Nintendo’s Brain Training game)
  • extended a simple Flappy Bird clone

Times table game

The motivation behind this example was to help people:

  • build a simple game loop
  • pick up some basic F# skills

The first tasks , like asking a multiplication question, could be built using F#’s REPL (F# Interactive) and later tasks that took user input required running as a console application.

Here’s some of the great solutions that were posted up to F# Snippets:

To run them, create a new F# Console Application project in Xamarin Studio or Visual Studio and paste in the code (use the Raw view in F# Snippets to copy the code).

Dominic Finn’s source code includes some fun ASCII art too:

// _____ _   _ _____ _____ _____  ______  _  _   _____  _____ _     
//|  __ \ | | |  ___/  ___/  ___| |  ___|| || |_|  _  ||  _  | |    
//| |  \/ | | | |__ \ `--.\ `--.  | |_ |_  __  _| | | || | | | |    
//| | __| | | |  __| `--. \`--. \ |  _| _| || |_| | | || | | | |    
//| |_\ \ |_| | |___/\__/ /\__/ / | |  |_  __  _\ \_/ /\ \_/ / |____
// \____/\___/\____/\____/\____/  \_|    |_||_|  \___/  \___/\_____/

Flappy Bird clone

For this example I sketched out a flappy bird clone using Monogame (along with WinForms and WPF for comparison) with the idea that people could enhance and extend the game:


Monogame lets you target multiple platforms including iOS and Android along with Mac, Linux, Windows and even Rapsberry Pi!

The different flavours are available on F# Snippets, simply cut and paste them into an F# script file to run them:

All the samples and tasks are also available in a zip:

Have fun!