Fg
- This is still a work in progress. It may be changed in the future.
Paradigm(s) | Unknown |
---|---|
Designed by | User:NutronStar45 |
Appeared in | 2023 |
Computational class | Unknown |
Reference implementation | Unimplemented |
File extension(s) | Unknown |
Fg is a programming language created by User:NutronStar45.
Values
A value in Fg has a type and can have one or more supertypes.
Types
Name | Description | Example |
---|---|---|
int |
32-bit signed integer | 2147483647
|
long |
64-bit signed integer | 2147483648L
|
float |
Single-precision floating point number | 6.283185
|
double |
Double-precision floating point number | 6.28318530717959d
|
bool |
Boolean value | true
|
str |
String of characters encoded in utf-8 | "Hello World\n"
|
void |
Default return value of subroutines and functions | (void)
|
list |
Ordered collection of values | [1, 2, 3]
|
dict |
Ordered collection of key-value pairs | ["R" 0, "G" 1, "B" 1]
|
subr |
Subroutine (set of defined procedures without parameters with return value) | { (out "Hello World\n") }
|
func |
Function (set of defined procedures with parameters with return value) | (new func "args" { (out (str args)) })
|
olfunc |
Overloaded function (a function with multiple implementations) | (new olfunc func1 func2)
|
type |
Data type | (new type)
|
int
int
objects are 32-bit signed integers. They can be constructed by writing an integer in decimal, e.g. 1234
long
long
objects are 64-bit signed integers. They can be constructed by writing an integer in decimal and appending an L
after it, e.g. 2147483648L
float
float
objects are 32-bit floating point numbers (8-bit exponent and 23-bit mantissa). They can be constructed by writing a number with one decimal (.
), e.g. 1234.
double
double
objects are 64-bit floating point numbers (11-bit exponent and 52-bit mantissa). They can be constructed by writing a number with one decimal (.
) and appending an d
after it, e.g. 1234.d
bool
bool
objects are boolean values that can either be true or false. They can be constructed by writing true
or false
.
str
str
objects are strings of characters encoded in utf-8. They can be constructed by surrounding characters by single ('
) or double ("
) quotation marks, e.g. "Hello World\n"
. For including quotation marks and special characters in strings, see #Escape characters.
void
void
is the type of the default return value of subroutines and functions, and only has one value: (void)
list
list
objects are ordered collections of values that can be of different types. They can be constructed by surrounding values separated by commas (,
) with brackets ([]
), e.g. [1, 2, 3]
dict
dict
objects are ordered collections of key-value pairs, and each key and value can be of different types. They can be constructed by surrounding key-value pairs (with keys and values separated by whitespace characters) separated by commas (,
) with brackets ([]
), e.g. ["R" 0, "G" 1, "B" 1]
subr
subr
objects are sets of defined procedures that don't have parameters and may return a value. They can be constructed by surrounding the procedures separated by whitespace characters with braces ({}
), e.g. { (out "Hello World\n") (out "This is a subroutine") }
func
func
objects are sets of defined procedures that have parameters and may return a value. They can be constructed by creating a new instance of func
with the name of the variable that the list of parameters will be stored at as the first argument and the subroutine as the secon, e.g. (new func "args" { (out (str args)) })
olfunc
type
Escape characters
Escape characters are a way to include quotation marks and special characters in strings, and they start with backslashes (\
).
Escape characters in Fg include:
Structure
Whitespace characters
Built-in functions
Arithmetic
add
sub
mul
div
exp
Comparisons
eq
ne
gt
lt
ge
le
Logic
and
or
not
xor
Variables
var
set
Control flow
if
while
dowhile
repeat
iter
ret
break
continue
IO
in
out
Types
int
long
float
double
bool
str
list
dict
subr
func
olfunc
type
OOP
new
Others
join
range
ref
prop
propref
Examples
Hello World
(out "Hello World\n")
Cat
(out (in))
Truth-machine
({ (var "input" str) (set (ref "input") (in)) (if (eq input "0") { (out "0") } (eq input "1") { (repeat { (out "1\n") }) }) })
Fibonacci function
(new func "n" { (var "a" int) (var "b" int) (set (ref "a") 0) (set (ref "b") 1) (repeat n { (set (ref "b") (add a b)) (set (ref "a") (sub b a)) }) (ret a) })
99 bottles of beer
({ (var "count" subr) (set (ref "count") { (if (eq bottles 0) { (out "No") } { (out (str bottles)) }) (out (str bottles)) (out " ") (if (eq bottles 1) { (out "bottle") } { (out "bottles") }) }) (var "bottles" int) (set (ref "bottles") 99) (while (ne bottles 0) { (count) (out " of beer on the wall,\n") (count) (out " of beer.\nTake one down, pass it around,\n") (set (ref "bottles") (sub bottles 1)) (count) (out " of beer on the wall.") }) })