mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
Deploy to GitHub Pages:
This commit is contained in:
@ -217,6 +217,22 @@ var error = fiber.try()
|
||||
System.print("Caught error: " + error)
|
||||
</pre>
|
||||
|
||||
<p>If the called fiber raises an error, it can no longer be used.</p>
|
||||
<h3><strong>try</strong>(value) <a href="#try(value)" name="try(value)" class="header-anchor">#</a></h3>
|
||||
<p>Tries to run the fiber. If a runtime error occurs
|
||||
in the called fiber, the error is captured and is returned as a string.
|
||||
If the fiber is being
|
||||
started for the first time, and its function takes a parameter, <code>value</code> is
|
||||
passed to it.</p>
|
||||
<pre class="snippet">
|
||||
var fiber = Fiber.new {|value|
|
||||
value.badMethod
|
||||
}
|
||||
|
||||
var error = fiber.try("just a string")
|
||||
System.print("Caught error: " + error)
|
||||
</pre>
|
||||
|
||||
<p>If the called fiber raises an error, it can no longer be used.</p>
|
||||
<h3><strong>transfer</strong>() <a href="#transfer()" name="transfer()" class="header-anchor">#</a></h3>
|
||||
<p><strong>TODO</strong></p>
|
||||
|
||||
@ -97,6 +97,14 @@
|
||||
<p>Removes all elements from the list.</p>
|
||||
<h3><strong>count</strong> <a href="#count" name="count" class="header-anchor">#</a></h3>
|
||||
<p>The number of elements in the list.</p>
|
||||
<h3><strong>indexOf(value)</strong> <a href="#indexof(value)" name="indexof(value)" class="header-anchor">#</a></h3>
|
||||
<p>Returns the index of <code>value</code> in the list, if found. If not found, returns -1.</p>
|
||||
<pre class="snippet">
|
||||
var list = [0, 1, 2, 3, 4]
|
||||
System.print(list.indexOf(3)) //> 3
|
||||
System.print(list.indexOf(20)) //> -1
|
||||
</pre>
|
||||
|
||||
<h3><strong>insert</strong>(index, item) <a href="#insert(index,-item)" name="insert(index,-item)" class="header-anchor">#</a></h3>
|
||||
<p>Inserts the <code>item</code> at <code>index</code> in the list.</p>
|
||||
<pre class="snippet">
|
||||
@ -145,6 +153,32 @@ System.print(["a", "b", "c"].removeAt(1)) //> b
|
||||
</pre>
|
||||
|
||||
<p>It is a runtime error if the index is not an integer or is out of bounds.</p>
|
||||
<h3><strong>sort</strong>(), <strong>sort</strong>(comparer) <a href="#sort(),-sort(comparer)" name="sort(),-sort(comparer)" class="header-anchor">#</a></h3>
|
||||
<p>Sorts the elements of a list in-place; altering the list. The default sort is implemented using the quicksort algorithm.</p>
|
||||
<pre class="snippet">
|
||||
var list = [4, 1, 3, 2].sort()
|
||||
System.print(list) //> [1, 2, 3, 4]
|
||||
</pre>
|
||||
|
||||
<p>A comparison function <code>comparer</code> can be provided to customise the element sorting. The comparison function must return a boolean value specifying the order in which elements should appear in the list.</p>
|
||||
<p>The comparison function accepts two arguments <code>a</code> and <code>b</code>, two values to compare, and must return a boolean indicating the inequality between the arguments. If the function returns true, the first argument <code>a</code> will appear before the second <code>b</code> in the sorted results.</p>
|
||||
<p>A compare function like <code>{|a, b| true }</code> will always put <code>a</code> before <code>b</code>. The default compare function is <code>{|a, b| a < b }</code>.</p>
|
||||
<pre class="snippet">
|
||||
var list = [9, 6, 8, 7]
|
||||
list.sort {|a, b| a < b}
|
||||
System.print(list) //> [6, 7, 8, 9]
|
||||
</pre>
|
||||
|
||||
<p>It is a runtime error if <code>comparer</code> is not a function.</p>
|
||||
<h3><strong>swap</strong>(index0, index1) <a href="#swap(index0,-index1)" name="swap(index0,-index1)" class="header-anchor">#</a></h3>
|
||||
<p>Swaps values inside the list around. Puts the value from <code>index0</code> in <code>index1</code>,
|
||||
and the value from <code>index1</code> at <code>index0</code> in the list.</p>
|
||||
<pre class="snippet">
|
||||
var list = [0, 1, 2, 3, 4]
|
||||
list.swap(0, 3)
|
||||
System.print(list) //> [3, 1, 2, 0, 4]
|
||||
</pre>
|
||||
|
||||
<h3><strong>[</strong>index<strong>]</strong> operator <a href="#[index]-operator" name="[index]-operator" class="header-anchor">#</a></h3>
|
||||
<p>Gets the element at <code>index</code>. If <code>index</code> is negative, it counts backwards from
|
||||
the end of the list where <code>-1</code> is the last element.</p>
|
||||
|
||||
@ -87,8 +87,15 @@
|
||||
<p>Attempts to parse <code>value</code> as a decimal literal and return it as an instance of
|
||||
<code>Num</code>. If the number cannot be parsed <code>null</code> will be returned.</p>
|
||||
<p>It is a runtime error if <code>value</code> is not a string.</p>
|
||||
<h3>Num.<strong>infinity</strong> <a href="#num.infinity" name="num.infinity" class="header-anchor">#</a></h3>
|
||||
<p>The value of &infinity;.</p>
|
||||
<h3>Num.<strong>nan</strong> <a href="#num.nan" name="num.nan" class="header-anchor">#</a></h3>
|
||||
<p>One value representing a NaN.</p>
|
||||
<p>Provides a default sane NaN number suitable for the vm internal values.</p>
|
||||
<h3>Num.<strong>pi</strong> <a href="#num.pi" name="num.pi" class="header-anchor">#</a></h3>
|
||||
<p>The value of π.</p>
|
||||
<h3>Num.<strong>tau</strong> <a href="#num.tau" name="num.tau" class="header-anchor">#</a></h3>
|
||||
<p>The value of τ.</p>
|
||||
<h3>Num.<strong>largest</strong> <a href="#num.largest" name="num.largest" class="header-anchor">#</a></h3>
|
||||
<p>The largest representable numeric value.</p>
|
||||
<h3>Num.<strong>smallest</strong> <a href="#num.smallest" name="num.smallest" class="header-anchor">#</a></h3>
|
||||
@ -149,6 +156,14 @@ System.print(2.3.isInteger) //> false
|
||||
<p>The binary (base-2) logarithm of the number. Returns <code>nan</code> if the base is negative.</p>
|
||||
<h3><strong>exp</strong> <a href="#exp" name="exp" class="header-anchor">#</a></h3>
|
||||
<p>The exponential <code>e</code> (Euler’s number) raised to the number. This: <code>eⁿ</code>. </p>
|
||||
<h3><strong>min</strong>(other) <a href="#min(other)" name="min(other)" class="header-anchor">#</a></h3>
|
||||
<p>Returns the minimum value when comparing this number and <code>other</code>.</p>
|
||||
<h3><strong>max</strong>(other) <a href="#max(other)" name="max(other)" class="header-anchor">#</a></h3>
|
||||
<p>Returns the maximum value when comparing this number and <code>other</code>.</p>
|
||||
<h3><strong>clamp</strong>(min, max) <a href="#clamp(min,-max)" name="clamp(min,-max)" class="header-anchor">#</a></h3>
|
||||
<p>Clamps a number into the range of <code>min</code> and <code>max</code>. If this number is less than min,
|
||||
<code>min</code> is returned. If bigger than <code>max</code>, <code>max</code> is returned. Otherwise, the number
|
||||
itself is returned.</p>
|
||||
<h3><strong>pow</strong>(power) <a href="#pow(power)" name="pow(power)" class="header-anchor">#</a></h3>
|
||||
<p>Raises this number (the base) to <code>power</code>. Returns <code>nan</code> if the base is negative.</p>
|
||||
<h3><strong>round</strong> <a href="#round" name="round" class="header-anchor">#</a></h3>
|
||||
|
||||
Reference in New Issue
Block a user