The Zkl Programming Language Reference Manual
Total Page:16
File Type:pdf, Size:1020Kb
The zkl Programming Language Reference Manual Craig Durland Copyright © 2006,2007-13, 2014 Craig Durland All Rights Reserved You can distribute this document and/or modify it under the terms of the Creative Commons Attribution-NonCommercial License, version 3.0 (http://creativecommons.org/licenses/by-nc/3.0/). Feedback Please direct comments and suggestions about this document to: [email protected] See Also For more on zkl, including downloads (and an electronic copy of this book), please visit http://zenkinetic.com/ Publication history ● March 2008 ● July 2008 ● January 2010, updated for zkl version 1.1 ● December 2010, updated for zkl version 1.3 ● June 2011, updated for zkl version 1.5.2 ● December 2011, updated for zkl version 1.6 ● August 2012, updated for zkl version 1.7 ● June 2013, updated for zkl version 1.10 ● September 2013, updated for zkl version 1.12 ● June 2015, updated for zkl version 1.12.21 ● January 2017, updated for zkl version 1.12.38 ● December 2018, updated for zkl version 1.14.1 Contents The Young Person's Guide to zkl...........................1 onExit..............................................................55 Getting Started.............................................2 pimport (packaging)........................................57 Data Things: Numbers, Strings, etc.............3 print, println....................................................60 Branching.....................................................4 [ ] (Range).......................................................61 Loops............................................................4 reg...................................................................63 Functions......................................................4 return...............................................................65 Classes..........................................................5 Multi-valued Return..............................65 Scope............................................................5 returnClass......................................................67 The zkl Shell................................................5 self...................................................................69 Shared Libraries...........................................5 switch..............................................................70 Concept to Topic Mapping...........................6 throw...............................................................72 Keywords...............................................................7 Wishing for Goto...................................73 Names...........................................................7 try/catch..........................................................74 Keywords.................................................7 var...................................................................79 Reserved Words.......................................7 Scope.....................................................81 Syntactic Sugar........................................8 Constant (Write Once) and protected __<name>.........................................................9 Variables................................................81 AKA................................................................10 List assignment......................................82 ask...................................................................11 Proxy Variables......................................83 _assert_...........................................................12 while................................................................84 Attributes........................................................13 Objects.................................................................85 break................................................................14 Environment Variables..........................86 class.................................................................15 Names....................................................86 Special Functions..................................16 What thread-safe and not thread-safe Inheritance.............................................19 mean......................................................87 Anonymous Classes..............................21 Notes on the Pump Method...................87 Supporting Subscripts............................21 Notes on the apply and filter methods...91 Threading...............................................21 Notes on the reduce method..................91 Side Effects............................................23 Atomic............................................................93 comments: #, //, /* */, #define, #if, #ifdef, Simple Waits: Events.............................95 #text, #tokenize...............................................25 Waiting for a Method.............................95 const................................................................30 Waiting for a Function...........................96 continue...........................................................34 Waiting for Multiple Objects.................96 critical.............................................................35 Atomic.Bool....................................................96 Non-Locking Uses.................................35 Events....................................................98 _debug_...........................................................37 Atomic.Int.......................................................98 do....................................................................38 Atomic.Lock.................................................100 fcn...................................................................39 Atomic.WriteLock........................................101 Return Value..........................................40 Bool...............................................................105 Anonymous Functions...........................42 True and False.....................................105 Nested Functions...................................43 Class..............................................................106 Tail Recursion........................................45 Class Attributes....................................116 Tail Calls................................................46 Parent Classes and Top Dogs...............116 Functions are not Closures....................46 Static Classes.......................................118 foreach............................................................48 Late Binding........................................119 if else...............................................................50 Delegation............................................119 include.............................................................52 Dynamic Class Creation......................120 [[ ]] (List Comprehension)..............................53 The Null Class..........................................121 Compiler.......................................................122 Thread.Heartbeat...........................................255 Compiler.Asm...............................................122 Thread.List....................................................256 Loader..................................................123 Thread.Pipe...................................................257 Disassembler Functions.......................123 Thread.Semaphore........................................264 Compiler.Compiler.......................................124 Thread.Straw.................................................265 Compiler.Parser.............................................125 Thread.StrawBoss.........................................265 Compiler.Tokenizer.......................................127 Thread.Timer................................................267 Console.........................................................129 Time..............................................................268 Data...............................................................130 Time.Clock....................................................268 Sequence Example: String Tables.......140 Time.Date......................................................269 Stream Example: Code Containers......141 Utils...............................................................273 Deferred........................................................143 Utils.Argh.....................................................273 Dictionary.....................................................148 Utils.BlackHole.............................................276 Exception......................................................151 Utils.Generator..............................................277 Fcn................................................................156 Coroutines...........................................278 Thread Safety......................................160 Utils.Helpers.................................................278 Function Creation................................160 Utils.MD5.....................................................279 File................................................................163 Utils.range.....................................................280 Utility Methods....................................166 Utils.Wad......................................................281 File.DevNull.................................................171 Utils.wap.......................................................284 Float..............................................................172 Utils.zip.........................................................285 GarbageMan..................................................177