G Sharp
- The title of this article is not correct because of technical limitations. The correct title is actually G#.
G# is a esolang with the syntax similar to Python and C
Syntax
Commands
Command | It's action |
---|---|
make <classname>; | Creates a class, |
print <string> | Prints a string. |
assign <varname> as <varval> | Creates/Edits a variable. |
loop if <condition> | while statement. |
if/else/orif | Condition command. |
input | Gets user input |
# | One-line comment |
###...### | Multi-line comments |
return | turns a class into a function |
Classes
A Class should folow this structure:
make a_name_here; [ # Commands here ]
Variables
The variables NEED to be assigned at the top.
Also there are types:
Type name | Type symbol |
---|---|
String | $ |
Integer | # |
Boolean | ? |
Ticker | + |
And if you want to edit a variable. You just write:
assign $a to anything
And if you want to assign more variables with the same value, write:
assign a;b to anything
This implies to the variable edition as well
Functions
Functions are basically the same as Classes. "But how do make functions?" you may ask. Simple. Just add a return command and some arguments:
return {written}{like}{this}
And to use the argument on a function, We just write:
f[name]{the argument used in your function}
So the function should look like this:
make function; [ return {arg}{another arg} # Commands here ]
And to call a function:
f[function]{Hello, ||world!}
And now you're probably saying, "So if an argument is used, it's automatically an required argument, right?"
Yes, but you can turn off the "require" option if it's not really required:
make fun [ return{arg#require=0} # Commands here ]
Errors
If no main class is found in the code:
NO MAIN CLASS FOUND IN CODE
If a built-in function gets overwritten by another function:
CANNOT OVERWRITE BUILT-IN
Examples
Hello World
make main; [print("Hello World",\n)]
Cat program
string assign a as input make main; [print($a)]
A+B problem
integer assign a;b as input make main; [print(#a+#b)]
Infinite loop
boolean assign l to 1 make main; [loop if ?l is 0 [print(1)]]
Truth-machine
integer assign i as input boolean assign l to 1 make main; [ if #i is 0 [print(0)] orif #i is 1 [loop if ?l=1 [print(1)] ] ]
Empty Program
make e; [return{}] make main; [f[e]{}]
99 bottles of beer
integer assign bot as 99 make main; [ if #bot is 1 [ print(#bot," bottle of beer on the wall,",\n) print(#bot," bottle of beer.",\n) print("Take one down, Pass it around,",\n) print("No bottles of beer on the wall,",\n) ] else [ loop if #bot ! 1 [ print(#bot," bottles of beer on the wall,",\n) print(#bot," bottles of beer.",\n) print("Take one down, Pass it around,",\n) assign #bot as 1 - print(#bot," bottles of beer on the wall,",\n,\n) ] ] ]