Skip to content

Commit 2b78885

Browse files
authored
Update fn to function (#13)
1 parent f84aba0 commit 2b78885

File tree

15 files changed

+205
-187
lines changed

15 files changed

+205
-187
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# The Gom Programming Language
22

3-
**Gom** is a statically typed, multi-paradigm programming language based on a subset of the ECMAScript (and Rust) syntax but providing type-safety and concise syntax. It can be interpreted or compiled to C code or LLVM IR. It takes inspiration from AssemblyScript and makes it more approachable to learn compiler construction.
3+
**Gom** is a statically typed, compiled programming language based on a subset of TypeScript's syntax. Imagine writing TypeScript, but instead of compiling to JavaScript, it compiles to LLVM IR which can then be compiled directly to machine code.
44

55
Here’s a typical hello world program in Gom:
66

77
```ts
88
import io;
99

10-
fn main() {
10+
function main() {
1111
io.log("Hello, world!");
1212
}
1313
```
@@ -19,29 +19,31 @@ Simple arithmetic and function declaration looks like this:
1919
```ts
2020
import io;
2121

22-
fn add(a: int, b: int): int {
22+
function add(a: int, b: int): int {
2323
return a + b;
2424
}
2525

26-
fn main() {
26+
function main() {
2727
io.log("Sum:", add(1, 2)); // Prints "Sum: 3"
2828
}
2929
```
3030
31-
Defining complex data structures is possible via the `struct` notation (like `struct` in C/Rust/Go). `let` is the variable declaration keyword, it infers type from the expression on the right hand side of `=`.
31+
Defining complex data structures is possible via the `type` keyword. `let` is the variable declaration keyword, it infers type from the expression on the right hand side of `=`.
3232
3333
```ts
3434
import io;
3535

36+
// List
3637
type Numbers = [int];
3738

39+
// Struct
3840
type Temperature = {
3941
high: int,
4042
low: int,
4143
avg: int
4244
};
4345

44-
fn main() {
46+
function main() {
4547
let a = 1; // type inferred as int
4648
io.log("a: ", a);
4749

@@ -60,7 +62,7 @@ fn main() {
6062
}
6163
```
6264
63-
Apart from the built-in types, custom types can be created using the `type` keyword.
65+
Other types can be defined using the `type` keyword.
6466
6567
```ts
6668
type Count = int;

examples/hello_world.gom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import io;
22

3-
fn main() {
3+
function main() {
44
io.log("Hello, World!");
55
}

examples/list.gom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Status = {
88
type StatusList = [Status];
99
type Pairs = [{ int, int }];
1010

11-
fn main() {
11+
function main() {
1212
let numbers = Numbers { 1, 2, 3, 4, 5 };
1313

1414
let i = 0;

examples/loop.gom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import io;
22

3-
fn main() {
3+
function main() {
44
let i = 0;
55
for (i = 0; i < 10; i = i + 1) {
66
io.log("i: ", i);

examples/methods.gom

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import io;
2+
3+
type Status = {
4+
code: int,
5+
success: bool,
6+
7+
function print() {
8+
io.log("Status { code: ", code, ", success: ", success, " }");
9+
}
10+
};
11+
12+
function main() {
13+
let status = Status { code: 200, success: true };
14+
io.log("Printing status:");
15+
status.print();
16+
}

examples/readme.gom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Temperature = {
88
avg: int
99
};
1010

11-
fn main() {
11+
function main() {
1212
let a = 1; // type inferred as int
1313
io.log("a: ", a);
1414

examples/recursion.gom

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import io;
22

3-
fn power_n(x: int, n: int): int {
3+
function power_n(x: int, n: int): int {
44
if (n == 0) {
55
return 1;
66
}
77
return x * power_n(x, n - 1);
88
}
99

10-
fn main() {
10+
function main() {
1111
io.log("Hello, World!");
1212
io.log("2^3 = ", power_n(2, 3));
1313
}

examples/test_2.gom

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ type Line = {
1313

1414
let GLOBAL = 1;
1515

16-
fn square(x: int): int {
16+
function square(x: int): int {
1717
return x * x;
1818
}
1919

20-
fn add(a: int, b: int): int {
20+
function add(a: int, b: int): int {
2121
return a + b;
2222
}
2323

24-
fn distance(p1: Point, p2: Point): int {
24+
function distance(p1: Point, p2: Point): int {
2525
return square(p1.x - p2.x) + square(p1.y - p2.y);
2626
}
2727

28-
fn main() {
28+
function main() {
2929
let p1 = Point { x: 1, y: 2 }, p2 = Point { x: 3, y: 4 };
3030
let d = distance(p1, p2);
3131
io.log("Distance between p1 and p2: ", d);

examples/test_3.gom

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import io;
44
type HttpResponse = { int, bool };
55

66

7-
fn process_http(url: str): HttpResponse {
7+
function process_http(url: str): HttpResponse {
88
if(url == "http://www.example.com") {
99
return { 200, true };
1010
}
1111

1212
return { 401, false };
1313
}
1414

15-
fn process_http_retry(url: str, retries: int): HttpResponse {
15+
function process_http_retry(url: str, retries: int): HttpResponse {
1616
let i = 0;
1717
for(i = retries; i > 0; i = i - 1) {
1818
io.log("Round: ", retries - i + 1);
@@ -25,7 +25,7 @@ fn process_http_retry(url: str, retries: int): HttpResponse {
2525
return { 500, false };
2626
}
2727

28-
fn main() {
28+
function main() {
2929
let resp = process_http_retry("http://www.example.com", 10);
3030
io.log("Status: ", resp.0, " Success: ", resp.1);
3131
}

gom.ebnf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ typeOrFunctionDefinition = typeDefinition | functionDefinition;
66
77
typeDefinition = "type" , identifier , "=" , gomType , ";";
88
9-
functionDefinition = "fn" , identifier , "(" , argumentItem* , ")" , functionReturnType? ,
9+
functionDefinition = "function" , identifier , "(" , argumentItem* , ")" , functionReturnType? ,
1010
"{" , statement+ , "}";
1111
12-
mainFunction = "fn" , "main" , "(" , argumentItem* , ")" , functionReturnType? ,
12+
mainFunction = "function" , "main" , "(" , argumentItem* , ")" , functionReturnType? ,
1313
"{" , statement+ , "}";
1414
1515
statement = ifStatement

0 commit comments

Comments
 (0)