summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bash.html.markdown10
-rw-r--r--c++.html.markdown3
-rw-r--r--haskell.html.markdown2
-rw-r--r--python.html.markdown10
-rw-r--r--standard-ml.html.markdown24
5 files changed, 38 insertions, 11 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index 35bed9a2..e0c12f97 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -10,6 +10,7 @@ contributors:
- ["Anton Strömkvist", "http://lutic.org/"]
- ["Rahil Momin", "https://github.com/iamrahil"]
- ["Gregrory Kielian", "https://github.com/gskielian"]
+ - ["Etan Reisner", "https://github.com/deryni"]
filename: LearnBash.sh
---
@@ -36,7 +37,14 @@ VARIABLE="Some string"
# But not like this:
VARIABLE = "Some string"
# Bash will decide that VARIABLE is a command it must execute and give an error
-# because it couldn't be found.
+# because it can't be found.
+
+# Or like this:
+VARIABLE= 'Some string'
+# Bash will decide that 'Some string' is a command it must execute and give an
+# error because it can't be found. (In this case the 'VARIABLE=' part is seen
+# as a variable assignment valid only for the scope of the 'Some string'
+# command.)
# Using the variable:
echo $VARIABLE
diff --git a/c++.html.markdown b/c++.html.markdown
index 1a84efa4..ae93ceba 100644
--- a/c++.html.markdown
+++ b/c++.html.markdown
@@ -32,8 +32,7 @@ one of the most widely-used programming languages.
// variable declarations, primitive types, and functions.
// Just like in C, your program's entry point is a function called
-// main with an integer return type,
-// though void main() is also accepted by most compilers (gcc, clang, etc.)
+// main with an integer return type.
// This value serves as the program's exit status.
// See http://en.wikipedia.org/wiki/Exit_status for more information.
int main(int argc, char** argv)
diff --git a/haskell.html.markdown b/haskell.html.markdown
index f28fcfe7..6a64442f 100644
--- a/haskell.html.markdown
+++ b/haskell.html.markdown
@@ -282,7 +282,7 @@ foldl (\x y -> 2*x + y) 4 [1,2,3] -- 43
foldr (\x y -> 2*x + y) 4 [1,2,3] -- 16
-- This is now the same as
-(2 * 3 + (2 * 2 + (2 * 1 + 4)))
+(2 * 1 + (2 * 2 + (2 * 3 + 4)))
----------------------------------------------------
-- 7. Data Types
diff --git a/python.html.markdown b/python.html.markdown
index 7281a330..ace3f794 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -46,7 +46,7 @@ to Python 2.x. For Python 3.x, take a look at the [Python 3 tutorial](http://lea
2.0 # This is a float
11.0 / 4.0 # => 2.75 ahhh...much better
-# Result of integer division truncated down both for positive and negative.
+# Result of integer division truncated down both for positive and negative.
5 // 3 # => 1
5.0 // 3.0 # => 1.0 # works on floats too
-5 // 3 # => -2
@@ -191,14 +191,14 @@ li[2:] # => [4, 3]
li[:3] # => [1, 2, 4]
# Select every second entry
li[::2] # =>[1, 4]
-# Revert the list
+# Reverse a copy of the list
li[::-1] # => [3, 4, 2, 1]
# Use any combination of these to make advanced slices
# li[start:end:step]
# Remove arbitrary elements from a list with "del"
del li[2] # li is now [1, 2, 3]
-
+r
# You can add lists
li + other_li # => [1, 2, 3, 4, 5, 6]
# Note: values for li and for other_li are not modified.
@@ -439,14 +439,14 @@ def pass_all_the_args(*args, **kwargs):
print varargs(*args)
print keyword_args(**kwargs)
-# Function Scope
+# Function Scope
x = 5
def setX(num):
# Local var x not the same as global variable x
x = num # => 43
print x # => 43
-
+
def setGlobalX(num):
global x
print x # => 5
diff --git a/standard-ml.html.markdown b/standard-ml.html.markdown
index b545f3e1..07896beb 100644
--- a/standard-ml.html.markdown
+++ b/standard-ml.html.markdown
@@ -3,13 +3,14 @@ language: "Standard ML"
contributors:
- ["Simon Shine", "http://shine.eu.org/"]
- ["David Pedersen", "http://lonelyproton.com/"]
+ - ["James Baker", "http://www.jbaker.io/"]
---
Standard ML is a functional programming language with type inference and some
side-effects. Some of the hard parts of learning Standard ML are: Recursion,
pattern matching, type inference (guessing the right types but never allowing
-implicit type conversion). If you have an imperative background, not being able
-to update variables can feel severely inhibiting.
+implicit type conversion). Standard ML is distinguished from Haskell by including
+references, allowing variables to be updated.
```ocaml
(* Comments in Standard ML begin with (* and end with *). Comments can be
@@ -383,6 +384,25 @@ val test_poem = readPoem "roses.txt" (* gives [ "Roses are red,",
"Violets are blue.",
"I have a gun.",
"Get in the van." ] *)
+
+(* We can create references to data which can be updated *)
+val counter = ref 0 (* Produce a reference with the ref function *)
+
+(* Assign to a reference with the assignment operator *)
+fun set_five reference = reference := 5
+
+(* Read a reference with the dereference operator *)
+fun equals_five reference = !reference = 5
+
+(* We can use while loops for when recursion is messy *)
+fun decrement_to_zero r = if !r < 0
+ then r := 0
+ else while !r >= 0 do r := !r - 1
+
+(* This returns the unit value (in practical terms, nothing, a 0-tuple) *)
+
+(* To allow returning a value, we can use the semicolon to sequence evaluations *)
+fun decrement_ret x y = (x := !x - 1; y)
```
## Further learning