+
+
+
+
+
+ Map Class
+ An associative collection that maps keys to values. More details here .
+clear
+Removes all entries from the map.
+containsKey (key)
+Returns true if the map contains key or false otherwise.
+count
+The number of entries in the map.
+keys
+A Sequence that can be used to iterate over the keys in the
+map. Note that iteration order is undefined. All keys will be iterated over,
+but may be in any order, and may even change between invocations of Wren.
+iterate (iterator), iteratorValue (iterator)
+Implements the iterator protocol
+for iterating over the elements in the list.
+remove (key)
+Removes [key] and the value associated with it from the map. Returns the value.
+If the key was not present, returns null.
+values
+A Sequence that can be used to iterate over the values in the
+map. Note that iteration order is undefined. All values will be iterated over,
+but may be in any order, and may even change between invocations of Wren.
+If multiple keys are associated with the same value, the value will appear
+multiple times in the sequence.
+[ key] operator
+Gets the value associated with key in the map. If key is not present in the
+map, returns null.
+var map = { "george" : "harrison" , "ringo" : "starr" }
+IO . print ( map [ "ringo" ]) // "starr".
+IO . print ( map [ "pete" ]) // "null".
+
+
+
+[ key]= (value) operator
+Associates value with key in the map. If key was already in the map, this
+replaces the previous association.
+It is a runtime error if the key is not a Bool ,
+Class , Null , Num , Range ,
+or String .
+
+
+
+
+
+
Wren lives on GitHub — Made with ❤ by Bob Nystrom .
+
+
+
+
+
\ No newline at end of file
diff --git a/core/null.html b/core/null.html
index 20cd3506..7924a287 100644
--- a/core/null.html
+++ b/core/null.html
@@ -31,6 +31,7 @@
Fiber
Fn
List
+
Map
Null
Num
Object
diff --git a/core/num.html b/core/num.html
index e451bfa0..b507e0b9 100644
--- a/core/num.html
+++ b/core/num.html
@@ -31,6 +31,7 @@
Fiber
Fn
List
+
Map
Null
Num
Object
diff --git a/core/object.html b/core/object.html
index 53d396f7..8da8d74b 100644
--- a/core/object.html
+++ b/core/object.html
@@ -31,6 +31,7 @@
Fiber
Fn
List
+
Map
Null
Num
Object
diff --git a/core/range.html b/core/range.html
index 17ab34c8..00c3c992 100644
--- a/core/range.html
+++ b/core/range.html
@@ -31,6 +31,7 @@
Fiber
Fn
List
+
Map
Null
Num
Object
diff --git a/core/sequence.html b/core/sequence.html
index 3d7d64b8..a62362cf 100644
--- a/core/sequence.html
+++ b/core/sequence.html
@@ -31,6 +31,7 @@
Fiber
Fn
List
+
Map
Null
Num
Object
@@ -54,6 +55,12 @@ If it returns
false, stops iterating and returns
false
+
join (sep)
+
Returns a string representation of the list. The string representations of the
+elements in the list is concatenated with intervening occurrences of sep.
+
It is a runtime error if sep is not a string.
+
join
+
Calls join with the empty string as the separator.
map (transformation)
Creates a new list by applying transformation to each element in the
sequence.
diff --git a/core/string.html b/core/string.html
index a5e14161..fa8fd21d 100644
--- a/core/string.html
+++ b/core/string.html
@@ -31,6 +31,7 @@
Fiber
Fn
List
+
Map
Null
Num
Object
diff --git a/functions.html b/functions.html
index d67aac4b..b7f23fac 100644
--- a/functions.html
+++ b/functions.html
@@ -163,8 +163,8 @@ of the body, like so:
-It's an error to call a function with fewer or more arguments than its
-parameter list expects.
+It's an error to call a function with fewer arguments than its parameter list
+expects. If you pass too many arguments, the extras are ignored.
Returning values
The body of a function is a block . If it is a single
expression—more precisely if there is no newline after the { or
diff --git a/getting-started.html b/getting-started.html
index 2dc453f6..0d4ed5d5 100644
--- a/getting-started.html
+++ b/getting-started.html
@@ -67,13 +67,10 @@ Mac and you can rock a command line, it's just:
-For Mac users, there is also an XCode project in the repo that you can use to
-hack on Wren. That's what I develop in. It builds fine from there but may not
-have the exact same build settings. The Makefile is the canonical way to
-compile it.
-For our Windows brethren, there's still a little work to be done. Ideally, the
-repo would include a Visual Studio solution for building Wren. I don't have a
-Windows machine, but if you do, I would be delighted to take a patch for this.
+For Mac users, there is also an XCode project under project/xcode. For
+Windows brethren, project/msvc2013 contains a Visual Studio solution. Note
+that these may not have the exact same build settings as the makefile. The
+makefile is the "official" way to compile Wren.
Interactive mode
The above instructions will drop you into Wren's standalone interpreter in
interactive mode. You can type in a line of code, and it will immediately
diff --git a/maps.html b/maps.html
index c4027d49..8bf9ee3f 100644
--- a/maps.html
+++ b/maps.html
@@ -57,8 +57,97 @@
Maps
- Wren will have a built-in hash table type similar to objects in JavaScript and
-tables in Lua, but they haven't been implemented yet.
+ A map is an associative collection. It holds a set of entries, each of which
+maps a key to a value . The same data structure has a variety of names in
+other languages: hash table, dictionary, association, table, etc.
+You can create a map by placing a series of comma-separated entries inside
+curly braces. Each entry is a key and a value separated by a colon:
+{
+ "George" : "Harrison" ,
+ "John" : "Lennon" ,
+ "Paul" : "McCartney" ,
+ "Ringo" : "Starr"
+}
+
+
+
+This creates a map that maps the first names of the Beatles to their last
+names. Syntactically, in a map literal, keys can be any literal, a variable name, or a parenthesized expression. Values can be any expression. Here, we're using string literals for both keys and values.
+Semantically , values can be any object, and multiple keys may map to the
+same value. Keys have a few limitations. They must be one of the immutable
+built-in value types in Wren. That means a number, string,
+range, bool, or null. You can also use a class object as a
+key.
+The reason for this limitation—and the reason maps are called "hash tables" in other languages—is that each key is used to generate a numeric hash code . This lets a map locate the value associated with a key in constant time, even in very large maps. Since Wren only knows how to hash certain built-in types, only those can be used as keys.
+Adding entries
+You add new key-value pairs to the map by using the subscript operator :
+var capitals = {}
+capitals [ "Georgia" ] = "Atlanta"
+capitals [ "Idaho" ] = "Boise"
+capitals [ "Maine" ] = "Augusta"
+
+
+
+If the key isn't already present, this adds it and associates it with the given value. If the key is already there, this just replaces its value.
+Looking up values
+To find the value associated with some key, again you use your friend the subscript operator:
+IO . print ( capitals [ "Idaho" ]) // "Boise".
+
+
+
+If the key is present, this returns its value. Otherwise, it returns null. Of course, null itself can also be used as a value, so seeing null here doesn't necessarily mean the key wasn't found.
+To tell definitively if a key exists, you can call containsKey():
+var belief = { "nihilism" : null }
+
+IO . print ( belief [ "nihilism" ]) // "null" though key exists.
+IO . print ( belief [ "solipsism" ]) // Also "null".
+IO . print ( belief . containsKey ( "nihilism" )) // "true".
+IO . print ( belief . containsKey ( "solipsism" )) // "false".
+
+
+
+You can see how many entries a map contains using count:
+IO . print ( capitals . count ) // "3".
+
+
+
+Removing entries
+To remove an entry from a map, call remove() and pass in the key for the entry you want to delete:
+capitals . remove ( "Maine" )
+IO . print ( capitals . containsKey ( "Maine" )) // "false".
+
+
+
+If the key was found, this returns the value that was associated with it:
+IO . print ( capitals . remove ( "Georgia" )) // "Atlanta".
+
+
+
+If the key wasn't in the map to begin with, remove() just returns null.
+If you want to remove everything from the map, just like with lists , you
+can just call clear:
+capitals . clear
+IO . print ( capitals . count ) // "0".
+
+
+
+Iterating over the contents
+The subscript operator works well for finding values when you know the key you're looking for, but sometimes you want to see everything that's in the map. For that, map exposes two methods: keys and values.
+The first returns a Sequence that iterates over all of the keys in the map, and the second returns one that iterates over the values.
+If you want to see all of the key-value pairs in a map, the easiest way is to iterate over the keys and use each to look up its value:
+var stateBirds = {
+ "Arizona" : "Cactus wren" ,
+ "Hawaii" : "Nēnē" ,
+ "Ohio" : "Northern Cardinal"
+}
+
+for ( state in stateBirds . keys ) {
+ IO . print ( "The state bird of " , state , " is " , stateBirds [ state ])
+}
+
+
+
+This program will print the three states and their birds. However, the order that they are printed isn't defined. Wren makes no promises about what order keys and values will be iterated in when you use these methods. All it promises is that every entry will appear exactly once.
diff --git a/values.html b/values.html
index e2c5140a..8f1ffa88 100644
--- a/values.html
+++ b/values.html
@@ -64,7 +64,7 @@ All values are immutable —once created, they do not change. The nu
character array modified in place.
Booleans
A boolean value represents truth or falsehood. There are two boolean literals,
-true and false. Their class is Bool.
+true and false. Their class is Bool .
Numbers
Like other scripting languages, Wren has a single numeric type:
double-precision floating point. Number literals look like you expect coming
@@ -78,10 +78,10 @@ from other languages:
-Numbers are instances of the Num class.
+Numbers are instances of the Num class.
Strings
-Strings are chunks of text stored as UTF-8. Their class is String. String
-literals are surrounded in double quotes:
+Strings are chunks of text stored as UTF-8. Their class is
+String . String literals are surrounded in double quotes:
@@ -126,11 +126,13 @@ example:
+Their class is Range
Null
Wren has a special value null, which is the only instance of the class
-Null. (Note the difference in case.) It functions a bit like void in some
-languages: it indicates the absence of a value. If you call a method that
-doesn't return anything and get its returned value, you get null back.
+Null . (Note the difference in case.) It functions a bit like
+void in some languages: it indicates the absence of a value. If you call a
+method that doesn't return anything and get its returned value, you get null
+back.