summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLeah Hanson <astrieanna@gmail.com>2013-07-02 18:55:23 -0400
committerLeah Hanson <astrieanna@gmail.com>2013-07-02 18:55:23 -0400
commit0cf568d278db4cb766723e30d88b15c38f1d4536 (patch)
tree89e005763e3f87e364b525a6b26f3de3ff1a815e
parent587e35062cd129f6b7665f80daab384960863327 (diff)
finished first draft :)
-rw-r--r--julia.html.markdown35
1 files changed, 29 insertions, 6 deletions
diff --git a/julia.html.markdown b/julia.html.markdown
index e18fc3cd..f722f7ee 100644
--- a/julia.html.markdown
+++ b/julia.html.markdown
@@ -429,14 +429,37 @@ type Panther <: Cat # Panther is also a subtype of Cat
Panther() = new("green") # Panthers will only have this constructor, and no default constructor.
end
-####
-#### In progress point
-####
+# Multiple Dispatch
+
+# In Julia, all named functions are generic functions
+# This means that they are built up from many small methods
+# For example, let's make a function meow:
+function meow(cat::Lion)
+ cat.roar # access properties using dot notation
+end
+
+function meow(cat::Panther)
+ "grrr"
+end
+
+function meow(cat::Tiger)
+ "rawwwr"
+end
+
+meow(tigger) #=> "rawwr"
+meow(Lion("brown","ROAAR")) #=> "ROAAR"
+meow(Panther()) #=> "grrr"
+
+function pet_cat(cat::Cat)
+ println("The cat says $(meow(cat))")
+end
+
+pet_cat(tigger) #=> ERROR: no method pet_cat(Tiger,)
+pet_cat(Lion(Panther(),"42")) #=> prints "The cat says 42"
-#### Multiple Dispatch
## Further Reading
-#### Link to Maunual
-Still up for more? Try [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
+You can get a lot more detail from [The Julia Manual](http://docs.julialang.org/en/latest/manual/)
+