aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md4
1 files changed, 4 insertions, 0 deletions
diff --git a/README.md b/README.md
index 2093aa3..53f2f56 100644
--- a/README.md
+++ b/README.md
@@ -182,6 +182,7 @@ Functions can be overloaded by both type and arity. For example, in the standard
library, the function `reverse` is defined in two ways:
- `(reverse :[:any]) ; => :[:any]`
- `(reverse :string) ; => :string`
+
This is an example of overloading by type -- one implementation of `reverse` works
on `:[:any]`, and the other works on `:string`. The interpreter evaluates the
argument passed in, and dispatches according to the type of the argument. If a
@@ -190,6 +191,7 @@ matching implementation is not found, an error is thrown.
Another example is `exit`, defined as:
- `(exit) ; => :nil`
- `(exit :int) ; => :nil`
+
It will accept either zero or one argument, and dispatch accordingly.
Built-in functions can be overloaded by user-defined functions, and user-defined
@@ -200,6 +202,7 @@ In the case where there are multiple defined functions that can satisfy the argu
passed, an error is thrown. An example of this:
- `(my-func :[:string]) ; => :[:string]`
- `(my-func :[:number]) ; => :[:number]`
+
`my-func` above is ambiguously defined for the case of an empty list, because both
`:[:string]` and `:[:number]` are compatible with an empty list (note: this will
*only* throw an error when passed an empty list -- if a non-empty list is passed,
@@ -207,6 +210,7 @@ the function will succeed). To define this unambiguously, define it as such:
- `(my-func :{:string}) ; => :{:string}`
- `(my-func :{:number}) ; => :{:number}`
- `(my-func :nil) ; => :nil`
+
Note: the return types in this example are unimportant.
### truthiness