From 4334700549dafa62e4a85e8b78693836ef4c5cc4 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 1 Apr 2013 07:14:23 -0500 Subject: [PATCH] Explaining cond --- docs/language/index.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/language/index.rst b/docs/language/index.rst index 3521df2..bb7a721 100644 --- a/docs/language/index.rst +++ b/docs/language/index.rst @@ -189,6 +189,28 @@ If you need to do more complex conditionals, you'll find that you don't have elif available in hy. Instead, you should use something called "cond". In python, you might do something like:: + somevar = 33 + if somevar > 50: + print "That variable is too big!" + elif somevar < 10: + print "That variable is too small!" + else: + print "That variable is jussssst right!" + +In hy, you would do:: + + (cond + (> somevar 50) (print "That variable is too big!") + (< somevar 10) (print "That variable is too small!") + true (print "That variable is jussssst right!")) + +What you'll notice is that cond switches off between a some statement +that is executed and checked conditionally for true or falseness, and +then a bit of code to execute if it turns out to be true. You'll also +notice that the "else" is implemented at the end simply by checking +for "true"... that's because true will always be true, so if we get +this far, we'll always run that one! + You can also import and make use of various python libraries. For example::