diff --git a/classes.html b/classes.html index 1254666b..9a4463ea 100644 --- a/classes.html +++ b/classes.html @@ -159,7 +159,7 @@ an object, or produce a new object from it:

Since the parentheses are part of the method's signature, the callsite and definition have to agree. These don't work:

-
"string".count()
+
"string".count()
 list.clear
 
diff --git a/core/bool.html b/core/bool.html index 20b02dbc..d3ffd2d5 100644 --- a/core/bool.html +++ b/core/bool.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -47,10 +48,10 @@

    Methods #

    ! operator #

    Returns the logical complement of the value.

    -
    > !true
    -false
    -> !false
    -true
    +
    > !true
    +false
    +> !false
    +true
     
    @@ -61,9 +62,9 @@ - \ No newline at end of file + diff --git a/core/class.html b/core/class.html index 3b62fc9d..44f4d202 100644 --- a/core/class.html +++ b/core/class.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -68,9 +69,9 @@ - \ No newline at end of file + diff --git a/core/fiber.html b/core/fiber.html index 45275d35..f07b2a86 100644 --- a/core/fiber.html +++ b/core/fiber.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -155,9 +156,9 @@ run. This returns false if the fiber is currently running or has yi - \ No newline at end of file + diff --git a/core/fn.html b/core/fn.html index be73049b..9c047029 100644 --- a/core/fn.html +++ b/core/fn.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -83,9 +84,9 @@ ignored.

    - \ No newline at end of file + diff --git a/core/index.html b/core/index.html index bec6ffbf..0078c671 100644 --- a/core/index.html +++ b/core/index.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -61,15 +62,16 @@ interfaces for this.

  • Range
  • Sequence
  • String
  • +
  • IO
  • - \ No newline at end of file + diff --git a/core/io.html b/core/io.html new file mode 100644 index 00000000..4e21a67c --- /dev/null +++ b/core/io.html @@ -0,0 +1,93 @@ + + + + +IO Class – Wren + + + + + + +
    +
    +
    +

    wren

    +

    a classy little scripting language

    +
    +
    +
    +
    + +
    +

    IO Class

    +

    The IO class can be used to read and write to and from the console.

    +

    Static Methods #

    +

    IO.print(objects...) #

    +

    Prints any number of things to the console and then prints a newline +character. If you don't pass it a string, it will be converted to a string for +you. When passed multiple things, Wren outputs one after another.

    +
    > IO.print("I like bananas")
    +I like bananas
    +> IO.print("Oranges", 10)
    +Oranges10
    +>
    +
    + + +

    IO.write(object) #

    +

    Prints a single thing to the console, but does not print a newline character +afterwards. If you pass it something that isn't a string, it will convert it to +a string.

    +
    > IO.write(4 + 5)
    +9>
    +
    + + +

    In the above example, the result of 4 + 5 is printed, and then the prompt is +printed on the same line because no newline character was printed afterwards.

    +

    IO.read(prompt) #

    +

    Reads in and returns a line of text from the console. Takes a single string to +be used as a prompt. Pass an empty string for no prompt. Note that the returned +line of text includes the newline character at the end.

    +
    > var name = IO.read("Enter your name: ")
    +Enter your name: John
    +> IO.print("Hello " + name + "!")
    +Hello John
    +!
    +>
    +
    +
    +
    + + + diff --git a/core/list.html b/core/list.html index 9095875f..08d2d898 100644 --- a/core/list.html +++ b/core/list.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -95,7 +96,7 @@ are shifted up to fill in where the removed element was.

    Returns the removed item.

    -
    IO.print(["a", "b", "c"].removeAt(1)) // "b".
    +
    IO.print(["a", "b", "c"].removeAt(1)) // "b".
     
    @@ -124,9 +125,9 @@ backwards from the end of the list where -1 is the last element.

    -

    Wren lives on GitHub — Made with ❤ by Bob Nystrom.

    +

    Wren lives on GitHub — Made with ❤ by Bob Nystrom and friends.

    - \ No newline at end of file + diff --git a/core/map.html b/core/map.html index 3d4d8386..a64b576f 100644 --- a/core/map.html +++ b/core/map.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -87,9 +88,9 @@ or String.

    - \ No newline at end of file + diff --git a/core/null.html b/core/null.html index ff67ee6c..c4bb1dba 100644 --- a/core/null.html +++ b/core/null.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -46,17 +47,17 @@

    Methods #

    ! operator #

    Returns true, since null is considered false.

    -
    > !null
    -true
    +
    > !null
    +true
     
    - \ No newline at end of file + diff --git a/core/num.html b/core/num.html index 2763a92d..c1707522 100644 --- a/core/num.html +++ b/core/num.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -146,9 +147,9 @@ from the beginning number to the ending number not including the ending number.< - \ No newline at end of file + diff --git a/core/object.html b/core/object.html index 5423c6ee..0b84df68 100644 --- a/core/object.html +++ b/core/object.html @@ -38,18 +38,29 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • Object Class

    -

    Methods #

    +

    Static Methods #

    +

    same(obj1, obj2) #

    +

    Returns true if obj1 and obj2 are the same. For value +types, this returns true if the objects have equivalent +state. In other words, numbers, strings, booleans, and ranges compare by value.

    +

    For all other objects, this returns true only if obj1 and obj2 refer to +the exact same object in memory.

    +

    This is similar to the built in == operator in Object except that this cannot +be overriden. It allows you to reliably access the built-in equality semantics +even on user-defined classes.

    +

    Methods #

    ! operator #

    Returns false, since most objects are considered true.

    ==(other) and !=(other) operators #

    -

    Compares two objects using built-in equality. This compares numbers by value, -and all other objects are compared by identity—two objects are equal only -if they are the exact same object.

    +

    Compares two objects using built-in equality. This compares value +types by value, and all other objects are compared by +identity—two objects are equal only if they are the exact same object.

    toString #

    A default string representation of the object.

    type #

    @@ -59,9 +70,9 @@ if they are the exact same object.

    - \ No newline at end of file + diff --git a/core/range.html b/core/range.html index d270b8e2..cc9ee4f7 100644 --- a/core/range.html +++ b/core/range.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -63,9 +64,9 @@ - \ No newline at end of file + diff --git a/core/sequence.html b/core/sequence.html index 4b1a7b72..4d40e539 100644 --- a/core/sequence.html +++ b/core/sequence.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -87,6 +88,10 @@ and counting the number of times the returned value evaluates to true
    +

    isEmpty #

    +

    Returns whether the sequence contains any elements.

    +

    This can be more efficient that count == 0 because this does not iterate over +the entire sequence.

    join(sep) #

    Returns a string representation of the sequence. The string representations of the elements in the sequence is concatenated with intervening occurrences of @@ -165,9 +170,9 @@ sequence.

    - \ No newline at end of file + diff --git a/core/string.html b/core/string.html index 86b6d372..fe071968 100644 --- a/core/string.html +++ b/core/string.html @@ -38,6 +38,7 @@
  • Range
  • Sequence
  • String
  • +
  • IO
  • @@ -172,9 +173,9 @@ string.

    - \ No newline at end of file + diff --git a/lists.html b/lists.html index 209975ad..7e39b0f5 100644 --- a/lists.html +++ b/lists.html @@ -151,7 +151,7 @@ gap:

    The removeAt method returns the removed item:

    -
    IO.print(letters.removeAt(1)) // "c"
    +
    IO.print(letters.removeAt(1)) // "c"
     
    diff --git a/maps.html b/maps.html index 05c5220b..9fa6ffda 100644 --- a/maps.html +++ b/maps.html @@ -74,13 +74,22 @@ curly braces. Each entry is a key and a value separated by a colon:

    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.

    +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.

    +

    In addition, even though they aren't strictly immutable, fibers +can be used as map keys. This is handy for storing data that's roughly +"thread-local" by using the current fiber as a map 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 = {}
    @@ -90,14 +99,18 @@ key.

    -

    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.

    +

    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:

    +

    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.

    +

    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}
     
    @@ -114,7 +127,8 @@ key.

    Removing entries #

    -

    To remove an entry from a map, call remove() and pass in the key for the entry you want to delete:

    +

    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".
     
    @@ -134,9 +148,13 @@ can just call clear():

    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:

    +

    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ē",
    @@ -149,7 +167,10 @@ can just call clear():

    -

    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.

    +

    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.