aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/guessing.sloth8
-rw-r--r--examples/hello.sloth6
-rw-r--r--examples/read.sloth4
-rw-r--r--examples/read.txt1
-rw-r--r--examples/snake.sloth81
5 files changed, 49 insertions, 51 deletions
diff --git a/examples/guessing.sloth b/examples/guessing.sloth
index f88c35b..49c0bde 100644
--- a/examples/guessing.sloth
+++ b/examples/guessing.sloth
@@ -1,11 +1,3 @@
-foreign fn print();
-foreign fn println();
-foreign fn readln() String;
-foreign fn random(min: Int, max: Int) Int;
-foreign fn parse_int(str: String) Int;
-foreign fn randGen(min: Int, max: Int) Int;
-foreign fn istr(x: Int) String;
-
fn main() Int {
var computer: Int = randGen(1, 10);
var tries: Int = 0;
diff --git a/examples/hello.sloth b/examples/hello.sloth
index 75071c3..8f42051 100644
--- a/examples/hello.sloth
+++ b/examples/hello.sloth
@@ -1,7 +1,3 @@
-foreign fn printdeez(nutz: Int);
-foreign fn print(str: String);
-foreign fn randGen(min: Int, max: Int) Int;
-
fn main() Int {
var x: [Int] = [5];
vpopi(x);
@@ -15,7 +11,7 @@ fn main() Int {
var y: Int = vgeti(x, 45);
var y: Int = vgeti(x, 41);
var y: Int = vgeti(x, 49);
- printdeez(y);
+ println(istr(y));
print("Hello World\n");
diff --git a/examples/read.sloth b/examples/read.sloth
new file mode 100644
index 0000000..cf947f8
--- /dev/null
+++ b/examples/read.sloth
@@ -0,0 +1,4 @@
+fn main() Int {
+ print(filer("examples/read.txt"));
+ return 0;
+}
diff --git a/examples/read.txt b/examples/read.txt
new file mode 100644
index 0000000..980a0d5
--- /dev/null
+++ b/examples/read.txt
@@ -0,0 +1 @@
+Hello World!
diff --git a/examples/snake.sloth b/examples/snake.sloth
index c60819d..8283368 100644
--- a/examples/snake.sloth
+++ b/examples/snake.sloth
@@ -1,40 +1,45 @@
-var xPos = 0;
-var yPos = 0;
-# 0=right 1=down 2=left 3=up
-var direction = 0;
+fn main() Int {
+ var xPos: Int = 0;
+ var yPos: Int = 0;
+ # 0=right 1=down 2=left 3=up
+ var direction: Int = 0;
+ var x: Int = 0;
+ var y: Int = 0;
-while true {
- if direction == 0{
- var x = xPos + 1;
- xPos = x;
- }
- if direction == 1 {
- var y = yPos + 1;
- yPos = y;
- }
- if direction == 2{
- var x = xPos - 1;
- xPos = x;
- }
- if direction == 3 {
- var y = yPos - 1;
- yPos = y;
- }
-
- var input = readln();
- if input == "w" && direction != 1 {
- direction = 3;
- }
- if input == "a" && direction != 0 {
- direction = 2;
- }
- if input == "s" && direction != 3 {
- direction = 1;
- }
- if input == "d" && direction != 2 {
- direction = 0;
- }
-
- term_setpos(x, y);
- print("*");
+ while true {
+ if direction == 0{
+ x = xPos + 1;
+ xPos = x;
+ }
+ if direction == 1 {
+ y = yPos + 1;
+ yPos = y;
+ }
+ if direction == 2{
+ x = xPos - 1;
+ xPos = x;
+ }
+ if direction == 3 {
+ y = yPos - 1;
+ yPos = y;
+ }
+
+ var input: String = readln();
+ if input == "w" && direction != 1 {
+ direction = 3;
+ }
+ if input == "a" && direction != 0 {
+ direction = 2;
+ }
+ if input == "s" && direction != 3 {
+ direction = 1;
+ }
+ if input == "d" && direction != 2 {
+ direction = 0;
+ }
+
+ termpos(x, y);
+ print("*");
+ }
+ return 0;
}