summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhenesy <henesy.dev@gmail.com>2019-03-11 22:20:41 -0500
committerhenesy <henesy.dev@gmail.com>2019-03-11 22:20:41 -0500
commit747ef3dcbcb100c40659805d13d966540a892319 (patch)
tree8528d1abb0dad5ff67bf04168d1d4661d91b8918
parentcd8fd72bbb8de47f88390db0f13add61da2c90a1 (diff)
add function references example
-rw-r--r--Function-Refs/README.md21
-rw-r--r--Function-Refs/funcrefs.b6
-rw-r--r--README.md1
3 files changed, 23 insertions, 5 deletions
diff --git a/Function-Refs/README.md b/Function-Refs/README.md
index 09a6715..1b2dd5b 100644
--- a/Function-Refs/README.md
+++ b/Function-Refs/README.md
@@ -6,14 +6,31 @@ The example in this section is a derivative of the function reference summary in
## Source
-###
+### funcrefs.b:18,34
+The variable `fp` is a name whose type is a reference to a function with a given argument and return value scheme. A function which fulfills this scheme can be used to set the reference, in this case the `cmp()` function is referenced by `fp`.
+### funcrefs.b:36,46
-## Demo
+The `sort()` function takes a function reference as an argument, using it as a comparator. In this case `cmp()` and `rcmp()` are passed as a function reference argument.
+
+### funcrefs.b:48,53
+The `choose()` function returns a reference to a function, being called in this case to return a given comparator with the comparator being called in-line.
+
+## Demo
+ ; limbo funcrefs.b
+ ; funcrefs
+ Matched smiley!
+ Did not match duck
+ [ d b c a]
+ [ a b c d]
+ [ d c b a]
+ quack ≥ quack
+ ;
## Exercises
- Change the value of `c` to 1, what happens?
+- Write a function which returns a function which returns a function.
diff --git a/Function-Refs/funcrefs.b b/Function-Refs/funcrefs.b
index d4b7259..deb6ed1 100644
--- a/Function-Refs/funcrefs.b
+++ b/Function-Refs/funcrefs.b
@@ -47,10 +47,10 @@ init(nil: ref Draw->Context, nil: list of string) {
c := 0;
- if(choose(c)("quack", "quack") <= 0)
- print("quack ≤ quack\n");
+ if(choose(c)("quack", "quack") >= 0)
+ print("quack ≥ quack\n");
else
- print("quack > quack\n");
+ print("quack < quack\n");
exit;
}
diff --git a/README.md b/README.md
index 3246b96..9a50133 100644
--- a/README.md
+++ b/README.md
@@ -36,6 +36,7 @@ You could then run said file with:
- [Switch Case](./Switch)
- [Arrays](./Arrays)
- [Functions](./Functions)
+- [Function References](./Function-Refs)
- [Generics, Picks, and Interfaces (kind of)](./Generics)
## References