Skip to content

Instantly share code, notes, and snippets.

@cjburkey01
Created May 29, 2018 23:35
Show Gist options
  • Save cjburkey01/a9f9aaf230b227673628d6f53cff6b4a to your computer and use it in GitHub Desktop.
Save cjburkey01/a9f9aaf230b227673628d6f53cff6b4a to your computer and use it in GitHub Desktop.
A little outline for a language I may or may not create for fun
// This is a single line comment
/*
This comment is multi-line,
it's pretty cool
*/
// Notice that the library declaration is padded with new lines surrounding the contained code (conventionally)
// Also notice that opening braces are located on the same line (conventionally)
lib sample.namespace:TestProgram {
// Array utilities (getting length, in our case)
use std:Array;
// Our test library for handling our input (in this example)
use sample.namespace:SecondTest;
// Ordinary statements may not be included outside of functions.
// For instance, 5+5; would result in an error because it has no executing environment
// Variables and functions, however, may be declared outside of functions
// Immutable variables must be given a value in their declaration
// Integers and floats are 32-bit unless otherwise statated (like this: "int64" or "float64")
// Also notice the space following colons (conventionally)
var immut exampleIntegerVariable: int = 42;
// Similarly typed variables are grouped (conventionally)
// Grouping follows these rules, generally: availability (pub or not pub and type) (conventionally)
var changeableHighPrecisionFloatVariable: float64;
var immut lowPrecisionImmutableVariable: float = 12.03;
// Functions are not padded with new lines (conventionally)
// The main function must be public, with an argument of type str... (string array)
fun pub main(args: str...) {
if (Array:getLength(args) < 1) {
SecondTestProgram:askForName();
// "exit;" leaves the function. Equivalent to "return;" in a C-like language. This leaves the main() function, so the program ends
// Avoids the need for an "else" branch to call our "returnName" function
exit;
}
// Array access is ARRAY.INDEX
SecondTestProgram:returnName(args.0);
// Sample addition and function access
SecondTestProgram:doTestAdd();
}
// "exampleIntegerVariable" is not public, so a getter method allows access
fun pub getExampleVariable(): int {
return exampleIntegerVariable;
}
// A getter makes more sense here, we don't want external libraries changing the value, but we want them to be able to access it.
// The variable is still private, and can only be changed from inside of this library
fun pub getChangeableHighPrecisionFloatVariable(): float64 {
return changeableHighPrecisionFloatVariable;
}
fun pub add(a: float, b: float): float {
return a + b;
}
}
// There may be multiple libraries in file. Only one main function is required in an entire program, which
// may be spread over multiple files and libraries
lib sample.namespace:SecondTest {
// std:IO includes basic functions for printing to the screen and polling the terminal
use std:IO;
use sample.namespace:TestProgram;
fun pub returnName(name: str) {
// Array declaration is "{ VALUES }: type...
// The "printLn" method in the IO library takes one parameter or optionally two. The second is an array of values to insert into the message where the "{}" are/is found
IO:printLn("Hello, {}", { name }: str...);
}
fun pub askForName() {
IO:printLn("Please enter your name");
}
fun pub doTestAdd() {
IO:printLn("5.3 + 2.0 = {}", { TestProgram:add(5.3, 2.0) }: float...);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment