
2 This page intentionally left blank. 3 Programming with Unicon 2nd edition Clinton Jeffery Shamim Mohamed Jafar Al Gharaibeh Ray Pereda Robert Parlett Copyright c 1999-2018 Clinton Jeffery, Shamim Mohamed, Jafar Al Gharaibeh, Ray Pereda, and Robert Parlett Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”. This is a draft manuscript dated November 24, 2018. Send comments and errata to jeff[email protected]. This document was prepared using LATEX. Contents Preface to the Second Edition vii I Core Unicon5 1 Programs and Expressions7 1.1 Your First Unicon Program..........................7 1.2 Command Line Options............................ 12 1.3 Expressions and Types............................. 13 1.4 Numeric Computation............................. 14 1.5 Strings and Csets................................ 15 1.6 Goal-directed Evaluation............................ 16 1.7 Fallible Expressions............................... 18 1.8 Generators.................................... 18 1.9 Iteration and Control Structures........................ 20 1.10 Procedures.................................... 22 2 Structures 29 2.1 Tables...................................... 30 2.2 Lists....................................... 31 2.3 Records..................................... 33 2.4 Sets....................................... 34 2.5 Using Structures................................ 34 2.6 Summary.................................... 40 3 String Processing 41 3.1 The String and Cset Types........................... 41 3.1.1 String Indexes.............................. 41 3.1.2 Character Sets............................. 43 3.1.3 Character Escapes........................... 43 3.2 String Scanning................................. 44 3.3 Pattern Matching................................ 49 i ii CONTENTS 3.3.1 Regular Expressions.......................... 49 3.3.2 Pattern Composition.......................... 49 3.3.3 Pattern Match Operators........................ 51 3.3.4 Scopes of Unevaluated Variables.................... 51 3.4 String Scanning and Pattern Matching Miscellany.............. 51 3.4.1 Grep................................... 51 3.4.2 Grammars................................ 52 4 Advanced Language Features 57 4.1 Limiting or Negating an Expression...................... 57 4.2 List Structures and Parameter Lists...................... 58 4.3 Co-expressions.................................. 59 4.4 User-Defined Control Structures........................ 60 4.5 Parallel Evaluation............................... 61 4.6 Coroutines.................................... 62 4.7 Permutations.................................. 63 4.8 Simulation.................................... 65 5 The System Interface 69 5.1 The Role of the System Interface....................... 69 5.2 Files and Directories.............................. 70 5.3 Programs and Process Control......................... 73 5.4 Networking................................... 77 5.5 Messaging Facilities............................... 81 5.6 Tasks....................................... 83 5.7 Summary.................................... 90 6 Databases 91 6.1 Language Support for Databases....................... 91 6.2 Memory-based Databases............................ 92 6.3 DBM Databases................................. 92 6.4 SQL Databases................................. 94 6.5 Tips and Tricks for SQL Database Applications............... 100 6.6 Summary.................................... 102 7 Graphics 103 7.1 2D Graphics Basics............................... 103 7.2 Graphics Contexts............................... 106 7.3 Events...................................... 108 7.4 Colors and Fonts................................ 110 7.5 Images, Palettes, and Patterns......................... 111 CONTENTS iii 7.6 3D Graphics................................... 117 7.7 Textures..................................... 122 7.8 Summary.................................... 134 8 Threads 135 8.1 Threads and Co-Expressions.......................... 136 8.2 First Look at Unicon Threads......................... 136 8.3 Thread Safety.................................. 140 8.4 Thread Synchronization............................ 142 8.5 Thread Communication............................ 153 8.6 Practical examples using threads and messages................ 161 8.6.1 Disk space usage............................ 165 8.6.2 More suggestions for parallel processing................ 168 8.7 Summary.................................... 168 9 Execution Monitoring 171 9.1 Monitor Architecture.............................. 171 9.2 Obtaining Events Using evinit ......................... 179 9.3 Instrumentation in the Icon Interpreter.................... 181 9.4 Artificial Events................................. 183 9.5 Monitoring Techniques............................. 184 9.6 Some Useful Library Procedures........................ 186 9.7 Conclusions................................... 186 II Object-oriented Software Development 187 10 Objects and Classes 189 10.1 Objects in Programming Languages...................... 189 10.2 Objects in Program Design........................... 192 10.3 Classes and Class Diagrams.......................... 193 10.4 Declaring Classes................................ 195 10.5 Object Instances and Initially Sections.................... 196 10.6 Object Invocation................................ 198 10.7 Comparing Records and Classes........................ 199 10.8 Summary.................................... 201 11 Inheritance and Associations 203 11.1 Inheritance................................... 203 11.2 Associations................................... 215 11.3 Aggregation................................... 215 iv CONTENTS 11.4 User-defined associations............................ 216 11.5 Summary.................................... 219 12 Writing Large Programs 221 12.1 Abstract Classes................................ 221 12.2 Design Patterns................................. 223 12.3 Packages..................................... 228 12.4 HTML documentation............................. 232 12.5 Summary.................................... 232 13 Use Cases and Supplemental UML Diagrams 235 13.1 Use Cases.................................... 236 13.2 Statechart Diagrams.............................. 239 13.3 Collaboration Diagrams............................ 241 13.4 Summary.................................... 242 III Example Applications 243 14 CGI Scripts 245 14.1 Introduction to CGI.............................. 245 14.2 The CGI Execution Environment....................... 248 14.3 An Example HTML Form........................... 249 14.4 An Example CGI Script: Echoing the User’s Input............. 250 14.5 Debugging CGI Programs........................... 251 14.6 Appform: An Online Scholarship Application................ 252 15 System and Administration Tools 255 15.1 Searching for Files............................... 255 15.2 Finding Duplicate Files............................. 257 15.3 User File Quotas................................ 263 15.4 Capturing a Shell Command Session..................... 268 15.5 Filesystem Backups............................... 270 15.6 Filtering Email................................. 274 15.7 Summary.................................... 279 16 Internet Programs 281 16.1 The Client-Server Model............................ 281 16.2 An Internet Scorecard Server.......................... 282 16.3 A Simple “Talk” Program............................ 285 16.4 Summary.................................... 291 CONTENTS v 17 Genetic Algorithms 293 17.1 What are Genetic Algorithms?......................... 293 17.2 Operations: Fitness, Crossover, and Mutation................ 294 17.3 The GA Process................................. 297 17.4 ga_eng: a Genetic Algorithm Engine..................... 298 17.5 Color Breeder: a GA Application....................... 303 17.6 Picking Colors for Text Displays........................ 305 18 Object-oriented User Interfaces 307 18.1 A Simple Dialog Example........................... 307 18.2 A More Complex Dialog Example....................... 310 18.3 Containers.................................... 317 18.4 Menu Structures................................ 319 18.5 Other Components............................... 322 18.5.1 Trees................................... 323 18.5.2 Borders................................. 327 18.5.3 Images and icons............................ 327 18.5.4 Scroll bars................................ 328 18.5.5 Custom Components.......................... 328 18.5.6 Tickers.................................. 338 18.6 Advanced List Handling............................ 343 18.6.1 Selection................................. 343 18.6.2 Popups.................................. 344 18.6.3 Drag and drop............................. 344 18.7 Programming Techniques............................ 351 18.8 ivib........................................ 353 18.9 Summary.................................... 360 IV Appendices 361 A Language Reference 363 A.1 Immutable Types: Numbers, Strings, Csets, Patterns............ 363 A.2 Mutable Types: Containers and Files..................... 365 A.3 Variables....................................
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages535 Page
-
File Size-