From 170de5223165b0f9aa763b171bed153c4073648d Mon Sep 17 00:00:00 2001 From: Patrick Sebastian Zimmermann Date: Tue, 5 Aug 2014 19:50:19 +0200 Subject: Minor fixes to return values. --- perl6.html.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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: -- cgit v1.2.3 From 472142d11f8052f6042a8cd4366c7ea7d6680c0d Mon Sep 17 00:00:00 2001 From: "Mikael E. Wikner" Date: Wed, 30 Jul 2014 11:28:21 +0200 Subject: Squashed commits to prepare for merge moved underscore for range variable, added comment renamed parameter in beg decorator added comment about double underscores Update python.html.markdown --- python.html.markdown | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/python.html.markdown b/python.html.markdown index b7d5895a..73963a3c 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -439,7 +439,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 @@ -526,10 +529,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 @@ -542,10 +547,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 -- cgit v1.2.3 From a30c76789e12e9b73278b382c42f2046692cd678 Mon Sep 17 00:00:00 2001 From: "Mikael E. Wikner" Date: Wed, 6 Aug 2014 00:20:24 +0200 Subject: Added changes to the python3 file aswell --- python3.html.markdown | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/python3.html.markdown b/python3.html.markdown index 531d3b5a..08eeb86b 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -471,7 +471,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 @@ -557,9 +560,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 @@ -572,10 +577,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 -- cgit v1.2.3 From 3f8dbe8e77ca8b1602a317e218b78df94afd8f66 Mon Sep 17 00:00:00 2001 From: LumenTeun Date: Wed, 6 Aug 2014 19:30:15 +0100 Subject: && and || in Bash if statements. --- bash.html.markdown | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 )) -- cgit v1.2.3