G Sharp

From Esolang
(Redirected from User:Ractangle/G Sharp)
Jump to navigation Jump to search
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. Created by User:Ractangle

Syntax

Keywords

print Self explanatory
assign name as value Creates/Edits a variable.
loop if/if/else/orif condition While/Conditionals statement.
input Gets user input
[...] List of arguments

Classes

A Class should folow this structure:

make name(;)[
   Commands
]

Variables

The variables are required to be assigned at the top, however you can still assign them anywhere in the code and they would be placed above the code when run

There are also types you can assign to variables, which include:

Type name Type prefix
string $
integer #
boolean ?
placeholder None

"placeholder" is special as since it's the only type that can be assigned as the variables value

You can also just add the variables prefix if you don;t want to write the type name over and over again:

assign $a to void

Btw you can also assign multiple variables like in python:

assign a=b=c to void

The two methonds above work with variable editing as well

Functions

Functions are basically the same as Classes but with a return keyword

return [a1,a2]

And as since a function is a class you can use it like a class (just with arguments):

f[1,2]

You can also just make an argument shut up about being the "main charecter":

make f;[
    Commands'
    return [!a]
]

So now we know the stucture of a function!

Also fun fact: If there are no classes but only functions, the program will run the latest declared function, user input is used for the arguments

Errors

If no main class (or function) is found in the code:

NO MAIN CLASS FOUND IN CODE

Converting a value type to a different type (as long as it can't be converted):

INCORRECT TYPE CONVERSION

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 as input
integer assign b as input
make main[print[#a+#b]]

Truth-machine

make main[
    if #i=0 [print[0]]
    loop if #i [print[1]]
    return[i]
]

99 bottles of beer

integer assign bot as 99
make main[
    if #bot is 1;[ print[#bot," bottle of beer on the wall,\n",#bot," bottle of beer.\nTake one down, Pass it around,\nNo bottles of beer on the wall,\n"] ]
    else [ loop if #bot>1[
        print[#bot," bottles of beer on the wall,\n",#bot," bottles of beer.\nTake one down, Pass it around,\n"]
        assign #bot as #bot-1
        print[#bot," bottles of beer on the wall,\n\n"] 
    ]
  ]
]