From 1550ff919d4f347417335a058357c4b164b02f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 28 Sep 2021 23:48:51 +0200 Subject: [PATCH 1/2] Add some examples --- README.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/README.md b/README.md index 7692494..7cf66d1 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,82 @@ or download from [releases](https://github.com/Flipez/rocket-lang/releases). * `rocket-lang FILE` will run the code in that file (no file extension check yet) * Use _Javascript_ Highlighting in your editor for some convenience * Checkout Code [Samples](examples/) for what is currently possible (and what not) + +## Examples +### Variables +```js +let some_integer = 1; +let name = "RocketLang"; +let array = [1, 2, 3, 4, 5]; +let some_boolean = true; +``` + +Also expressions can be used +```js +let another_int = (10 / 2) * 5 + 30; +let an_array = [1 + 1, 2 * 2, 3]; +``` + +### Functions +Implicit and explicit return statements are supported. +```js +let fibonacci = fn(x) { + if (x == 0) { + 0 + } else { + if (x == 1) { + return 1; + } else { + fibonacci(x - 1) + fibonacci(x - 2); + } + } +}; +``` +### Closures +```js +let newGreeter = fn(greeting) { + return fn(name) { puts(greeting + " " + name); } +}; + +let hello = newGreeter("Hello"); + +hello("dear, future Reader!"); + +``` + +### Data Types +#### Strings +```js +let a = "test_string; + +let b = "test" + "_string"; + +let is_true = "test" == "test"; +let is_false = "test" == "string"; +``` + +#### Integer +```js +let a = 1; + +let b = a + 2; + +let is_true = 1 == 1; +let is_false = 1 == 2; +``` + +#### Boolean +```js +let a = true; +let b = false; + +let is_true = a == a; +let is_false = a == b; + +let is_true = a != b; +``` + +#### Hashes +```js +let people = [{"name": "Anna", "age": 24}, {"name": "Bob", "age": 99}]; +``` From 4d20bd72adebe77adaba7e3a7f56387919fb009e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 28 Sep 2021 23:53:34 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7cf66d1..855a1b7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ [![goreleaser](https://github.com/Flipez/rocket-lang/actions/workflows/release.yml/badge.svg)](https://github.com/Flipez/rocket-lang/actions/workflows/release.yml) -# General +# 🚀🇱🅰🆖 -RocketLang as of version 0.9.5 is the _full_ (as in the book was worked through) version of [MonkeyLang](https://monkeylang.org/) +RocketLang as of version 0.9.5 is the _full_ (as in the book was worked through) version of [MonkeyLang](https://monkeylang.org/) and is then being extended with various useful and not so useful features. ## Installation