diff options
| author | mryouse | 2022-07-30 01:09:56 +0000 |
|---|---|---|
| committer | mryouse | 2022-07-30 01:09:56 +0000 |
| commit | f4d8e138d1c81338c0afba47620e0d1589f99941 (patch) | |
| tree | bdd8163e46a201eedbb88a21cf8f468fa4c0d7c7 /README.md | |
| parent | 1e2e0a307ee515ddf4a6de4012c02f0e8ef6d3f4 (diff) | |
bugfix: markdown formatting
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -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 |
