GSharp README
This language extension currently provides syntax highlighting and program structure support for G#. A language server is coming soon.
The primary goal of this language is to provide people with a friendly introduction to robotics routine programming. That being said, it does also have everything needed to be considered a general purpose language. It makes use of .NET Core's Common Language Infrastructure to allow interoperability between G#, C#, and F#. The purpose being that G# can focus entirely on communication with hardware components (by way of an Arduino board) while leveraging the strengths of C# and F# to handle more advanced features on the user/system side. This design decision was also made in the interest of better handling and processing sensory input.
Part of the syntax of G# incorporates elements from both C# and F#. However, where helpful, concepts are simplified so it's easier for beginners to make sense of. For example, the standard string
type has been renamed to text
. With the same motivation in mind, many of the library imports are handled automatically by the compiler so makers may focus on the logic as much as possible. An output to the screen is accomplished by invoking the output
method without specifically importing the System
namespace.
The language draws technical inspiration from, besides the obvious, Occam-π, Go, and Forth.
Features
G# will see a few releases.
- Standalone compilation by invoking the compiler directly through a console
- A plugin for full project support in Visual Studio
- A standalone IDE named A Major
The following is true of all three versions:
- Interoperability is enabled through built-in keyword blocks.
C#{/*C# Code here*/}
F#{(*F# Code here*)}
- The concept of a
routine
is introduced. These are blocks of hardware instructions that may be passed around. They are similar to lambdas, but they don't accept parameters. They're intended specifically to be a list of instructions to be carried out by your construct.
routine
s have their own local stack to store state. They do not modify anything external.
- Asynchronous execution has been simplified by use of the
go
block (Yes, borrowed from Golang).
Unique to A Major:
There is an optional kit of modular components to more fluidly construct your machines. A Major will connect to the construct and automatically produce a digital mapping for your program to parse and interact with.
Syntax
For C# developers:
- A container is a simplified version of a namspace.
import
is equivalent to using
.
- The
infer
keyword is equivalent to var
.
permanent
is equivalent to const
.
dynamic
is implemented in a similar way.
- The
if
, while
, do while
, and case
constructs were brought over.
For F# developers:
- A
container
is equivalent to a module
.
import
is equivalent to open
/#load
- The F# default is to have immutable data. In G#, this only applies to object references.
|>
is used only to cast.
for
was brought over.
Shared Essentials
string
has been renamed text
.
number
stores numeric data. The compiler worries about proper storage.
boolean
still exists as-is (I couldn't bring myself to rename this iconic type).
object
stores class references (upcasting and downcasting are preserved, but more automatic)
- G# infers as much as possible. Function return types are optional.
- All the standard arithmetic and compare operators carry over.
/
always performs floating point divison
- A complete list of keywords and usage examples may be found on our websites (given below).
For Beginners
A beginner friendly getting started guide may be found on our websites (given below). This is suitable for complete beginners to programming or programmers unfamiliar with .NET specifically.
Sample programs
container Main
Main () =
{
output("Hello, world!"); // ; is required as code is consumed until one is found
}
{*
Example of what a routine may look like for a hand-like construct to play the piano
*}
container Main
Main () =
{
Joint wrist = Joints.Origin;
Joint indexFinger = wrist.B0, middleFinger = wrist.C0, ringFinger = wrist.D0;
routine PlayFirstFourNotesOfTheFairyTailAnimeTheme =
{
// Hardware-specific instructions are still being defined and may change from what is seen here.
{*
Robotics components will likely need to guarantee their starting position.
For example, if making a hand to play a melody on piano, you may want to start at and make movements relative to middle C.
The adjust keyword acts like a function to perform the initialisation.
*}
adjust [[elbow, 90]]; // Simplified example, "pass" an array of tuples of joints with their starting positions
middleFinger.down(5); // D5
middleFinger.pause(100);
go
{
middleFinger.up(5);
ringFinger.down(5); // E5
}
go
{
ringFinger.up(5);
middleFinger.down(5); // D5
}
go
{
middleFinger.up(5);
indexFinger.down(5); // C5
}
indexFinger.up(5);
}
PlayFirstFourNotesOfTheFairyTailAnimeTheme; // invoke
}
Name
The name G# and the IDE it's a part of are both inspired by music theory. In the A major scale there are exactly three sharps: C#, F#, and G#. It was a straightforward conclusion to create the missing G# and name the new IDE A Major.
The music scale also refers to G# as the leading tone. Mirroring that, G# stands out from C# and F# by prioritising things the other two don't: mainly the rule-based paradigm and distributed execution.
Release Notes
Initial release: currently only supports syntax highlighting, program structure, block folding, and token recognising.
0.0.1
Initial release
Authors
Triumvirate
Thank you and enjoy!