Sleep 2.1 Manual
Total Page:16
File Type:pdf, Size:1020Kb
Sleep 2.1 Manual "If you put a million monkeys at a million keyboards, one of them will eventually write a Java program. The rest of them will write Perl programs." -- Anonymous Raphael Mudge Sleep 2.1 Manual Revision: 06.02.08 Released under a Creative Commons Attribution-ShareAlike 3.0 License (see http://creativecommons.org/licenses/by-sa/3.0/us/) You are free: • to Share -- to copy, distribute, display, and perform the work • to Remix -- to make derivative works Under the following conditions: Attribution. You must attribute this work to Raphael Mudge with a link to http://sleep.dashnine.org/ Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license. • For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to the license. • Any of the above conditions can be waived if you get permission from the copyright holder. • Apart from the remix rights granted under this license, nothing in this license impairs or restricts the author's moral rights. Your fair use and other rights are in no way affected by the above. Table of Contents Introduction................................................................................................. 1 I. What is Sleep?...................................................................................................1 II. Manual Conventions......................................................................................2 III. Acknowledgements ......................................................................................3 1. Getting Started........................................................................................ 5 1.1 Stand-alone Scripts........................................................................................5 1.2 The Sleep Console .........................................................................................7 2. Scalars ..................................................................................................... 10 2.1 Scalar Expressions .......................................................................................10 2.2 Numbers .......................................................................................................16 2.3 Strings ...........................................................................................................20 3. Data Structures...................................................................................... 23 3.1 Arrays............................................................................................................23 3.2 Stacks, Lists, and Sets..................................................................................28 3.2 Hashes...........................................................................................................33 4. Flow Control.......................................................................................... 37 4.1 Comparisons ................................................................................................37 4.2 Loops.............................................................................................................43 4.3 Exceptions.....................................................................................................48 4.4 Assertions .....................................................................................................51 3 5. Functions ................................................................................................ 53 5.1 Subroutines...................................................................................................53 5.2 Scalar Scope..................................................................................................57 5.3 Closures ........................................................................................................61 5.4 Continuations...............................................................................................69 6. Regular Expressions............................................................................. 77 6.1 The Matcher .................................................................................................77 6.2 Pattern Elements..........................................................................................78 6.3 Quantifiers....................................................................................................85 6.4 Special Constructs .......................................................................................86 7. Java Objects ........................................................................................... 89 7.1 Object Expressions ......................................................................................89 7.2 Proxy Instances............................................................................................96 7.3 Exceptions.....................................................................................................97 8. Input / Output ....................................................................................... 99 8.1 I/O Handles .................................................................................................99 8.2 String I/O ...................................................................................................114 8.3 Binary I/O ..................................................................................................116 9. Sleep Integration ................................................................................ 121 9.1 Embed Sleep...............................................................................................121 9.2 Manage Multiple Scripts ..........................................................................126 9.3 Extend Sleep...............................................................................................128 9.4 Scalars..........................................................................................................138 Appendix A: Array Functions .............................................................. 142 =~.......................................................................................................................142 add.....................................................................................................................142 addAll................................................................................................................143 cast .....................................................................................................................143 clear ...................................................................................................................144 concat ................................................................................................................145 copy ...................................................................................................................145 filter ...................................................................................................................146 flatten ................................................................................................................146 in ........................................................................................................................146 map....................................................................................................................147 pop.....................................................................................................................147 push...................................................................................................................147 reduce................................................................................................................148 remove ..............................................................................................................148 4 removeAll .........................................................................................................149 removeAt ..........................................................................................................150 retainAll ............................................................................................................150 reverse...............................................................................................................150 search.................................................................................................................151 shift....................................................................................................................152 size .....................................................................................................................152 sort .....................................................................................................................152 sorta ...................................................................................................................153 sortd...................................................................................................................153 sortn...................................................................................................................153 splice..................................................................................................................154 sublist ................................................................................................................154