Re: wikipedia draft
- Posted by petelomax Jan 08, 2021
- 1863 views
Examples:
Strings are fully mutable, with variable length slice substitution:
string s = "food" ?s -- outputs "food" s[2..3] = "e" ?s -- outputs "fed" s[2..1] = "east" ?s -- outputs "feasted"
the above, wp-ready:
Strings are fully mutable, with variable length slice substitution: <font color="#004080">string</font><font color="#000000"> s</font><font color="#0000FF"> =</font><font color="#008000"> "food" </font><font color="#0000FF"> ?</font><font color="#000000">s </font><font color="#000080"><i> -- outputs "food"</i></font> <font color="#000000">s</font><font color="#0000FF">[</font><font color="#000000">2</font><font color="#0000FF">..</font><font color="#000000">3</font><font color="#0000FF">] =</font><font color="#008000"> "e" </font><font color="#0000FF"> ?</font><font color="#000000">s </font><font color="#000080"><i> -- outputs "fed"</i></font> <font color="#000000">s</font><font color="#0000FF">[</font><font color="#000000">2</font><font color="#0000FF">..</font><font color="#000000">1</font><font color="#0000FF">] =</font><font color="#008000"> "east" </font><font color="#0000FF"> ?</font><font color="#000000">s </font><font color="#000080"><i> -- outputs "feasted"</i></font>
Exception handling:
try integer i = 1/0 -- or, for example, throw("file in use") catch e ?e[E_USER] end try puts(1,"still running...\n")
Output:
"attempt to divide by 0" -- or "file in use" still running...
the above, wp-ready:
Exception handling: <font color="#008080">try</font> <font color="#004080"> integer</font><font color="#000000"> i</font><font color="#0000FF"> =</font><font color="#000000"> 1</font><font color="#0000FF">/</font><font color="#000000">0</font> <font color="#000080"><i> -- or, for example, throw("file in use")</i></font> <font color="#008080">catch</font><font color="#000000"> e</font> <font color="#0000FF"> ?</font><font color="#000000">e</font><font color="#0000FF">[</font><font color="#004600">E_USER</font><font color="#0000FF">]</font> <font color="#008080">end try</font> <font color="#7060A8">puts</font><font color="#0000FF">(</font><font color="#000000">1</font><font color="#0000FF">,</font><font color="#008000">"still running...\n"</font><font color="#0000FF">)</font> Output: "attempt to divide by 0" -- or "file in use" still running...