aboutsummaryrefslogtreecommitdiff
path: root/tour/modules.sloth
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-01-29 20:58:04 -0600
committerCody <cody@codyq.dev>2023-01-29 20:58:04 -0600
commita653a6602fe5ae5eb4739755db7b34bc92ecdadf (patch)
tree2d99c570ccd77767e1d5fcf9b098d45c79cbe6e4 /tour/modules.sloth
parentb856e5c7226e71e500be5eff7079c5d3b0e9e2f4 (diff)
downloadsloth-a653a6602fe5ae5eb4739755db7b34bc92ecdadf.tar.gz
More stuffs
Diffstat (limited to 'tour/modules.sloth')
-rw-r--r--tour/modules.sloth49
1 files changed, 40 insertions, 9 deletions
diff --git a/tour/modules.sloth b/tour/modules.sloth
index 1523753..b91261e 100644
--- a/tour/modules.sloth
+++ b/tour/modules.sloth
@@ -24,18 +24,49 @@ use extern "git://github.com/CatDevz/AdventOfCode.git" as spookylib;
use extern "ftp://codyq.dev/libs/spookylib.sloth" as spookylib;
use extern "https://codyq.dev/libs/spookylib.sloth" as spookylib;
-# In order to use modules or members of modules without quantifying the entire
-# path you must include them using a `use` statement. Star imports do not exist
-# because they fucking suck.
+# In sloth files will automatically become modules. Files named `mod.sloth` will
+# become the module for the directory. If you have a project with multiple files
+# the root module will be `mod.sloth`. Anything exposed in this can just strait up
+# be used.
#
+# If no `mod.sloth` exists, for example when running single file scripts, it will
+# be trated as if there is one but its empty.
+
+# /mod.sloth
+pub fn fib(n: i32) -> i32 {
+ match n {
+ 0 | 1 => n,
+ _ => fib(n - 1) + fib(n - 2),
+ }
+}
+
+# /foo.sloth
+use fib; # TODO:
+
+fib(5); # Works because everything inside of mod.sloth is fair game
+
+# This means if you want an extern library to be available in every module you just
+# need to add a `pub(pkg) use extern "lib"`
+
+# In order to use modules or members of modules without quantifying the entire
+# path you must include them using a `use` statement.
+use foo::bar;
+
+# Sloth will use your root module (the one used as your entrypoint) for imports.
+# In order to import from modules relative to your own you must prefix the use
+# with a `::`
+use ::from::relative;
+
+# If you would live to traverse up the module tree you can use the `super`
+# psudo-module.
+use
+
+# TODO:
# Sloth will automatically turn files relative to your own and directories
# relative to your own with a `mod.sloth` into modules. In order to traverse
-# up the module tree you can use the `super` and `pkg` psudo-modules.
-#
-# The super psudo-module will go up a single module in the module tree whereas
-# the pkg psudo-module will go to the root module in the module tree.
-use pkg::a;
-use pkg::b;
+# up the module tree you can use the `super` psudo-module.
+use super::a;
+use super::b;
use std::rand::random;
use std::uuid;