aboutsummaryrefslogtreecommitdiff
path: root/documentation/book/the_lux_programming_language/appendix_f.md
diff options
context:
space:
mode:
authorEduardo Julian2021-09-20 23:01:35 -0400
committerEduardo Julian2021-09-20 23:01:35 -0400
commit8196ab379495ab00c11b74b55b6f2fabd99ab351 (patch)
tree07b5e9eacbe1532ff4eb7506ac5d492e367b1d7b /documentation/book/the_lux_programming_language/appendix_f.md
parent0bc2c541ab27e44b760618d15a248a794ab2f98e (diff)
Updates and fixes for the book.
Diffstat (limited to 'documentation/book/the_lux_programming_language/appendix_f.md')
-rw-r--r--documentation/book/the_lux_programming_language/appendix_f.md25
1 files changed, 13 insertions, 12 deletions
diff --git a/documentation/book/the_lux_programming_language/appendix_f.md b/documentation/book/the_lux_programming_language/appendix_f.md
index 461d54417..37b0788d3 100644
--- a/documentation/book/the_lux_programming_language/appendix_f.md
+++ b/documentation/book/the_lux_programming_language/appendix_f.md
@@ -1,6 +1,6 @@
# Appendix F: Implicit polymorphism
-If you've used Lux's interfaces and implementations already (with the `\` macro), you've probably noticed that you need to pass around the specific implementations you need every time you want to call some interface's method, or access some constant value.
+If you've used Lux's interfaces and implementations already (with the `#` macro), you've probably noticed that you need to pass around the specific implementations you need every time you want to call some interface's method.
That can become tiresome if you need to do it all the time, and specially if you come from languages that do method-selection for you automatically.
@@ -19,19 +19,20 @@ Why do you have to pay for something you're not taking advantage of?
Clearly, there is an asymmetry here.
It is a feature that is most useful in the few instances when you want full power.
+
At any other point, it's a hindrance.
Well... there is an alternative.
-The Lux Standard Library includes a module called `library/lux/type/implicit`, which provides a macro called `\\`, that serves as an easier-to-use alternative to the `\` macro.
+The Lux Standard Library includes a module called `library/lux/type/implicit`, which provides a macro called `##`, that serves as an easier-to-use alternative to the `#` macro.
-What it does is that instead of requiring the implementation you want to use, it only requires the name of the function you want to call and the arguments.
+What it does is that instead of requiring the implementation you want to use, it only requires the name of the method you want to call and the arguments.
Then, at compile-time, it does some type-checking and some look-ups and selects an implementation for you that will satisfy those requirements.
That implementation can come from the local-var environment, from the definitions in your own module, or even from the exported definitions of the modules you're importing.
-That way, you can use `\` whenever you need precision and power, and use `\\` whenever you're doing more lightweight programming.
+That way, you can use `#` whenever you need precision and power, and use `##` whenever you're doing more lightweight programming.
Fantastic!
@@ -39,30 +40,30 @@ This is how you'd use it:
```clojure
... Equality for nats
-(\ nat.equivalence = x y)
-## vs
-(\\ = x y)
+(# nat.equivalence = x y)
+... vs
+(## = x y)
```
```clojure
... Equality for lists of nats
-(\ (list.equivalence nat.equivalence) =
+(# (list.equivalence nat.equivalence) =
(list.indices 10)
(list.indices 10))
... vs
-(\\ = (list.indices 10) (list.indices 10))
+(## = (list.indices 10) (list.indices 10))
```
```clojure
... Functor mapping
-(\ list.functor each nat.inc (list.indices 10))
+(# list.functor each ++ (list.indices 10))
... vs
-(\\ each nat.inc (list.indices 10))
+(## each ++ (list.indices 10))
```
---
Thanks to implicit polymorphism, you don't have to choose between power and ease of use.
-Just do a static-import of the `library/lux/type/implicit` module, and you'll get the `\\` available and ready for action.
+Just do a static-import of the `library/lux/type/implicit` module, and you'll get the `##` available and ready for action.