summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEvgeniy Ginzburg <Nad.Oby@gmail.com>2014-08-06 23:45:44 +0300
committerEvgeniy Ginzburg <Nad.Oby@gmail.com>2014-08-06 23:45:44 +0300
commitcb3217fc35f3097c4be5b39fb36bd74b5e415f6c (patch)
treecedbb3d549ea8f810ab720b09f1c56ba6b89dc6e
parent7bcf65278c28cffd32ef051965c2e6401563acc9 (diff)
parent4349587ac4de7bc3436f68415bcf5bdfac260e5e (diff)
Merge https://github.com/adambard/learnxinyminutes-docs
Added two minor changes in integer division to make it clear
-rw-r--r--bash.html.markdown12
-rw-r--r--perl6.html.markdown10
-rw-r--r--python.html.markdown17
-rw-r--r--python3.html.markdown17
4 files changed, 39 insertions, 17 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index 15d1c068..845ebead 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -7,6 +7,7 @@ contributors:
- ["Alexandre Medeiros", "http://alemedeiros.sdf.org"]
- ["Denis Arh", "https://github.com/darh"]
- ["akirahirose", "https://twitter.com/akirahirose"]
+ - ["Anton Strömkvist", "http://lutic.org/"]
filename: LearnBash.sh
---
@@ -81,6 +82,17 @@ fi
echo "Always executed" || echo "Only executed if first command fails"
echo "Always executed" && echo "Only executed if first command does NOT fail"
+# To use && and || with if statements, you need multiple pairs of square brackets:
+if [ $NAME == "Steve" ] && [ $AGE -eq 15 ]
+then
+ echo "This will run if $NAME is Steve AND $AGE is 15."
+fi
+
+if [ $NAME == "Daniya" ] || [ $NAME == "Zach" ]
+then
+ echo "This will run if $NAME is Daniya OR Zach."
+fi
+
# Expressions are denoted with the following format:
echo $(( 10 + 5 ))
diff --git a/perl6.html.markdown b/perl6.html.markdown
index 567c4629..92219708 100644
--- a/perl6.html.markdown
+++ b/perl6.html.markdown
@@ -92,7 +92,7 @@ sub as-many($head, *@rest) { # the `*@` slurpy will basically "take everything e
# but not *after*.
say @rest.join(' / ') ~ " !";
}
-say as-many('Happy', 'Happy', 'Birthday'); #=> Happy Birthday !
+say as-many('Happy', 'Happy', 'Birthday'); #=> Happy / Birthday !
# Note that the splat did not consume the parameter before.
## You can call a function with an array using the "argument list flattening" operator `|`
@@ -127,7 +127,7 @@ sub with-named($normal-arg, :$named) {
}
with-named(1, named => 6); #=> 7
# There's one gotcha to be aware of, here:
-# If you quote your key, Perl 6 won't be able to see it as compile time,
+# If you quote your key, Perl 6 won't be able to see it at compile time,
# and you'll have a single Pair object as a positional paramater.
with-named(2, :named(5)); #=> 7
@@ -171,9 +171,9 @@ named-def(def => 15); #=> 15
### Containers
# In Perl 6, values are actually stored in "containers".
-# the assignment operator asks the container on the left to store the value on its right
+# The assignment operator asks the container on the left to store the value on its right.
# When passed around, containers are marked as immutable. Which means that, in a function,
-# you'll get an error if you try to mutate one of your argument.
+# you'll get an error if you try to mutate one of your arguments.
# If you really need to, you can ask for a mutable container using `is rw` :
sub mutate($n is rw) {
$n++;
@@ -374,7 +374,7 @@ sub foo(@array [$fst, $snd]) {
say "My first is $fst, my second is $snd ! All in all, I'm @array[].";
# (^ remember the `[]` to interpolate the array)
}
-foo(@tail); #=> My first is 2, my second is 3 ! All in all, I'm 1 2
+foo(@tail); #=> My first is 2, my second is 3 ! All in all, I'm 2 3
# If you're not using the array itself, you can also keep it anonymous, much like a scalar:
diff --git a/python.html.markdown b/python.html.markdown
index 312e3c15..9057dde2 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -441,7 +441,10 @@ class Human(object):
# A class attribute. It is shared by all instances of this class
species = "H. sapiens"
- # Basic initializer
+ # Basic initializer, this is called when this class is instantiated.
+ # Note that the double leading and trailing underscores denote objects
+ # or attributes that are used by python but that live in user-controlled
+ # namespaces. You should not invent such names on your own.
def __init__(self, name):
# Assign the argument to the instance's name attribute
self.name = name
@@ -528,10 +531,12 @@ def double_numbers(iterable):
# Note xrange is a generator that does the same thing range does.
# Creating a list 1-900000000 would take lot of time and space to be made.
# xrange creates an xrange generator object instead of creating the entire list like range does.
-_xrange = xrange(1, 900000000)
+# We use a trailing underscore in variable names when we want to use a name that
+# would normally collide with a python keyword
+xrange_ = xrange(1, 900000000)
# will double all numbers until a result >=30 found
-for i in double_numbers(_xrange):
+for i in double_numbers(xrange_):
print(i)
if i >= 30:
break
@@ -544,10 +549,10 @@ for i in double_numbers(_xrange):
from functools import wraps
-def beg(_say):
- @wraps(_say)
+def beg(target_function):
+ @wraps(target_function)
def wrapper(*args, **kwargs):
- msg, say_please = _say(*args, **kwargs)
+ msg, say_please = target_function(*args, **kwargs)
if say_please:
return "{} {}".format(msg, "Please! I am poor :(")
return msg
diff --git a/python3.html.markdown b/python3.html.markdown
index dc972196..b494dc1e 100644
--- a/python3.html.markdown
+++ b/python3.html.markdown
@@ -470,7 +470,10 @@ class Human(object):
# A class attribute. It is shared by all instances of this class
species = "H. sapiens"
- # Basic initializer
+ # Basic initializer, this is called when this class is instantiated.
+ # Note that the double leading and trailing underscores denote objects
+ # or attributes that are used by python but that live in user-controlled
+ # namespaces. You should not invent such names on your own.
def __init__(self, name):
# Assign the argument to the instance's name attribute
self.name = name
@@ -556,9 +559,11 @@ def double_numbers(iterable):
# double_numbers.
# Note range is a generator too. Creating a list 1-900000000 would take lot of
# time to be made
-_range = range(1, 900000000)
+# We use a trailing underscore in variable names when we want to use a name that
+# would normally collide with a python keyword
+range_ = range(1, 900000000)
# will double all numbers until a result >=30 found
-for i in double_numbers(_range):
+for i in double_numbers(range_):
print(i)
if i >= 30:
break
@@ -571,10 +576,10 @@ for i in double_numbers(_range):
from functools import wraps
-def beg(_say):
- @wraps(_say)
+def beg(target_function):
+ @wraps(target_function)
def wrapper(*args, **kwargs):
- msg, say_please = _say(*args, **kwargs)
+ msg, say_please = target_function(*args, **kwargs)
if say_please:
return "{} {}".format(msg, "Please! I am poor :(")
return msg