0% found this document useful (0 votes)
8 views86 pages

Mastering Dyalog Apl A Complete Introduction To Dyalog Apl Bernard Legrand Download

The document is a comprehensive guide titled 'Mastering Dyalog APL' by Bernard Legrand, aimed at introducing readers to the Dyalog APL programming language. It covers various topics including installation, data handling, user-defined functions, and error management, providing detailed explanations and examples. The book is structured into chapters that progressively build knowledge, making it suitable for both beginners and experienced programmers looking to enhance their skills in APL.

Uploaded by

pewvtcn2182
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views86 pages

Mastering Dyalog Apl A Complete Introduction To Dyalog Apl Bernard Legrand Download

The document is a comprehensive guide titled 'Mastering Dyalog APL' by Bernard Legrand, aimed at introducing readers to the Dyalog APL programming language. It covers various topics including installation, data handling, user-defined functions, and error management, providing detailed explanations and examples. The book is structured into chapters that progressively build knowledge, making it suitable for both beginners and experienced programmers looking to enhance their skills in APL.

Uploaded by

pewvtcn2182
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

Mastering Dyalog Apl A Complete Introduction To

Dyalog Apl Bernard Legrand download

https://ebookbell.com/product/mastering-dyalog-apl-a-complete-
introduction-to-dyalog-apl-bernard-legrand-4978886

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Mastering Collaboration In A Product Team 70 Techniques To Help Teams


Build Better Products 1st Edition Natasha Hampshire Glaudia Califano
David Spinks

https://ebookbell.com/product/mastering-collaboration-in-a-product-
team-70-techniques-to-help-teams-build-better-products-1st-edition-
natasha-hampshire-glaudia-califano-david-spinks-44875474

Mastering Collaboration In A Product Team 70 Techniques To Help Teams


Build Better Products 1st Edition Natasha Hampshire

https://ebookbell.com/product/mastering-collaboration-in-a-product-
team-70-techniques-to-help-teams-build-better-products-1st-edition-
natasha-hampshire-44915468

Mastering Gnome A Beginners Guide 1st Edition Sufyan Bin Uzayr

https://ebookbell.com/product/mastering-gnome-a-beginners-guide-1st-
edition-sufyan-bin-uzayr-46082774

Mastering Flutter A Beginners Guide 1st Edition Sufyan Bin Uzayr

https://ebookbell.com/product/mastering-flutter-a-beginners-guide-1st-
edition-sufyan-bin-uzayr-46082778
Mastering Rust A Beginners Guide 1st Edition Sufyan Bin Uzayr

https://ebookbell.com/product/mastering-rust-a-beginners-guide-1st-
edition-sufyan-bin-uzayr-46151622

Mastering Rust A Beginners Guide 1st Edition Sufyan Bin Uzayr

https://ebookbell.com/product/mastering-rust-a-beginners-guide-1st-
edition-sufyan-bin-uzayr-46191750

Mastering Primary Science Amanda Mccrory Kenna Worthington

https://ebookbell.com/product/mastering-primary-science-amanda-
mccrory-kenna-worthington-46236134

Mastering Ubuntu Server Explore The Versatile Powerful Linux Server


Distribution Ubuntu 2204 With This Comprehensive Guide 4th Edition 4th
Jay Lacroix

https://ebookbell.com/product/mastering-ubuntu-server-explore-the-
versatile-powerful-linux-server-distribution-ubuntu-2204-with-this-
comprehensive-guide-4th-edition-4th-jay-lacroix-46242660

Mastering Python Scripting For System Administrators Ganesh Sanjiv


Naik

https://ebookbell.com/product/mastering-python-scripting-for-system-
administrators-ganesh-sanjiv-naik-46242670
Mastering Dyalog APL
A Complete Introduction to Dyalog APL

Bernard Legrand

With most grateful acknowledgements to the contributors:


Kim S. Andreasen
Daniel Baronet
Gitte Christensen
Peter Donnelly
Morten Kromberg
John Scholes
Adrian Smith
Tim JA. Smith
Dyalog is a trademark of Dyalog Limited
Copyright  1982-2009 by Dyalog Limited
Published by Dyalog Limited

All rights reserved.

First Edition November 2009


No part of this publication may be reproduced in any form by any means without the prior written permission of Dyalog Limited.

Dyalog Limited makes no representations or warranties with respect to the contents


hereof and specifically disclaims any implied warranties of merchantability or
fitness for any particular purpose. Dyalog Limited reserves the right to revise this
publication without notification.

TRADEMARKS

SQAPL is copyright of Insight Systems ApS.


UNIX is a trademark of X/Open Ltd.
Windows, Windows Vista, Visual Basic and Excel are trademarks of Microsoft Corporation.

All other trademarks and copyrights are acknowledged.

Dyalog Limited
http://www.dyalog.com

ISBN : 978-0-9564638-0-7
iii

Contents

INTRODUCTION - WILL YOU PLAY APL WITH ME? 1

Will You Follow Us? 1

Our First Steps into APL's Magic World 4

Array Processing 5

More Symbols 7

Most Symbols Have a Double Meaning 8

Reduction Unifies Traditional Notations 9

Let's Write Our First Programs 10

Indexing 11

Calculating Without Writing Programs 12

Friendly Binary Data 14

A Touch of Modern Math 16

A Powerful Search Function 17

After Values, Let Us Process Shapes 20

Back to Primary School 22

There Is a Lot to Discover Yet 25

FAQ 28
iv Contents

CHAPTER A: GETTING STARTED 31

1 - Installing the Software 31


1.1 Installation 31
1.2 First Contact 33
1.3 Demonstration Files 36

2 - Working with This Tutorial 40

CHAPTER B: DATA AND VARIABLES 43

1 - Simple Numeric Values 43


1.1 Our First Operations 43
1.2 Variables 44
1.3 Operations on Variables 46

2 - Arrays of Items 47
2.1 Create a List or a Matrix 47
2.2 Special Cases with Reshape 48
2.3 Multi-dimensional Arrays 49

3 - Shape, Rank, and Vocabulary 50


3.1 Shape and Rank 50
3.2 Scaling Down the Ranks 51
3.3 Vocabulary 51
3.4 Beware! 52

4 - Simple Character Values 53


4.1 Character Vectors and Scalars 53
4.2 Character Arrays 55

5 - Indexing 56
5.1 Traditional Vector Indexing 56
5.2 The Shape of the Result 57
5.3 Array Indexing 58
5.4 Convention 60
5.5 Warnings 61
5.6 The Index Function 62
Contents v

6 - Mixed and Nested Arrays 63


6.1 Mixed Arrays 63
6.2 Four Important Remarks 64
6.3 Nested Arrays 64
6.4 DISPLAY 66
6.5 Be Simple! 68
6.6 That's Not All, Folks! 70

7 - Empty Arrays 70

8 - Workspaces and Commands 71


8.1 The Active Workspace 72
8.2 The Libraries 73
8.3 Load a WS 74
8.4 File Extensions 75
8.5 Merge Workspaces 76
8.6 Exiting APL 78
8.7 Contents of a WS 78
8.8 Our First System Commands 79
Exercises 81

The Specialist's Section 83


Spe-1 Variable Names 83
Spe-2 Representation of Numbers 83
Spe-3 The Shape of the Result of Indexing 84
Spe-4 Multiple Usage of an Index 86
Spe-5 A Problem With Using Reshape ( ∰ ) 86
Spe-6 Monadic Index ( ⌷ ) 87

CHAPTER C: SOME PRIMITIVE FUNCTIONS 89

1 - Definitions 89

2 - Some Scalar Dyadic Functions 90


2.1 Definition and Examples 90
2.2 Division By Zero 92
2.3 Power 92
2.4 Maximum & Minimum 92
2.5 Relationship 93
2.6 Residue 94

3 - Order of Evaluation 94
vi Contents

4 - Monadic Scalar Functions 96


4.1 The Four Basic Symbols 96
4.2 Other Scalar Monadic Functions 97

5 - Processing Binary Data 99


5.1 Membership 99
5.2 Binary Algebra 100
5.3 Without 102

6 - Processing Nested Arrays 102


6.1 Scalar vs. Non-scalar Functions 102
6.2 Be Careful With Shape/Type Compatibility 103

7 - Reduction 104
7.1 Presentation 104
7.2 Definition 105
7.3 Reduction of Binary Data 106
7.4 Reduction of Nested Arrays 107
7.5 Application 1 107
7.6 Application 2 108

8 - Axis Specification 109


8.1 Totals in an Array 109
8.2 The Shape of the Result 111
8.3 Special Notations 111

9 - Our First Program 112

10 - Concatenation 113
10.1 Concatenating Vectors 113
10.2 Concatenating Other Arrays 114
10.3 Concatenating Scalars 117
10.4 Special Notations 117

11 - Replication 118
11.1 Basic Approach: Compression 118
11.2 Replication 120
11.3 Scalar Left Argument 120
11.4 Special Notations 121

12 - Position (Index Of) 121


12.1 Discovery 121
12.2 Application 3 123
Contents vii

13 - Index Generator 125


13.1 Basic Usage 125
13.2 Application 4 126
13.3 Comparison of Membership and Index Of 127
13.4 Idioms 130
13.5 Application 5 131
13.6 Application 6 132

14 - Ravel 132

15 - Empty Vectors and Black Holes 134


Exercises 136

The Specialist's Section 140


Spe - 1 Division Control - ⎕DIV 140
Spe - 2 Derived Functions 141
Spe - 3 Nor & Nand 141
Spe - 4 Index Generator of Arrays 142
Spe - 5 Ravel With Axis 143
Spe - 6 Residue 145

CHAPTER D: USER DEFINED FUNCTIONS 147

1 - Landmarks 147
1.1 Some Definitions 147
1.2 Configure Your Environment 148

2 - Single-Line Direct Functions 152


2.1 Definition 152
2.2 Unnamed D-Fns 153
2.3 Modifying The Code 153

3 - Procedural Functions 154


3.1 A First Example 154
3.2 Local Names 156
3.3 Miscellaneous 159
3.4 Second Example 161
Exercises 164
3.5 Calls to Sub-Functions 166
viii Contents

4 - Flow Control 167


4.1 Overview 167
4.2 Conditional Execution 169
4.3 Disparate Conditions 174
4.4 Predefined Loops 176
4.5 Conditional Loops 178
4.6 Exception Control 181
4.7 Endless Loops 182

5 - Traditional Flow Control 186


5.1 Conditional Execution 186
5.2 Multiple Conditions 190
5.3 Modern and Traditional Controls Cooperate 192

6 - Input, Output, and Format 193


6.1 Some Input and Output Methods 193
6.2 Format 194
6.3 Displaying Intermediate Results 196
6.4 Using Global Variables 197
6.5 Exchanging Data With an Excel Worksheet 198
6.6 Reading or Writing a Text File 199
6.7 Printing Results on a Printer 201
6.8 Using a Graphical User Interface 202
6.9 Requesting Values From the Keyboard 203

7 - Syntax Considerations 205


7.1 Comments & Statement Separators 205
7.2 Why Should a Function Return a Result? 206
7.3 Different Types of Functions 207
7.4 Nested Argument and Result 211
7.5 Choice of Names 212

8 - Multi-Line Direct Functions 213


8.1 Characteristics 213
8.2 Guards 215
8.3 Syntax Considerations 215

9 - Recursion 217

10 - Synonyms 218
Contents ix

11 - About the Text Editor 220


11.1 What Can You Edit? 220
11.2 What Can You Do? 221
11.3 Undo, Redo, Replay 222
11.4 Miscellaneous 224

12 - SALT 225
Exercises 227

The Specialist's Section 230


Spe-1 Shadowed Names 230
Spe-2 Loop Control 231
Spe-3 Labels and the Branch Arrow 231
Spe-4 Other Conditional Execution 233
Spe-5 Name Category of Synonyms 234
Spe-6 Bare Output 235
Spe-7 :InEach 236

CHAPTER E: FIRST AID KIT 239

1 - When an Error Occurs 240


1.1 Our First Error 240
1.2 Cascade of Errors 243
1.3 Information and Actions 249
1.4 Why Should You Reset Your State Indicator? 250

2 - Most Frequent Error Messages 252


2.1 Execution Errors 252
2.2 Some Other Errors 257

3 - Trace Tools 258


3.1 Invoke and Use the Tracer 258
3.2 Choose Your Configuration 261
3.3 Break-points and Trace-controls 262
3.4 System Functions 265
Exercises 267

The Specialist's Section 268


Spe-1 Value Errors 268
Spe-2 )SINL 269
Spe-3 Namespaces and Indicators 269
x Contents

CHAPTER F: EXECUTE & FORMAT CONTROL 273

1 - Execute 273
1.1 Definition 273
1.2 Some Typical Uses 274
1.3 Make Things Simple 276

2 - The Format Primitive 276


2.1 Monadic Format 276
2.2 Dyadic Format 277

3 - The ⎕FMT System Function 280


3.1 Monadic Use 280
3.2 Dyadic Use 281
3.3 Qualifiers and Affixtures 288

The Specialist's Section 292


Spe-1 Execute 292
Spe-2 Formatting data 295

CHAPTER G: WORKING ON DATA SHAPE 299

1 - Take and Drop 299


1.1 Take and Drop Applied to Vectors 299
1.2 Three Basic Applications 302
1.3 Take and Drop Applied to Arrays 303

2 - Laminate 305
2.1 Application to Vectors and Scalars 307
2.2 Applications 308

3 - Expand 310
3.1 Basic Use 310
3.2 Extended Definition 310
3.3 Expand Along First Axis 311

4 - Reverse and Transpose 312

5 - Rotate 314
5.1 Rotate Vectors 314
5.2 Rotate Higher-Rank Arrays 315
Contents xi

6 - Dyadic Transpose 316


Exercises 319

The Specialist's Section 322


Spe - 1 More About Laminate 322
Spe - 2 Dyadic Transpose 322

CHAPTER H: SPECIAL SYNTAX 325


1 - Modified Assignment 325

2 - Multiple Assignment 326

3 - Selective Assignment 327


3.1 Quick Overview 327
3.2 Available Primitives 328

CHAPTER I: NESTED ARRAYS (CONTINUED) 331

1 - First Contact 331


1.1 Definitions 331
1.2 Enclose & Disclose 332
1.3 More About DISPLAY 336

2 - Depth & Match 338


2.1 Enclosing Scalars 338
2.2 Depth 339
2.3 Match & Natch 341

3 - Each 342
3.1 Definition and Examples 342
3.2 Three Compressions! 345

4 - Processing Nested Arrays 346


4.1 Scalar Dyadic Functions 346
4.2 Juxtaposition vs. Catenation 346
4.3 Characters and Numbers 348
4.4 Some More Operations 350
Exercises 353
xii Contents

5 - Split and Mix 354


5.1 Basic Use 354
5.2 Axis Specification 355

6 - First & Type 357

7 - Prototype, Fill Item 358

8 - Pick 361
8.1 - Definition 361
8.2 - Beware! 362
8.3 - Important 363
8.4 - Selective Assignment 364
8.5 - An Idiom 365

9 – Partition & Partitioned Enclose 365


9.1 The Dyalog Definition 366
9.2 The IBM Definition 367

10 - Union & Intersection 369

11 - Enlist 369
Exercises 371

The Specialist's Section 372


Spe-1 Compatibility and Migration Level 372
Spe-2 The IBM Partition on Matrices 375
Spe-3 Ambiguous Representation 376
Spe-4 Pick Inside a Scalar 376

CHAPTER J: OPERATORS 377

1 - Definitions 377
1.1 Operators & Derived Functions 377
1.2 Sequences of Operators 378
1.3 List of Built-in Operators 379

2 - More About Some Operators You Already Know 379


2.1 Reduce 379
2.2 n-Wise Reduce 380
2.3 Axis 382
Contents xiii

3 - Scan 383
3.1 Definition 383
3.2 Scan with Binary Values 384
3.3 Applications 385

4 - Outer Product 386


4.1 Definition 386
4.2 Extensions 387
4.3 Applications 389
Exercise 393

5 - Inner Product 394


5.1 A Concrete Situation 394
5.2 Definitions 396
5.3 Typical Uses of Inner Products 396
5.4 Other Uses of Inner Product 405
5.5 Application 406
Exercises 408

6 - Compose 410
6.1 Form 1 411
6.2 Form 2 412
6.3 Form 3 412
6.4 Form 4 413

7 - Commute 414

8 - Power Operator 415


8.1 - Elementary Use (Form 1) 415
8.2 - Conditional Execution (Form 1) 416
8.3 - Left Argument (All Forms) 417
8.4 - Inverse Function 417
8.5 - Fixpoint, and Use with Defined Operators 418

9 - Spawn 418
9.1 Main Features 418
9.2 Special Syntax 420

10 - User-Defined Operators 421


10.1 Definition Modes 421
10.2 Some Basic Examples 422
xiv Contents

The Specialist's Section 424


Spe-1 Reduction Applied to Empty Vectors 424
Spe-2 Index Origin and Axis operator 426
Spe-3 The Power Operator 427
Spe-4 Defined Operators 429
Spe-5 The Result of an Inverse Function 429

CHAPTER K: MATHEMATICAL FUNCTIONS 431

1 - Sorting and Searching Data 431


1.1 Sorting Numeric Data 431
1.2 Sorting Characters 433
1.3 Finding Values 435

2 - Encode and Decode 436


2.1 Some Words of Theory 436
2.2 Using Decode & Encode 438
2.3 Applications 441

3 - Randomised Values 444


3.1 Deal: Dyadic Usage 445
3.2 Roll: Monadic Use 445
3.3 Derived Uses 446

4 - Some More Maths 447


4.1 Logarithms 447
4.2 Factorial & Binomial 448
4.3 Trigonometry 449
4.4 GCD and LCM 450
4.5 Set Union and Intersection 451

5 - Domino 452
5.1 Some Definitions 452
5.2 Matrix Inverse 453
5.3 Matrix Division 455
5.4 Two or Three Steps in Geometry 455
5.5 Least Squares Fitting 457
Exercises 461
Contents xv

The Specialist's Section 463


Spe - 1 Encode and Decode 463
Spe - 2 Random Link 466
Spe - 3 Gamma and Beta Functions 468
Spe - 4 Domino and Rectangular Matrices 468

CHAPTER L: SYSTEM INTERFACES 473

1 - Overview 473
1.1 Commands, System Variables, and System Functions 473
1.2 Common Properties 474
1.3 Organisation 475

2 - Workspace Management 475


2.1 )WSID & ⎕WSID Workspace Identification 476
2.2 ⎕LX Startup Expression 477
2.3 )LOAD, )XLOAD & ⎕LOAD Load a Workspace 478
2.4 )COPY, )PCOPY & ⎕CY Import Objects 479
2.5 )LIB Explore a Workspace Library 480
2.6 )CLEAR & ⎕CLEAR Clear the Active Workspace 480
2.7 )SAVE & ⎕SAVE Save a Workspace 481
2.8 ⎕WA Memory Space Available 482

3 - Object Management 482


3.1 )VARS, )FNS, )OPS, )OBS & ⎕NL Object Lists 482
3.2 ⎕NC Name Category 485
3.3 )ERASE & ⎕EX Delete Objects 486
3.4 ⎕SIZE Object Size 487

4 - Environment Control & Information 488


4.1 ⎕TS Current Date & Time 488
4.2 ⎕PP Print Precision 488
4.3 ⎕IO Index Origin 489
4.4 ⎕AI Account Information 490
4.5 ⎕PFKEY Programmable Function Keys 491
xvi Contents

5 - Function Definition and Processing 493


5.1 )ED & ⎕ED Edit Objects 493
5.2 ⎕CR, ⎕NR, ⎕VR & ⎕OR Function Representations 493
5.3 ⎕FX Function Creation 496
5.4 ⎕SHADOW Name Shadowing 497
5.5 ⎕LOCK Locking a Function 497
5.6 ⎕REFS Internal References 498
5.7 ⎕AT Function Attributes 498

6 - Debugging and Event Trapping 500

7 - Calculation Control 501


7.1 Already Studied 501
7.2 ⎕CT Comparison Tolerance 501
7.3 ⎕DL Delay 503

8 - Character Processing, Input/Output 503


8.1 ⎕AV & ⎕AVU Atomic Vectors 503
8.2 ⎕UCS Unicode Conversions 504
8.3 ⎕TC Terminal Control 504
8.4 ⎕A & ⎕D Alphabet & Digits 505
8.5 ⎕NULL Null Item 505

9 - Miscellaneous 507
9.1 ⎕OFF & )OFF Quit APL 507
9.2 ⎕SH, ⎕CMD, )SH & )CMD Host System Commands 507
9.3 ⎕PW Page Width 508

The Specialist's Section 509


Spe-1 Commands vs. System Functions 509
Spe-2 ⎕SAVE 510
Spe-3 )CONTINUE Save & Continue 511
Spe-4 ⎕OR 511
Spe-5 ⎕VFI Verify and Fix Input 512
Spe-6 ⎕RTL Response Time Limit 513
Spe-7 ⎕MONITOR Execution Monitoring 514
Spe-8 System Variables vs. System Functions 516
Contents xvii

CHAPTER M: EVENT HANDLING 517

1 - Diagnostic Tools 518

2 - Event Trapping 518


2.1 Event Numbers / Event Messages 519
2.2 :Trap / :Else / :EndTrap 520
2.3 ⎕TRAP 522
2.4 Beware of These Errors 527
2.5 Neutralise the Traps 530

3 - Event Simulation 530


3.1 ⎕SIGNAL Example 532

CHAPTER N: FILE PROCESSING 535

1 - Component Files 536


1.1 First Steps 536
1.2 Utility Functions 540
1.3 Shared Files 544
1.4 How to Queue File Operations 551

2 - Data Representation 554


2.1 Representation of Values 554
2.2 Representation of Variables 557

3 - Native Files 559


3.1 Similarities and Differences 559
3.2 Basic Operations 561

4 - External Variables 566

The Specialist's Section 569


Spe-1 Component Files 569
Spe-2 Native Files 572

CHAPTER O: NAMESPACES 577

1 - Simple Namespaces 577


1.1 Introduction 577
1.2 Use the Contents of a Namespace 583
xviii Contents

2 - More about References 588


2.1 Namespace References 588
2.2 Display Form 591

3 - Arrays of Refs 592


3.1 Create an Array 592
3.2 Indexing Arrays of Refs 594

4 - The Session Namespace 594

The Specialist's Section 597


Spe - 1 The Dot as a Syntactic Element 597
Spe - 2 State Indicators 598
Spe - 3 Evaluation of Statements 598
Spe - 4 The Dyalog Workspace Explorer 600
Spe - 5 Control of Exported Functions 601
Spe - 6 Retrieving a Namespace Source 602

CHAPTER P: GRAPHICAL USER INTERFACE 603

1 - Guidelines 603
1.1 Terminology and Options 603
1.2 Create a Simple Dialog Box 607
1.3 Get Information 610
1.4 Changing Properties 611
1.5 Make It Work 612

2 - Call-Back Functions 613


2.1 Discovery 613
2.2 The Arguments of a Call-Back Function 618
2.3 The Result of a Call-Back Function 622
2.4 Improve It 625
2.5 Tracing Call-Back Functions 628

3 - Selection Tools 628


3.1 List 628
3.2 Combo 631

4 - Colours, Fonts, and Root 633


4.1 Colours 633
4.2 Fonts 633
4.3 Properties of the Root Object 636
Contents xix

5 - Improve Your User Interface 639


5.1 Default Keys 639
5.2 Enqueuing Events and Using Methods 640
5.3 Activating Objects 641
5.4 Form Appearance 642

6 - Menus 644

7 - The Grid Object 646


7.1 Geometry & Titles 647
7.2 Cell Types 648
7.3 Interaction with a Grid 653
7.4 Example 654
7.5 Multi-Level Titles 658
7.6 Some Additional Properties 660

8 - Using Printers 661


8.1 The Printer Object 661
8.2 Printer Management 664

9 - And Also … 667

The Specialist's Section 669


Spe-1 Lists of Properties, Methods, Events 669
Spe-2 Different Syntaxes 671
Spe-3 Using Classes 672

CHAPTER Q: INTERFACES 675

1 - Introduction 675

2 - OLE Interface with Excel 676


2.1 Introduction 676
2.2 Create, Fill, and Save a Workbook 677
2.3 Open and Process a Workbook 680
2.4 A Simple Example 683

3 - Name Association 686


3.1 Introduction 686
3.2 Detailed Syntax 688
3.3 See How It Works 690
xx Contents

CHAPTER R: SALT 693

1 - Introduction 693
1.1 Why a Source Code Management System? 693
1.2 Using Script Files 697
1.3 Updating a Script From the APL Session 700

2 - Version Management 702


2.1 Creating and Using Versions 702
2.2 File Management 705
2.3 Comparing Scripts 707

3 - Settings 709

The Specialist's Section 711

CHAPTER S: PUBLISHING TOOLS 713

1 - NewLeaf 714
1.1 Getting Started 714
1.2 Frames and Text 715
1.3 Fonts 720
1.4 Tables 722
1.5 The Page Designer 726
1.6 More Tools, Better Quality 735

2 - RainPro 738
2.1 Getting started 738
2.2 Multiple Bar Chart 740
2.3 Scattered Points 744
2.4 Min-Max Vertical Lines 750
2.5 Polar Representations 753
2.6 Multiple Charts 754
2.7 There is Much More To Explore! 756
Contents xxi

CHAPTER X: SOLUTIONS 757


Chapter B 757
Chapter C 758
Chapter D 761
Chapter G 765
Chapter I 767
Chapter J 768
Chapter K 771

APPENDICES 773

Appendix 1 : Scalar Functions 773

Appendix 2 : Invoking the Editor 774

Appendix 3 : Selective Assignment 775

Appendix 4 : Dyalog APL Operators 776

Appendix 5 : Identity Items 777

Appendix 6 : Event Numbers 778

Appendix 7 : System Variables and Functions 780

Appendix 8 : System Commands 783

Appendix 9 : Symbolic Index 784

INDEX M-789
xxii Contents
1

Introduction - Will You Play APL With Me?

Will You Follow Us?


We would like to have you discover a new land, a land where people who may or may not be
specialists in programming can process their data, build computerised applications, and take
pleasure in using a programming language which is an extremely elegant and powerful tool of
thought.

Beware: Dyalog APL is Addictive!


Among the hundreds of programming languages which have been created, most of them share
the same fundamentals, the same basic instruction set, approximately the same functions, and
by and large the same methods to control the logic of a program. This greatly influences the
way people imagine and build solutions to computing problems. Because the languages are so
similar, the solutions are similar. Does it mean that these are the only ways of solving
problems? Of course not!
Dyalog APL is there to open doors, windows, and minds, prove that original new methods do
exist, and that mathematics is not limited to four basic operations. Using APL will expand and
extend the range of mental models that you use to solve problems, but beware:
Once you are hooked on APL, there is a real risk that you will no longer accept the limitations
of "traditional" programming languages.

Installation and Keyboard


If you do not have access to a computer with Dyalog APL installed, you should still be able to
gain an appreciation of the language from these pages and, we hope, enjoy the experience.
If you have installed Dyalog, not only can you read this book, but you can also experiment on
your own computer using the examples below, and invent your own data and calculations.
If you have a copy of Dyalog APL, install it as explained in the User Guide. Just run the
installation program and accept all the defaults; there is no need to change anything.
2 Dyalog APL - Tutorial

You might like to refer to section A-1 for additional installation hints.
As you will see in the following pages, APL uses special symbols, like ⍉, ∰, and ∸, which
you enter using a special keyboard layout.
You will not need all of the special symbols to read the following pages. The picture below
illustrates a cut-down version of the UK keyboard layout, with only the APL symbols that are
referred to in this introduction. They are shown on a grey background. The US keyboard is
slightly different, but the symbols we need are positioned identically. The full keyboard layout
is shown in the User Guide.

Here is how the keyboard is to be used:


 All the standard English letters, numerals and symbols are typed as usual.
 The majority of the APL symbols are obtained by pressing the "Ctrl" key, in conjunction
with another key. For example, to obtain ∰, you must press Ctrl and R. From now on, this
keystroke will be identified as "Ctrl+R". On the keyboard layout illustrated above, the
symbols that you enter this way are printed at the bottom-right corner of each key.
 Most other APL symbols are obtained by simultaneously pressing "Ctrl" and "Shift" and
then the appropriate key. For example, to obtain ⍉, you must press Ctrl and Shift and 6.
From now on, this keystroke will be identified as "Ctrl+Shift+6". On the keyboard layout
illustrated above, the symbols that you enter this way are printed at the top-right corner of
each key.
 A few APL symbols are obtained by pressing the "Alt Gr" key (or Ctrl+Alt if your
keyboard does not have an "Alt Gr" key), simultaneously with another key, but you don't
have to bother about them here: We won't be using them in the examples in this
introduction.
Introduction - Will you play APL with me ? 3
 In case you initially have any difficulty with the keyboard, there is a "language bar" on top
of the session screen, with all the APL symbols on it. When you need a symbol, you just
have to click on it and the symbol will appear wherever your cursor is positioned.
You may notice that some symbols appear twice on the keyboard. This is the case for example
for the symbols < = >. These symbols are all part of a normal keyboard (the black ones), but
they have been repeated on the APL keyboard, mostly in order to group the symbols used for
comparison functions together (the red ones). Do not worry: No matter which key you use to
produce one of the duplicated symbols, you'll obtain the same result.

Utilities and Data


For most of the examples, you can just type what you read in the following pages, but
sometimes you will need some data which we have prepared for you.
This data is contained in a special file (called a WorkSpace) named DyalogTutor_EN.dws
which accompanies this book.
If you don’t have the file, please refer to section A-1 for instructions on how to download it.
The file can only be opened by Dyalog APL. You can open it as follows:
 In Windows Explorer, double-click on the file's name. APL will be started, and it will then
open the file.
 Or, start APL by double clicking on the Dyalog APL icon. Then, using the " File/Open"
menu, search for the file and open it.

Once the workspace has been loaded, a welcome message is displayed, and you can check that
the workspace contains the variables we shall be using in the following pages:
)vars
Actual Ages AlphLower AlphUpper Area Big Category etc…
You can display the contents of any variable by hovering over its name with the mouse-
pointer, by double-clicking on its name, or just by typing its name and pressing the Enter key,
like this:
Forecast
150 200 100 80 80 80
300 330 360 400 500 520
100 250 350 380 400 450
50 120 220 300 320 350

Now, you are ready, fasten your seatbelts, we're off!


4 Dyalog APL - Tutorial

Our First Steps into APL's Magic World


Simple Operations
In APL, what you type starts 6 characters right from the left margin (we say it is "indented"),
whereas the computer's response begins at the left margin. For additional clarity, in the
following pages the characters typed by the user are printed in red, the response given by the
computer being in black.
You will notice that in the examples given in the book we very often put a blank space
between a symbol and the surrounding names or values. This is in most cases unnecessary; we
only do so in order to improve readability. Later on, we will gradually cease to insert the
blank spaces in expressions that you should become familiar with along the way.
An expression gets evaluated and the result shown in the session when you press the Enter
key. Let's try some simple expressions:
27 + 53
80
1271 - 708
563
86 ÷ 4 The Divide sign is obtained using Ctrl+ =
21.5
59 × 8 The Multiply sign is obtained using Ctrl+ -
472
You can see that APL behaves like any hand-held calculator with, however, a small
difference; multiplication is represented by the multiplication symbol ( × ) which is used in
schools in many countries; likewise for division ( ÷ ).
In most other computer languages, a star * is used for Multiply and / for Divide. This is a
legacy of the early days of computers, when the character set was limited to the one available
on a typewriter. At the time it was decided to use * and / in place of × and ÷. But it is now
possible to display any type of symbol on a screen and on a printer, and this transposition is
no longer justifyable. The use of common symbols, which are taught all over the world, aids
the understanding of APL by non programmers.
If you are familiar with other programming languages, you may occasionally and erroneously
use * instead of ×. Let's see what might happen then:
7 * 3  In APL the star means "Power"
343 so that 7*3 is equivalent to 7×7×7
Introduction - Will you play APL with me ? 5

Variables
As in any programming language, it is possible to create variables. Just choose a name and use
the left arrow to assign it a value. In APL a numeric value can consist of a single number, or
several numbers separated by at least one blank space. The arrow can be obtained using Ctrl+ [
VAT ← 19.6  Read it as: VAT gets 19.6
Years ← 1952 1943 1986 2007
The names are "case sensitive". It means that three variables named respectively VAT, Vat,
and vat, would be distinct, and may contain different values.
To ask for the contents of a variable, just type its name and press Enter, like this:
VAT
19.6
Years
1952 1943 1986 2007

Array Processing
APL is able to operate on two sets of numbers, provided those two sets have the same "shape".
For the moment, understand this as "the same number of items". For example, suppose that
you have a list of prices of 5 products, and the quantity bought of each:
Prices 5.20 11.50 3.60 4.00 8.45
Quantities 2 1 3 6 2
You can create two variables like this:
Price ← 5.2 11.5 3.6 4 8.45
Qty ← 2 1 3 6 2
When multiplied together, the variables are multiplied item by item, and produce a result of
the same length. That result can be assigned to a new variable.
Costs ← Price ∲ Qty
Costs
10.4 11.5 10.8 24 16.9
This array processing capability eliminates most of the "loops" which are common to other
programming languages. This remains true even if the data is not a simple list but a multi-
dimensional array, of almost any size and number of dimensions.
6 Dyalog APL - Tutorial

To make it clear, imagine that a Sales Director makes forecasts for sales of 4 products over the
coming 6 months, and assigns them to the variable Forecast. At the end of the 6 months, he
assigns the real values to the variable Actual. Here they are:
Forecast Actual
150 200 100 80 80 80 141 188 111 87 82 74
300 330 360 400 500 520 321 306 352 403 497 507
100 250 350 380 400 450 118 283 397 424 411 409
50 120 220 300 320 350 43 91 187 306 318 363
We have not yet explained how you can build such arrays of data, but if you have APL
installed, these variables are provided in the Workspace file named "DyalogTutor_EN.dws".
Refer to the "Utilities and Data" section above to see how you can load the workspace and
access the data.
It is clear that the first idea of any Sales Director will be to ask for the differences between
what he expected and what he has really got. This can be done easily by typing:
Actual - Forecast
¯9 ¯12 11 7 2 ¯6  Note that to distinguish the sign attached to
21 ¯24 ¯8 3 ¯3 ¯13 negative values from subtraction, negative
18 33 47 44 11 ¯41 values are shown with a high minus sign.
¯7 ¯29 ¯33 6 ¯2 13
To enter negative values, this high minus sign can be obtained by pressing Ctrl+2.
In most traditional programming languages an operation like the one above requires two
embedded loops. See what is needed in PASCAL:

DO UNTIL I=4
DO UNTIL J=6
DIFF(I,J):=ACTUAL(I,J)-FORECAST(I,J)
END
END.
Even if this may seem obvious to a programmer, it is worth noting that most of the code has
nothing to do with the user requirement. The only important thing (subtract forecasts from
actual values) is hidden behind the detailed workings of the computer program.
To have a calculation done by a machine, one must translate our human wording into
something that the computer can understand. With traditional languages, most of that effort is
made by the man, to produce a program like the PASCAL example above. The great
advantage of APL is that the man has generally much less effort to make, and the machine
does the rest.
We have seen that APL will work on two variables of the same shape; it also works if one of
the variables is a single item, which is called a scalar. If so, the other variable may be of any
shape.
Introduction - Will you play APL with me ? 7
For example, if we want to calculate the amount of 19.6% VAT applied to the variable Price
above, we can type Price × VAT ÷ 100 (or VAT × Price ÷ 100 as well), as shown here:
Price × VAT ÷ 100
1.0192 2.254 0.7056 0.784 1.6562  This result would require some rounding
but this is not important for now

More Symbols
Most programming languages represent only a very small subset of the mathematical
functions using symbols (typically +, -, * and /). The creator of APL, Kenneth E. Iverson,
chose to include many traditional mathematical symbols in his language, and also added some
new symbols to the set that we already know so well.
E.g.: Many functions which in other programming languages are library routines with names
like "Maximum" have their own symbols in APL.
The function "Maximum" (⌈) returns the greater of two numbers, or of two arrays of numbers
compared item by item.
There is also, as one might expect, a symbol for "Minimum" (⌊).
75.6 ⌈ 87.3  Maximum (Ctrl+S)
87.3
11 28 52 14 ⌈ 30 10 50 20  Comparison item by item
30 28 52 20
11 28 52 14 ⌊ 20  Minimum (Ctrl+D)
11 20 20 14
APL supports about 70 symbols. Since some symbols have more than one meaning one could
argue at length about the exact number.
This is nothing to worry about: Some of the symbols are familiar; such as × or > or again ÷
and -, but also ! and a good many others.
8 Dyalog APL - Tutorial

Most Symbols Have a Double Meaning


This is not a peculiarity of APL; in algebra we are familiar with the use of symbols as
common as the minus sign being used in two different ways.
In the expression a=x-y the minus sign means subtract
Whereas in a = -y the minus sign indicates the negation of y, that's different
The first form is called the "dyadic" use of the symbol.
The second form is called the "monadic" use of the symbol.
It is the same in APL, where most of the symbols can have two meanings.
For example, to find the shape (the dimensions) of an array, one uses the Greek letter Rho (∰),
which can be read "shape of …", in its monadic use. It is produced using Ctrl+R.
∰ Price  Monadic use
5 Price has 5 items
∰ Forecast
4 6 Forecast has 4 rows of 6 items

Used dyadically, the same symbol will organise items into a specified shape. For example,
suppose that we want to create the matrix below:
25 60
33 47
11 44
53 28
We must give the computer two pieces of information:
 First the shape to give to the matrix: 4 2 (4 rows of 2 columns)
 Next the contents of the matrix: 25 60 33 47 11 44 53 28
It is the symbol ∰ (Rho) which makes the connection between the shape and the contents:
Tab ← 4 2 ∰ 25 60 33 47 11 44 53 28
Tab
25 60
33 47
11 44
53 28
A new variable Tab is thereby created, and this is also how the variables Forecast and
Actual above were made.
Introduction - Will you play APL with me ? 9

Conventions
In APL, we give special names to certain shapes of data:

 Scalar is used for a single value, a number like 456.18 or a single letter like 'Q'.
 Vector is a plain list of values
It may be composed of numbers like Price and Qty,
or of letters like 'Once upon a time' within single quotes
 Matrix is an array with two dimensions, like Forecast or Tab
 Array is a generic word for any set of values, whatever the number of its dimensions
 Table is a common word used for arrays with 2 dimensions (matrices)
 Cube is a common word used for arrays with 3 dimensions

Reduction Unifies Traditional Notations


Perhaps you remember the variable Costs: 10.4 11.5 10.8 24 16.9
So what must we do to work out the total? Mathematicians are creative people who long ago
devised the symbol ∑, always with a pretty collection of indices above and below, which
make it complex to understand and to type on a typewriter.
In APL, the operation is written like this:
+/ Costs
73.6
Simple isn’t it? This gives the total of all the items of the array.
You can read this as "Plus Reduction" of the variable Costs.
To gain a better understanding of the process:
When we write an instruction such as +/ 21 45 18 27 11
- it works as if we had written 21 + 45 + 18 + 27 + 11
- and we obtain the sum 122
In fact, it works as if we had "inserted" the symbol + between the values.
But then, if we write ×/ 21 45 18 27 11
- it is as if we had written 21 × 45 × 18 × 27 × 11
- so, we get the product 5051970
10 Dyalog APL - Tutorial

Similarly, if we write ⌈/ 21 45 18 27 11
- it is as if we had written 21 ⌈ 45 ⌈ 18 ⌈ 27 ⌈ 11
- so, we obtain the largest term 45

Reduction, represented by the symbol /, belongs to a special category of symbols called


Operators. All the other symbols (+ - ∲ ⌈ ∰ ⍉ ...) are called Functions (addition,
subtraction, multiplication, maximum, shape, etc.).
The arguments of a function are data (arrays): Price × Qty
Whereas at least one of the arguments of an operator is a function: +/ Qty
The left argument of Reduction can be one of many of the APL symbols, and it can also be the
name of a user-defined program. This may give you an idea of the generality and power of the
concept.
Dyalog APL contains 10 such powerful operators. If that is not enough, you can even write
your own operators, just like you can write your own functions!

Let's Write Our First Programs


Imagine that we want to calculate the average of the following numbers:
Val ← 22 37 41 19 54 11 34
We must:
 first calculate the sum of the values: +/ Val giving 218
 next calculate the number of values: ∰ Val giving 7
 and finally divide one result by the other

The calculation can be written as the single formula: (+/Val) ÷ (∰Val)


As it is quite likely that we shall often want to make this sort of calculation, it is preferable to
store this expression in the form of a program.
In APL we prefer the name defined function to the name "program".
Defined functions may be used in the same way as the built-in functions represented by
special symbols like + - × — > ∰..., which are called primitive functions.
To define a simple function like this one, here is the easiest way:
Average ← {(+/∱)÷(∰∱)}
Introduction - Will you play APL with me ? 11

Average is the program name


∱ is a generic symbol which represents the array passed on the right.
∭ would be the generic symbol for the array passed on the left, if any
The definition of the function is delimited by a set of curly braces { and }. For more complex
functions it is also possible to use a text editor, but this is beyond the scope of this short
introduction.
Once defined, this function may be invoked in a very simple way:
Average Val  For execution, ∱ will get the values
31.1428571428 contained in Val
Average 12 74 56 23
41.25

Let us also write two little dyadic functions, the left argument of which is ∭, and the right is ∱:
Plus ← {∭+∱}
Times ← {∭∲∱}
(3 Plus 6) Times (5 Plus 2)
63
As you can see, these functions behave exactly as if we had written (3+6) × (5+2)
We said in the preceding section that a user-defined program could be used by the Reduce
operator; let us try:
Plus/ Val
218  It works!

Indexing
Returning to our vector of numbers Val: 22 37 41 19 54 11 34
In order to extract the 4th item, we just write: Val[4]
In many other programming languages one uses parentheses instead of brackets; this is not
very different.
What is new is that one can extract several items in one instruction.
Val
22 37 41 19 54 11 34
Val[2 4 7 1 4]  One may extract the same item twice or more
37 19 34 22 19
12 Dyalog APL - Tutorial

And of course, in the same way, one may modify one or more items of Val using their
indexes. Naturally, one must provide as many values as there are items to modify, or a single
value for all:
Val[3 5 1] ← 0
Val
0 37 0 19 0 11 34
Val[3 5 1] ← 300 77 111
Val
111 37 300 19 77 11 34  You can check that the 3rd item is now 300, the 5th is 77, etc.
It is often necessary to extract the first few items from a list of values, for example the first 5.
Nothing could be easier:
Val[1 2 3 4 5]
111 37 300 19 77

But if one needs to extract the first 500 items from a long list, typing the integers from 1 to
500 would of course be very inconvenient.
This is why APL has been given the symbol ∯ (Iota), which produces the set of the first n
integers (∯ can be obtained using Ctrl+I)
Thus, instead of writing 1 2 3 4 5 6 7 8, it is sufficient to write ∯8.
And to extract the first 500 terms of a large vector, one may write: Big[∯500]
We shall discover later an even simpler method.

Calculating Without Writing Programs


The employees of a company are divided into three hierarchical categories, denoted simply 1,
2, and 3. One assigns to two variables the salaries and the categories of these employees; as
partly shown here:
Salaries ← 4225 1619 3706 2240 2076 1389 3916 3918 4939 2735 ...
Categories ← 3 1 3 2 2 1 3 3 3 2 ...
Do they never want to increase these salaries? (what has our poor world come to!).
Introduction - Will you play APL with me ? 13
A rumour reaches us about their plans: They want a different percentage increase for each
category, according to the following scale:

Suggested
Category increase
1 8%
2 5%
3 2%

How much is this going to cost the company?


We create a variable containing the above three rates:
Rates ← 8 5 2 ÷ 100  APL allows us to divide three numbers by a single one
Rates
0.08 0.05 0.02
The first employee is in category 3, so the rate that applies to him is:
Rates[3]
0.02
It follows that the first 5 employees, being in categories 3 1 3 2 2 respectively, are entitled to
the following increases:
Rates[3 1 3 2 2]
0.02 0.08 0.02 0.05 0.05
More generally, the rates applied to all of our employees could be obtained like this:
Rates[Categories]
0.02 0.08 0.02 0.05 0.05 0.08 0.02 0.02 0.02 0.05 0.05 0.02 etc.
Having the rates, one has just to multiply by the salaries to obtain the individual increases:
Salaries × Rates[Categories]
84.5 129.52 74.12 112 103.8 111.12 78.32 78.36 98.78 136.75 etc.
Finally, by adding them all, one will know how much it will cost the company:
+/ Salaries × Rates[Categories]
2177.41
You may note that:
 The expression remains valid whatever the number of employees or categories,
 the result has been obtained without writing any program,
 and this expression can be read as the simplest possible English, like this:
Sum the Salaries multiplied by Rates according to Categories
Clever, no?
This illustrates how the expression of a solution in APL can be very close to the way that the
solution could be phrased in everyday language. This also shows clearly that the ways of
reasoning induced by traditional programming languages are not the only possible ones. This
difference and originality, introduced by APL, are among the major features of the language.
14 Dyalog APL - Tutorial

Friendly Binary Data


APL makes much use of binary data. It is most often created by means of relational functions
like = or >, which give the answer 1 or 0, depending whether the relation is true or not:
Salaries > 3000
1 0 1 0 0 0 1 1 1 0 1 1 0 0 1 1 0 0 0 0
Actual > Forecast
0 0 1 1 1 0
1 0 0 1 0 0  One can see the favourable results instantly
1 1 1 1 1 0
0 0 0 1 0 1
APL offers the conventional mathematical form of the 6 relational functions:
< ≤ = ≥ > ≠

Naturally one can operate on this binary data using all the functions of Boolean algebra, and
moreover, the symbols used are those familiar to mathematicians of all nationalities around
the world:
Function AND is represented by the symbol ∧ (represented by the word AND in
many programming languages)
Function OR is represented by the symbol ∨ (represented by the word OR in
these languages)
Thus, if I am looking for people in category 3 whose salary is less than 4000 euros, I can
write:
(Categories = 3) ^ (Salaries < 4000)
0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 1
In fact APL offers all the functions of Boolean algebra, including some perhaps less familiar
functions like NOR and NAND (Not-OR and Not-AND), but they are very useful in finance
and electronic automation.
There is, however, no special symbol for the function Exclusive OR (often called XOR). This
is because it is not needed: The function Not Equal ≠ gives the same result as Exclusive OR
when it is used with Boolean values, as you can see below:
0 0 1 1 ≠ 0 1 0 1
0 1 1 0
Finally, not only can these binary vectors be used as we have described but also for novel
purposes, such as counting and selecting.
Introduction - Will you play APL with me ? 15

Counting
Having found which salaries are less than 2500 euros by means of the following expression:
Salaries < 2500
0 1 0 1 1 1 0 0 0 0 0 0 1 1 0 0 1 0 1 0
It is easy to add all the 1s and 0s to calculate how many people earn less than 2500 euros:
+/ Salaries < 2500
8

Selection
One can also use the binary vector as a "mask" to select the items corresponding to the binary
"1"s from another array:
1 1 0 1 0 0 1 / 23 55 17 46 81 82 83
23 55 46 83
The procedure is identical for character data:
1 0 1 0 0 0 0 1 1 / 'Drumstick'
Duck
This function, called Compress, is particularly useful for extracting the items conforming to a
given criterion from a variable. For example, to display the salaries of people in Category 2,
one writes:
(Categories = 2) / Salaries
2240 2076 2735 3278 1339 3319  Powerful, isn’t it?

Discovery
To practise our skills some more, let us find in our variable Val the positions of numbers
greater than 35. Here are the necessary steps:
Val ← 22 37 41 19 54 11 34
Val>35 is 0 1 1 0 1 0 0
∰Val is 7
∯∰Val is 1 2 3 4 5 6 7  All possible positions
Let us compare two of these results
Val>35  0 1 1 0 1 0 0
∯∰Val  1 2 3 4 5 6 7
16 Dyalog APL - Tutorial

You can see that that if you eliminate (using Compress) the items which correspond to zeros
in order to retain only those corresponding to 1, you easily get the positions required: 2 3 5
Thus the job may be done as follows:
(Val>35) / ∯∰Val
2 3 5
This expression is applicable in many different situations.
Here is a similar use, but applied to character data: To find the positions of "a" within a
phrase; the method is the same.
Phrase ← 'Panama is a canal between Atlantic and Pacific'
(Phrase = 'a') / ∯∰Phrase
2 4 6 11 14 16 30 36 41  You can check it!

A Touch of Modern Math


Proudly having found all the "a"s, we may wish to find all the vowels.
Alas, although we can write Phrase = 'a', because a vector can be compared with a single
value, one cannot write Phrase = 'aeiouy'(1), because that would require the item by item
comparison of a phrase of 46 letters and "aeiouy" which has only 6.
In other words: You may compare 46 letters with 46 other letters, or compare them with one
letter, but not with 6.

So we shall use a new function: Membership which is represented by the symbol ∮, also used
in mathematics.(∮ can be obtained by pressing Ctrl+E)
The expression A ∮ B returns a Boolean result which indicates which items of the variable A
appear in the variable B, wherever they may be. And it works no matter what are the shapes,
the dimensions or the type (numeric or character) of A and B, a pure marvel!
For example:
5 7 2 8 4 9 ∮ 3 4 5 6
1 0 0 0 1 0  Only 5 and 4 are found in 3 4 5 6
'dandelion' ∮ 'garden'
1 1 1 1 1 0 0 0 1  The letters "lio" do not appear in "garden"

1
"Y" is considered to be a vowel in many European languages.
Introduction - Will you play APL with me ? 17
So in pursuit of our enquiry we shall write:
(Phrase ∮ 'aeiouy') / ∯∰Phrase
2 4 6 8 11 14 16 20 23 24 30 33 36 41 43 45
One can also use membership between a vector and a matrix, as shown below, assuming that
the list of towns is a variable created earlier.
We have represented side by side the variable itself and the result of using Membership:
Towns Towns ∮ 'aeiouy'
Canberra 0 1 0 0 1 0 0 1 0 0
Paris 0 1 0 1 0 0 0 0 0 0
Washington 0 1 0 0 1 0 0 0 1 0
Moscow 0 1 0 0 1 0 0 0 0 0
Martigues 0 1 0 0 1 0 1 1 0 0
Mexico 0 1 0 1 0 1 0 0 0 0

We can reverse the expression, but the result has always the same shape as the left argument:
'aeiouy' ∮ Towns
1 1 1 1 1 0  None of the town names contains a "y"

A Powerful Search Function


We have harnessed a very useful method to look for the positions of letters or numbers in a
vector, but the answer obtained does not provide a one to one correspondence between the
search values and the resultant positions:
List ← 15 40 63 18 27 40 33 29 40 88  Vector of values
Where ← 29 63 40 33 50  We want to find these
(List ∮ Where) / ∯∰List  Let's apply our method
2 3 6 7 8 9  Positions found
The positions are correct, but 29 is not in position 2, and 40 is not in position 6.
The question we have answered using the expression above is: "In which positions in List do
we find a number that also appears somewhere in Where?"
If we want to answer the slightly different question: "Where in List do we find each number
in Where?" we need to use a different method.
This new method uses the dyadic form of the symbol ∯ (Iota).
List ← 15 40 63 18 27 40 33 29 40 88  Same vector of values
Where ← 29 63 40 33 50  Where are these?
List ∯ Where  New method using dyadic ∯
8 3 2 7 11  Positions found
18 Dyalog APL - Tutorial

It is true that 29, 63, 40 and 33, occur respectively in positions 8, 3, 2 and 7. It's much better!
But, first surprise: The value 40 occurs 3 times in List, but only the first one is reported in
the result. This is because, by definition, dyadic Iota returns only the first occurrence of a
given item. If the response for each value sought has to match a position; how may one,
looking for 5 numbers, obtain 7 results?
Second surprise: The value 50 is reported as being found in position 11 in a vector comprising
only 10 items! This is how the function IndexOf (dyadic ∯) reports that a value is absent.
At first sight this seems a bit surprising, but in fact it is a property which makes this function
so generally powerful, as we shall soon see.

An Example
A car manufacturer decides that he will offer his customers a discount on the catalogue price
(you can see how this example is imaginary!)
The country has been divided into 100 areas, and the discount rate will depend on the area
according to the following table:

Area Discount

17 9%
50 8%
59 6%
84 5%
89 4%

Others 2%

The problem is to calculate the discount rate that may be claimed for a potential customer who
lives in given area D; for example D ← 84.
Let us begin by creating two variables:
Area ← 17 50 59 84 89
Discount ← 9 8 6 5 4 2
Let us see if 84 is in the list of favoured areas:
D ∮ Area
1  Yes, it's there
Area ∯ D
4  84 is the 4th item in the list
Introduction - Will you play APL with me ? 19
Let us find the current rate of discount for this index position:
Discount[4]
5  This customer can claim a 5% discount; good!
One may simply write: Discount[Area∯D]
If a customer lives in any area such as 75, 45, or 93, the expression Area∯D will in all cases
give the result 6, because those values are absent in Area. Then Discount[6] will always
find the rate 2%, as expected.
The importance of this approach is that it is vector-based. Suppose that publicity attracts
crowds and that therefore D is no longer a single value but a vector, the solution is still valid:
D ← 24 75 89 60 92 50 51 50 84 66 17 89
Discount[Area∯D]
2 2 4 2 2 8 2 8 5 2 9 4
All that without a program, neither "loop" nor "test", and whatever the number of areas.
Readers who know other programming languages will have no difficulty in making the
comparison.

Generalisation
In truth, the expression we just wrote is an example of an algorithm for "changing the frame of
reference". Don’t panic, the name may seem esoteric, but the concept is simple. A list of area
numbers (the initial set) is translated into a list of discount rates (the final set).
Let us now imagine the initial set to be an alphabet composed of lower case and upper case
letters, and the final set to be composed of only upper case letters (with a blank space in the
middle):
AlphLower
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
AlphUpper
ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ*
Notice that AlphUpper is one character longer than AlphLower. We have added an asterisk
at the end, and you will see why we did so:
Here is a little French sentence, with one accented letter.
Tale ← 'Le Petit Chaperon-Rouge a bouffé le Loup'
The expression below converts from lower to upper case.
AlphUpper[AlphLower∯Tale]
LE PETIT CHAPERON*ROUGE A BOUFF* LE LOUP
20 Dyalog APL - Tutorial

As one might expect, the characters – and é, which are absent from the initial alphabetic set
have been replaced by the * of the final set, but the conversion is acceptable. This solution can
easily be improved.
Once more, the rational steps to be taken to create a solution are easily translated into a
programming algorithm, and the programmer can thereby get a much more extensive insight
into the problem itself.

After Values, Let Us Process Shapes


Many traditional programming languages do not really handle arrays of numbers or
characters. They hold them in memory, but when the arrays are required for processing they
can only be handled one item at a time. It is not surprising in these circumstances, that these
languages have only limited means of controlling the shape of the data.
It is quite the opposite in APL, which offers many tools for working with the shape of the
data. We shall only look at a few of them here.

Take and Drop


The functions Take ( ↑ ) and Drop ( ∸ ) serve, as their names suggest, to extract part of a set of
values. Here we shall show only examples based on vectors, but all the other shapes of data
can be treated in a similar way.
Recalling that List has values 15 40 63 18 27 40 33 29 40 88
4 ↑ List (Ctrl+Y)
15 40 63 18  Take the first 4 items of the vector
5 ∸ List (Ctrl+U)
40 33 29 40 88  Drop the first 5 items
If the left argument is negative, these same functions count from the end of the vector.
¯3 ↑ List
29 40 88  Take the last 3 items of the vector
¯7 ∸ List  If one drops the last 7 items; it only leaves
15 40 63 the first three ones
That last result is the same as obtained by 3 ↑ List.
Some pages ago, we used Big[∯500] to extract the first 500 items of Big. We can now see
that we also could have used 500↑Big.
Introduction - Will you play APL with me ? 21
Here again, using these new symbols, it is possible to create innovative solutions to classical
problems.
Let us imagine a business with a turnover which has grown over 12 years.
The variable Tome is Turnover in millions of euros.
Tome ← 56 59 67 64 60 61 68 73 78 75 81 84
We want to calculate the difference between each year and the year before; how can we do it?
1 ∸ Tome would give 59 67 64 60 61 68 73 78 75 81 84
¯1 ∸ Tome would give 56 59 67 64 60 61 68 73 78 75 81
In other words, in each position of the first result we have "this year's turnover", and in the
same position in the second result we have "the previous year's turnover".
We see that all that remains is to subtract these results item by item:
(1∸Tome) - (¯1∸Tome)
3 8 ¯3 ¯4 1 7 5 5 ¯3 6 3  Without a program or loops; all very simple!
In place of a subtraction, a division would calculate (with some obvious adjustments) the rates
of growth instead of the differences:
100 × ( (1∸Tome) ÷ (¯1∸Tome) )-1
Let us put that in a small defined function, and apply it:
Growth ← {100∲((1∸∱)÷(¯1∸∱))-1}
Growth Tome
5.36 13.56 ¯4.48 ¯6.25 1.67 11.48 7.35 6.85 ¯3.85 8 3.70
This is not the real appearance of the result; it has been rounded just for printing purposes.

Mirrors and Transposition


APL is also well equipped with functions to pivot data about any axis, as suggested by the
appearances of the symbols used. They apply to both numeric and character data; as we are
going to show by applying these functions to the variable Towns that we used earlier.
The symbols used hereafter are obtained like this: ⌽  Ctrl+Shift+5
⍁  Ctrl+Shift+7
⍉  Ctrl+Shift+6
22 Dyalog APL - Tutorial

Top-bottom Swap
Initial Variable Left-right reverse reverse Rows & Columns
(Mirror)
(Mirror) (Transpose)

Towns ⌽Towns ⍁Towns ⍉Towns

Canberra arrebnaC Mexico CPWMMM


Paris siraP Martigues aaaoae
Washington notgnihsaW Moscow nrssrx
Moscow wocsoM Washington bihcti
Martigues seugitraM Paris esioic
Mexico ocixeM Canberra r nwgo
r g u
a t e
o s
n

The symbols used ( ⌽ ⍁ ⍉ ) are self-explanatory, no effort is required to remember any of


them. They also have dyadic uses, but we shall not demonstrate them here.

Back to Primary School


Remember when we learned our multiplication tables? In that practically Palaeolithic era, to
make sure that we knew all our tables, my teacher made us calculate the multiplication table
for the integers 1 to 9:

× 1 2 3 4 5 6 7 8 9

1 1 2 3 4 5 6 7 8 9
2 2 4 6 8 10 12 14 16 18
3 3 6 9 12 15 18 21 24 27
4 4 8 12 16 20 24 28 32 36
etc. etc.

You see, I haven’t forgotten!


Probably you have done all this just like me. And then we quickly forgot that very powerful
tool, one which APL provides under the name Outer Product.
Introduction - Will you play APL with me ? 23
The task consists of taking all possible pairs of items of two vectors, (the column and row
headings) and making them the left and right arguments of the function at the top left. For
example, 3 times 7 gives 21 (in red here above).
Next we shall go on to see what we get if we change the values a little:

× 8 5 15 9 11 40

5 40 25 75 45 55 200
4 32 20 60 36 44 160
10 80 50 150 90 110 400
3 24 15 45 27 33 120

This operation is written as follows in APL:


5 4 10 3 ∬.∲ 8 5 15 9 11 40
40 25 75 45 55 200
32 20 60 36 44 160
80 50 150 90 110 400
24 15 45 27 33 120
The Outer Product symbol is made of a small circle (Ctrl+J), a dot, and the function to be
applied. It is an operator, as one of its arguments is a function ( × in this case) rather than an
array.
Despite of its name "Outer Product" this operator is by no means restricted to working with
multiplication. We can replace the symbol for Multiplication by any other dyadic function
(like = < ≥ or ⌈), or even functions which you have defined yourself (like Plus), and you
will understand, as for Reduce which we saw earlier, that Outer Product is an operator of
amazing power.
Let’s have some fun with it:

(∯5)∬.=(∯5) (∯5)∬.<(∯5) (∯5)∬.≥(∯5) (∯5)∬.⌈(∯5) (∯5)∬.Plus(∯5)

1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 2 3 4 5 2 3 4 5 6
0 1 0 0 0 0 0 1 1 1 1 1 0 0 0 2 2 3 4 5 3 4 5 6 7
0 0 1 0 0 0 0 0 1 1 1 1 1 0 0 3 3 3 4 5 4 5 6 7 8
0 0 0 1 0 0 0 0 0 1 1 1 1 1 0 4 4 4 4 5 5 6 7 8 9
0 0 0 0 1 0 0 0 0 0 1 1 1 1 1 5 5 5 5 5 6 7 8 9 10
24 Dyalog APL - Tutorial

A Useful Application
Suppose the vector Ages contains the ages of 400 respondents to an opinion poll. We want to
establish how many people there are in each of the following categories:
0 - 25 - 30 - 35 - 45 - 50 - 55 - 65 or above.
Here is an extract of the data:
Ages  32 19 50 33 23 65 46 26 31 58 51 23 51 36 28 42 ... etc
Category  0 25 30 35 45 50 55 65
We are going to use the Outer Product Category ∬.< Ages , and here are the first items of
the result:

< 32 19 50 33 23 65 46 26 31 58 51 23 51 36 28 42 34 ... etc

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
25 1 0 1 1 0 1 1 0 1 1 1 0 1 1 1 1 1
30 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1
35 0 0 1 0 0 1 1 0 0 1 1 0 1 1 0 1 0
45 0 0 1 0 0 1 1 0 0 1 1 0 1 0 0 0 0
50 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 0 0 … etc.
etc.

If one adds up this Boolean matrix, one obtains for each row the number of people who are
older than 0 years, older than 25 years, older than 30 years, etc. This is the expression:
cum ← +/ (Category ∬.< Ages)
With the cut-down extract shown above, the value of cum would be: 17 14 12 8 6 4
In other words there are 12 people older than 30. But among them, 8 are older than 35. In
order to know how many people are between 30 and 35, it is necessary to calculate 12-8 to
obtain 4.
If one wants to reproduce this calculation for all categories, it is necessary to perform a series
of subtractions as here:
17 14 12 8 6 4 This is cum
- 14 12 8 6 4 0 This is cum without its first item and followed by zero
-------------- Let us subtract
= 3 2 4 2 2 4 This result was obtained by the calculation cum-(1∸cum,0)
To append a zero to the right, we used a comma, which joins variables together. This is a
function called Catenate.
If one no longer works with a small extract of data, but with the full list of 400 people, this is
what one gets:
Introduction - Will you play APL with me ? 25
cum ← +/ (Category ∬.< Ages)
cum - (1∸cum,0)
56 32 56 104 63 38 37 14
All that without real programming, and it works whatever the number of people or categories.
What luck!
Once again, APL allowed us to find straightforward and original solutions to traditional
problems.

There Is a Lot to Discover Yet


In the course of these pages we have flown over APL country and glimpsed certain bold ideas
which explain the attraction of the language. A thousand other things remain to be seen! If
you are convinced that Dyalog APL is worth the effort, you can start studying APL in much
more detail in the rest of this book.
Let us just discover some additional attractive features of APL.

Attractively Simple Syntax Rules


Most other programming languages contain rather complex rules to determine how an
expression is evaluated; a concept called operator precedence. Very often it says that for
example multiplication and division have higher precedence than addition and subtraction,
meaning that an expression like 5 × 3 + 2 gives 17, because the multiplication is done first,
and then the addition.
This sounds simple and familiar, but it quickly gets very complex and difficult to remember,
especially in a language containing many functions, like APL. For example, which precedence
should we give to ∯ or ∸ or ⌈, for which we do not have an established tradition? And what
about the functions we write ourselves?
The democratic solution adopted in APL is "We hold these truths to be self-evident that all
functions are created equal!" The only and very simple rule is that any function works on the
result of the entire expression to its right, and, if it is a dyadic function, the value immediately
to the left of it. As usual, parentheses can be used to group parts of an expression.
So, let us see how this applies to the expression above:
5 × 3 + 2
26 Dyalog APL - Tutorial

× works on 5 (the value immediate to the left of it) and the result of 3 + 2, the entire
expression to the right of it. Even though it is not strictly correct, many people say that APL
evaluates from right to left. In any case, the result of the expression is 25 in APL!
Had we written (5 × 3) + 2 instead the result would of course have been 17.
It may take a little while to get used to this slightly unfamiliar rule, but once it has been
learned it is really a great advantage because you can direct your energy towards solving your
problem and not have to remember complex rules just to satisfy the computer's need for
guidance.

Use Many Other Calculating Tools


We have discovered some original functions, which are completely absent from most other
programming languages, like ∰, ↑, ⍉, ∮, and Outer Product. Those features lead to new
methods and new algorithms to process data; this is one of the main advantages of APL.
Not only do you have a lot more functions: Inner Product (generalized matrix product), many
built-in mathematical tools (trigonometry, matrix inverse, conversions to and from any
numerical base, etc.), but you can also handle generalized (nested) arrays; arrays which
contain arrays, which themselves contain arrays, and so on.
The scope of the possible solutions to a single problem is often so wide that it is probably the
reason why people never get tired of using APL: They always have something new to
discover and to invent.

Create User-friendly Applications with the GUI


Like all modern programming languages, Dyalog APL has a Graphic User Interface (GUI)
under Microsoft Windows and Win32 emulators under Unix. It allows you to design pleasant
user interfaces with all the items and features you are familiar with. Even a beginner can
quickly create an interface and process the data with all the power of the language, whereas in
traditional languages, the same operation would need days or weeks of programming. The
Microsoft.Net interface supports the use of WinForms and Windows Presentation Foundation
GUI elements as well.

Access Your Data


Of course, Dyalog APL has built-in instructions to access data files, and SQL databases like
Oracle, SQL Server, or other popular databases. These interfaces allow you to visualise and
process part or all of a data base as if it were an array, to which you can apply all the array
processing functions available in APL. That saves you a lot of heavy programming tasks.
Introduction - Will you play APL with me ? 27
Dyalog APL has also its own powerful file system. These files are collections of arrays of any
shapes or sizes, which can be processed with the full power of the language. Databases built
with this special feature are extremely compact (2 to 3 times smaller than an equivalent
relational database). They can be shared, and they offer much greater flexibility and superior
performance compared to traditional database management systems.

Build an Efficient Partnership With Microsoft Excel


Microsoft Excel, probably the most popular spreadsheet manager, is used all over the world
by millions of people. It appears that Excel is an easy way to enter data into a computer in a
tabular form, and it is also an excellent product to produce everyday business reports and
graphs.
While Excel is convenient for small business applications, it is too limited to process complex
calculations, or when some operations involve data located in many workbooks.
Excel and APL can easily be combined in an efficient partnership. Excel is used to input data
in a very flexible way into spreadsheets, which most users are familiar with. APL can then
read dozens (and sometimes hundreds) of sheets, aggregate the data, and perform very
complex calculations, which may be controlled and parameterized through the GUI interface.
Of course, the results can be printed, but they can also be output to the users in the form of
specially prepared Excel worksheets. In these worksheets, the users can proceed to additional
operations for their particular needs, or produce graphs of their own.

And Also…
You can interface APL with Internet, write your own web server, use multithreading to
process simultaneous tasks, use all the advantages of true Object Oriented Programming, and
use many attractive features, which are beyond the scope of this quick survey.
28 Dyalog APL - Tutorial

FAQ
Perhaps you have found this language rather engaging, but before you decide to invest time
and energy in developing APL applications, you would like to be sure of your choice. Let's
give you some answers.

Is Dyalog APL A Professional Tool?


Among many others, here are some significant examples of important applications:
 Long term Board level financial planning for one of the world's five biggest petroleum
companies, used over 12 years.
 The management of supplies required from 'today + 2 days' to 'today + 3 months', by the
assembly lines of the 6 principal factories of a major international car manufacturer.
 Risk Management for an important insurance group.
These three examples have common characteristics, positioning them as major industrial
applications:
 They are particularly crucial because considerable finances are at stake.
 They must be absolutely reliable. A major car manufacturer works must not be brought to
a stop by a programming bug.
 The first two applications operate in a highly volatile business environment. As their
requirements are always changing, the programs undergo constant mutation. These
evolutions must be made with very short development cycles.
So we can answer: Yes, for a reasonable cost in labour, APL makes it possible to create,
maintain, support, and further develop large, sensitive applications of the highest level of
quality, reliability, and flexibility.

Can Dyalog APL Fit a Professional Developer's Needs?


The characteristics of APL make it easy to use, lead to quick development, and help to
produce light and flexible code. Programs developed in APL can evolve quickly, to fit
changing user requirements at will.
 Because APL uses symbols rather than words to represent operations, a programmer can
use any word for his own data and program names; they will never be in conflict with the
language structure and contents.
Random documents with unrelated
content Scribd suggests to you:
"What hand would crush the
silken-wingèd fly,
The youngest of
inconstant April's
minions,
Because it cannot climb the
purest sky,
Where the swan sings,
amid the sun's
dominions?
Not thine."
Shelley.
"Do not mash your
specimens!"—The
Professor.
COLLECTING APPARATUS
Nets.—In the capture of insects of all orders, and especially of
butterflies and moths, one of the most important instruments is the
net. German naturalists make use of what are known as shears
(Scheren), which are made like gigantic scissors, having at the end
two large oval rings upon which wire gauze or fine netting is
stretched. With this implement, which looks like an old-fashioned
candle-snuffer of colossal size, they succeed in collecting specimens
without doing much injury. Shears are, however, not much in vogue
among the naturalists of other countries. The favorite instrument for
the ordinary collector is the net. Nets may be made in various ways
and of various materials. There are a multitude of devices which
have been invented for enabling the net to be folded up so as to
occupy but little space when not in use. The simplest form of the
net, which can be made almost anywhere, is constructed as follows:
A rod—preferably of bamboo, or some other light, stiff material—is
used as the handle, not more than five feet in length. Attached to
this at its upper end, a loop or ring made of metal, or some
moderately stiff

Fig. 43.—Plan for folding net-ring:


c, halves of ring detached; b, upper
joint of the halves; a, ring set; d,
cap of ferrule; f, cap of ferrule,
showing screw in place; e, screw
(Riley).

yet flexible material, should


be tied securely. Upon this
there should be sewed a bag
of fine netting, preferably
tarletan. The bag should be
Fig. 44.—a, net; b, quite long, not less than
ferrule to receive eighteen inches deep; the ring
handle; c, wire hoop to should be not less than a foot
be fastened in the in diameter. Such a net can be Fig. 45.—a,
upper end of the ferrule made at a cost of but a few ring of
(Riley). cents, and will be, in most metal tied
cases, as efficient as any of with wire
the more expensive nets which are more carefully at a; b,
constructed. A good, cheap ring for a net may be made ferrule; c,
by using the brass ferrule of a fishing-rod. The ferrule plug put in
should be at least three quarters of an inch in before
diameter. Into this insert the ends of a metal ring made pouring in
by bending brass, aluminium, or iron wire into the solder
proper form. When the ends have been inserted into (Riley).
the ferrule, melted solder or lead may be poured into
it, and the ends of the wire forming the ring will be thus firmly
secured in the ferrule. The ferrule can then be inserted into its mate
placed at the end of a bamboo rod. I have commonly obtained for
this purpose the last joint or butt of a fishing-rod as the handle of a
net. Such a handle can often be purchased for a small sum from a
dealer in fishing-rods. It can be made very cheaply. Any kind of a
stick, if not too heavy, will do. It is sometimes convenient to have it
in your power to lengthen the handle of your net so as to reach
objects that are at some elevation above the head, and for this
purpose I have had nets made with handles capable of being
lengthened by jointed extensions. In collecting in tropical countries,
among tall shrubbery and undergrowth, nets thus made, capable of
having their handles greatly lengthened, have often proved
serviceable. One of the most successful collectors I have ever had in
my employment made his net by simply bending a piece of bamboo
into the form of the frame of an Indian snow-shoe, to which he
attached a handle about a foot and a half in length, and to this he
affixed a bag of netting. He was, however, a Japanese, and
possessed a singular dexterity in the capture of specimens with this
simple apparatus to which I myself never attained. When tarletan
cannot be had, ordinary mosquito-netting will do as the material for
the bag. It is, however, too coarse in the mesh for many delicate and
minute species. Very fine netting for the manufacture of the bags is
made in Switzerland, and can be obtained from reputable dealers.
In order to protect and preserve the net, it is well to bind it with
some thin muslin at the point where it is joined to the ring. Nets are
sometimes made with a strip of muslin, about two inches wide,
attached to the entire circumference of the ring, and to this strip of
muslin the bag is sewed. For my part, I prefer gray or green as the
color for a net. White should be avoided, as experience shows that a
white net will often alarm an insect when a net of darker material
will not cause it to fly before the collector is ready to bring the net
down over the spot where it is settled.
Collecting-Jars.—In killing insects various methods have been
used. In practice the most approved method is to employ a jar
charged with cyanide of potash or with carbonate of ammonia. For
large moths and butterflies cyanide of potash and carbonate of
ammonia serve very well, but it must be remembered that carbonate
of ammonia bleaches insects which are green in color. It is well, in
my judgment, to use a drop or two of chloroform in the jar charged
with carbonate of ammonia, for the collection of diurnal lepidoptera.
By putting a few drops of chloroform into the jar, the insect is
anesthetized, and its struggles are made quickly to cease. The
principal objection to chloroform is the fact that it induces rigidity of
the thoracic muscles, which subsequently sometimes interferes with
handsome setting.
In the preparation of the poisoning-jar
it is well to use a jar which has a ground-
glass stopper, and the mouth of which is
about three inches in diameter. This will
be large enough for most specimens. The
Fig. 47.— one-pound hydrate of chloral jars,
Piece of provided with glass stoppers and sold by
paper Schering, make the neatest collecting-jars
punctured that are known to the writer. I have
and slit for found it well to have such jars partly
pasting covered with leather after the fashion of Fig. 46.—
over the a drinking-flask. An opening in the Cyanide-jar
cyanide in leather is left on either side, permitting prepared
the an inspection of the contents of the jar. for use: P,
collecting- The leather protects from breakage. At perforated
jar. the bottom of such a jar a few lumps of cardboard;
cyanide of potash, about the size of a Cy, lumps
filbert, should be placed. Over this may be laid a little
cotton, to prevent the lumps from rattling about loosely of cyanide
at the bottom of the jar. Over the cotton there is of potash.
pasted a sheet of strong white paper, perforated with a
multitude of holes. In securing the white paper over the cyanide, the
writer has resorted to a simple method which is explained in the
annexed diagram. A piece of paper is placed under the jar, and a
circle the size of the inside of the jar is traced upon it. Then a disk is
cut out about three quarters of an inch greater in diameter than the
original circle (Fig. 47). The paper is punctured over the entire
surface included within the inner line, and then, with a scissors, little
gashes are made from the outer circumference inward, so as to
permit of the folding up of the edge of the disk. A little gum
tragacanth is then applied to these upturned edges; and it is
inserted into the jar and pasted securely over the cyanide by the
upturned flaps. A jar thus charged will last for a long time, if kept
properly closed when not in use. Cyanide of potash has a tendency
to deliquesce, or melt down in the presence of moisture, and in very
humid climates or damp places, if the jar is not kept well stoppered,
the cyanide will quickly become semi-fluid, the paper will become
moist, and specimens placed in the jar will be injured or completely
ruined. It is well, however, to bear in mind the fact that the fumes of
hydrocyanic acid (prussic acid), which are active in producing the
death of the insect, will not be given off in sufficient volume unless
there is some small amount of moisture present in the jar; and in a
very dry climate the writer has found it sometimes necessary to add
a drop or two of water from time to time to the cyanide. The same
method which has been described for charging a jar with cyanide of
potash can be employed in charging it with carbonate of ammonia.
Fig. 48.—Method of disabling a
butterfly by pinching it when in the
net.

Field-Boxes.—In collecting butterflies it is often possible to kill, or


half kill, the specimens contained in the net by a smart pinch
administered to the insect by the thumb and the first finger, the
pressure being applied from without the net (Fig. 48). This mode of
procedure, however, unless the operator is careful, is apt to
somewhat damage the specimens. The writer prefers to hold the
insect firmly between the thumb and the first finger, and apply a
drop or two of chloroform from a vial which should be carried in the
upper left-hand vest-pocket. The application of the chloroform will
cause the insect to cease its struggles immediately, and it may then
be placed in the poisoning-jar, or it may be pinned into the field-box.
The field-box, which should be worn at the side, securely held in its
place by a strap going over the shoulder and by another strap
around the waist, may be provided with the poisoning apparatus or
may be without it. In the former case the box should be of tin, and
should have securely fastened in one corner some lumps of cyanide,
tied in gauze. The box should be very tight, so that when it is closed
the fumes of the cyanide may be retained. The bottom should be
covered with cork, upon which the specimens, as they are
withdrawn from the poisoning-jar, should be pinned. It is well to
bear strictly in mind that it is a mistake to continue to put one
specimen after another into the poisoning-jar until it is half filled or
quite filled with specimens. In walking about the field, if there are
several insects in the jar at a time, they are likely to become rubbed
and their beauty partially destroyed by being tossed about as the
collector moves from place to place; and a large insect placed in a
jar in which there are one or two smaller insects will in its death-
struggles possibly injure the latter. So, as fast as the insects are
partially asphyxiated, or deprived of the power of motion, they
should be removed from the poisoning-jar to the poisoning-box,
where they are pinned in place and prevented from rubbing one
against the other. Some collectors prefer simply to stun the insects,
and then pin them into the field-box, where they are left, in whole or
in part, to recover their vitality, to be subsequently put to death
upon the return of the collector from the field. This mode of
procedure, while undoubtedly it yields in the hands of a skilful
operator the most beautiful specimens, appears to the writer to be
somewhat cruel, and he does not therefore approve of it.

Plate
IV.

The Use of the Net.—In the use of the net the old saying is true
that "practice makes perfect." The bag of the net should be
sufficiently long to allow of its being completely closed when
hanging from the ring on either side. It is possible to sweep into the
net an insect which is fluttering through the air, and then by a turn
of the hand to close the bag and to capture the specimen. When the
insect has alighted upon the ground it is best to clap the net over it
and then to raise the net with one hand. Very many species have the
habit of flying upward. This is particularly true of the skippers, a
group of very vigorous and swift-flying butterflies. The writer
prefers, if possible, to clap the net over the specimens and then to
allow them to rise, and, by inserting the wide-mouthed collecting-jar
below, to capture them without touching them at all with the fingers.
So far as possible the fingers should not be allowed to come in
contact with specimens, whether in or out of the net, though some
persons acquire an extremely delicate yet firm touch which enables
them to handle the wings of frail species without removing any of
the scales. Nothing is more unsightly in a collection than specimens
that have been caught and rubbed by the fingers.
Baits.—Moths are frequently taken by the method of collecting
known as "sugaring." But it may also be employed for butterflies. For
this purpose a mixture of beer and cheap brown sugar may be used.
If the beer be stale drippings, so much the better. In fact, it is well, if
the collector intends to remain in one locality for some time, to make
a mixture of beer and sugar some hours or a day in advance of its
application. In semi-tropical countries a mixture of beer and sugar is
hardly as good as a mixture of molasses and water into which a few
tablespoonfuls of Jamaica rum have been put. A mixture thus
prepared seems to attract more effectually than the first
prescription. Having provided a pail with a quart or two of the
mixture, the collector resorts to the point where he proposes to
carry on his work. With an ordinary whitewash brush the mixture is
applied to the trunks of trees, stumps, fence-rails, and other objects.
It is well to apply the mixture to a series of trees and posts located
on the side of a bit of woodland, or along a path through forests, if
comparatively open and not too dense. The writer has rarely had
success in sugaring in the depths of forests. His greatest success has
always been on paths and at the edge of woods. Many beetles and
other insects come to the tempting sweets, and separate jars for
capturing these should be carried in the pocket. The collector never
should attempt to kill beetles in the same jar into which he is putting
butterflies. The hard, horny bodies and spiny legs of beetles will
make sad havoc with the delicate wings of butterflies.
Many other baits besides this may be employed to attract insects.
Some writers recommend a bait prepared by boiling dried apples
and mashing them into a pulp, adding a little rum to the mixture,
and applying this to the bark of trees. In tropical countries bananas,
especially rotten bananas, seem to have a charm for insects. The
cane-trash at sugar-mills is very attractive. If possible, it is well to
obtain a quantity of this trash and scatter it along forest paths. Some
insects have very peculiar appetites and are attracted by things
loathsome. The ordure of carnivorous animals seems to have a
special charm for some of the most magnificently colored and the
rarest of tropical butterflies. A friend of mine in Africa, who collected
for me for a number of years, used to keep civet-cats, the ordure of
which was collected and placed at appropriate points in the forest
paths; and he was richly rewarded by obtaining many insects which
were not obtained in any other way. Putrid fish have a charm for
other species, and dead snakes, when rankly high, will attract still
others. It may be observed that after the trees have been treated for
a succession of days or nights with the sweetening mixture spoken
of above, they become very productive. When collecting in Japan I
made it a rule to return in the morning to the spots that I had
sugared for moths the evening before, and I was always amply
repaid by finding multitudes of butterflies and even a good many
day-flying moths seated upon the mossy bark, feasting upon the
remnants of the banquet I had provided the evening before. There is
no sport—I do not except that of the angler—which is more
fascinating than the sport derived by an enthusiastic entomologist
from the practice of "sugaring." It is well, however, to know always
where your path leads, and not to lay it out in the dusk, as the
writer once did when staying at a well-known summer resort in
Virginia. The path which he had chosen as the scene of operations
was unfortunately laid, all unknown to himself, just in the rear of the
poultry-house of a man who sold chickens to the hotel; and when he
saw the dark lantern mysteriously moving about, he concluded that
some one with designs upon his hens was hidden in the woods, and
opened fire with a seven-shooter, thus coming very near to
terminating abruptly the career of an ardent entomologist.
Beating.—There are many species which are apparently not
attracted by baits such as we have spoken of in the preceding
paragraph. The collector, passing through the grove, searches
diligently with his eye and captures what he can see, but does not
fail also with the end of his net-handle to tap the trunks of trees and
to shake the bushes, and as the insects fly out, to note the point
where they settle, and then make them his prey. It is well in this
work, as in all collecting, to proceed somewhat leisurely, and to keep
perfectly cool. The caricature sometimes found in newspapers of the
ardent lepidopterist running like a "quarter-back" across a ten-acre
lot in quest of some flying insect does not represent the truly skilful
collector, whose movements are more or less stealthy and cautious.
THE BREEDING OF SPECIMENS
By breeding it is possible to obtain specimens in the most perfect
condition. Bred specimens which have not had an opportunity to fly
are always preferred on account of their freshness of color and
perfection of form. A great many species which apparently are
exceedingly rare may often be obtained in considerable numbers by
the process of breeding, the caterpillar being more readily found
than the perfect insect. Although the process of breeding involves a
good deal of labor and care, it affords a most delightful field for
observation, and the returns are frequently of the very greatest
value.
How to Get the Eggs of Butterflies.—The process of breeding may
begin with the egg. The skilful eye of the student will detect the
eggs of butterflies upon the leaves upon which they have been
deposited. The twig may be cut and placed in a vase, in water, and
kept fresh until the minute caterpillar emerges, and then from time
to time it may be transferred to fresh leaves of the same species of
plant, and it will continue to make its moults until at last it is
transformed into a chrysalis, and in due season the butterfly
emerges. Eggs may frequently be obtained in considerable numbers
by confining the female under gauze, with the appropriate food-
plant. A knowledge of the food-plant may often be obtained by
watching the female and observing upon what plants she deposits
her eggs. The exceedingly beautiful researches of Mr. W.H. Edwards
were largely promoted by his skill in inducing females to oviposit
upon their food-plants. He did this generally by confining the female
with the food-plant in a barrel or nail-keg, the bottom of which had
been knocked out, and over the top of which he tied mosquito-
netting. The plant was placed under the keg. The insects thus
confined may be fed with a mixture of honey and water placed upon
the leaves.
In collecting caterpillars it is well to have on hand a number of
small boxes in which to place them, and also a botany-box in which
to bring from the field a supply of their appropriate food.
The process of breeding may begin with the caterpillar. The
collector, having discovered the caterpillar feeding upon the branch
of a certain plant, provides the creature with a constant supply of
the fresh foliage of the same plant, until it finally pupates.
Breeding-Cages.—Various devices for
breeding caterpillars and rearing moths and
butterflies are known. One of the most
important of these devices is the breeding-
cage, which is sometimes called a vivarium.
The simplest form of the vivarium is often
the best. In breeding some species the best
method is simply to pot a plant of the
species upon which the larva is known to
feed, and to place the potted plant in a box Fig. 49.—Cheap form of
over which some mosquito-netting is tied. breeding-cage: G, lid
The writer frequently employs for this covered with mosquito-
purpose cylinders of glass over the top of netting; E, pan of
which perforated cardboard is placed. This earth; B, bottle for
method, however, can be resorted to only food-plant.
with the more minute forms and with plants
that do not attain great height. Another
form of vivarium is represented in the adjoining woodcut (Fig. 50).
The writer has successfully employed, for breeding insects upon a
large scale, ordinary store boxes provided with a lid made by
fastening together four pieces of wood, making a frame large
enough to cover the top of the box, and covering it with gauze. The
food-plant is kept fresh in bottles or jars which are set into the
boxes. Be careful, however, after you have put the branches upon
which the caterpillars are feeding into the jars, to stuff something
into the neck of the jar so as to prevent the caterpillar from
accidentally getting into the water and drowning himself—a mishap
which otherwise might occur. When breeding is undertaken on a still
larger scale, it may be well to set apart for this purpose a room,
preferably in an outbuilding, all the openings leading from which
should be carefully closed so as to prevent the escape of the
caterpillars.

Fig. 50.—Breeding-cage: a, base,


battened at g to prevent warping;
b, removable body of cage,
inclosing zinc pan, f, f, containing
jar for plant, d, and filled with five
inches of soil, e; c, removable top,
covered with wire gauze. The doors
and sides are of glass (Riley).
How to Find Caterpillars.—Many species of caterpillars are not
hard to discover; they are more or less conspicuous objects, and
strike the eye. Some species conceal themselves by weaving
together the leaves of the plant on which they feed, or by bending a
single leaf into a curved receptacle in which they lie hidden. Others
conceal themselves during the daytime about the roots of trees or
under bark or stones, only emerging in the night-time to feed upon
the foliage. The collector will carefully search for these. The
presence of caterpillars is generally indicated by the ravages which
they have committed upon the foliage. By carefully scanning a
branch the collector will observe that the leaves have been more or
less devoured. Generally underneath the tree will be found the frass,
or ejectamenta, of the caterpillar. The presence of the ejectamenta
and the evidence of the ravages committed by the larvæ upon the
foliage will give the collector a clue to the whereabouts of the
caterpillar. The writer has found it generally advantageous to search
for caterpillars that feed upon trees along the wide, sandy margins
of brooks and rivers. The frass is easily discovered upon the sand,
and by casting the eye upward into the foliage it is often easy to
detect the insect. The pavements in towns and cities which are
bordered by trees may also very well be scanned for evidence of the
presence of caterpillars. A favorite collecting-ground of the writer is
one of the large cemeteries of the city in which he lives, in which
there are numerous trees and a great quantity of shrubbery. Wood-
boring species, as a rule, are more difficult to obtain and rear than
those that feed upon the foliage.
Hibernating Caterpillars.—While some difficulty attends the
preservation of chrysalids in the case of those species which pupate
in the fall and pass the winter in the chrysalis state under the
ground, far more difficulty attends the preservation of species which
hibernate in the caterpillar state. As a rule, it is found best to expose
the boxes containing these species in an ice-house or other cold
place, keeping them there until there is available an abundant supply
of the tender shoots of the plant upon which they are in the habit of
feeding. They may then be brought forth from cold storage and
placed in proximity to the food-plant, upon which they will proceed
to feed.
THE PRESERVATION OF SPECIMENS
Papering Specimens.—When time and opportunities do not suffice
for the proper preparation of butterflies for display in the permanent
collection, the collector may, in the case of the larger species,
conveniently place them in envelopes, with their wings folded (Fig.
51), and they may then be stored in a box until such time as he is
able to relax the specimens and properly mount them. Thousands of
insects are thus annually collected. The small drug envelopes, or the
larger pay-roll envelopes, which may be bought in boxes by the
thousand of any stationer for a comparatively small sum, are
preferable because of their convenience. Many collectors, however,
paper their specimens in envelopes which they make of oblong bits
of paper adapted to the size of the insect. The process of making
the envelope and of papering the insect is accurately depicted in the
accompanying cut (Fig. 52). The writer finds it good in the case of
small butterflies to place them in boxes between layers of cheap
plush or velvet. A small box, a few inches long, may be provided,
and at its bottom a layer of velvet is placed; upon this a number of
small butterflies are laid. Over them is placed a layer of velvet, with
its soft pile facing the same side of the velvet at the bottom. On top
of this another piece of velvet is laid, with its pile upward, and other
specimens are again deposited, and over this another piece of velvet
is laid, and so on. If the box is not filled full at once, it is well to
have enough pieces of velvet cut to fill it, or else place cotton on
top, so as to keep the layers of velvet from moving or shaking about.
A yard or two of plush or velvet will suffice for the packing of a
thousand specimens of small butterflies.
Mounting Butterflies.—When the collector has time enough at his
disposal he should at once mount his specimens as they are
intended to be displayed in the collection. We shall now proceed to
explain the manner in which this is most advantageously
accomplished. The insect should first of all be pinned. The pin
should be thrust
perpendicularly
through the
thorax, midway
between the
Fig. 51.—Butterfly in wings, and at a
envelope. considerable
elevation upon the Fig. 52.—Method of
pin. It should then be placed upon the folding paper for
setting-board or setting-block. Setting- envelopes: first fold on
boards or setting-blocks are pieces of wood line AB; then on AD and
having a groove on the upper surface of CB; then on BF and EA.
sufficient depth to accommodate the body
of the insect and to permit the wings to be
brought to the level of the upper surface of the board (Fig. 53).
They should also be provided either with a cleft or a hole which will
permit the pin to be thrust down below the body of the insect for a
considerable distance. As a rule, the wings of all specimens should
be mounted at a uniform elevation of about seven eighths of an inch
above the point of the pin. This is known as the "continental
method" of mounting, and is infinitely preferable to the old-
fashioned "English method," in which the insect was pinned low
down upon the pin, so that its wings touched the surface of the box.
Setting-blocks
are most
advantageously
employed in
setting small
species, especially
the Hesperiidæ,
the wings of which
Fig. 54.—Setting-block:
are refractory.
A, holes to enable the
When the insect Fig. 53.—Setting-board
pin to reach to the
has been pinned designed by the author.
cork; C, cork, filling
upon the setting- The wings of the insect
groove on the bottom board or setting- are held in place by
of the block; B, slit to block, the next strips of tracing-
hold thread. step is to set the muslin, such as is used
wings in the by engineers. The
position which they are to maintain when grooves at the side
the specimen is thoroughly dry. This is serve to hold the board
accomplished by means of what are known in place in the drying-
as "setting-needles" (Fig. 56). Setting- box. (See Fig. 59.)
needles may be easily made by simply
sticking ordinary needles into wooden
matches from which the tips have been
removed. In drawing the wings into
position, care should be taken to plant the
setting-needle behind the strong nervure on
the costal margin of the wing; otherwise
the wings are liable to be torn and
disfigured. The rule in setting lepidoptera is
to draw the anterior wing forward in such a Fig. 55.—Setting-block
manner that the posterior margin of this with butterfly
wing is at right angles to the axis of the expanded upon it.
body, the axis of the body being a line
drawn through the head to the extremity of the abdomen. The hind
wing should then be moved forward, its anterior margin lying under
the opposing margin of the front wing. When the wings have thus
been adjusted into the position which they are to occupy, slips of
tracing-muslin or of paper should be drawn down over them and
securely pinned, the setting-needles being removed.
In pinning down the strips which are to
hold the wings in place, be careful to pin
Fig. 56.—Setting-needle. around the wing, but never, if possible,
through it. When the wings have been
adjusted in the position in which they are to remain, the antennæ,
or feelers, should be attended to and drawn forward on the same
plane as the wings and secured in place. This may ordinarily be done
by setting pins in such a position as to hold them where they are to
stay. Then the body, if it has a tendency to sag down at the end of
the abdomen, should be raised. This may also be accomplished by
means of pins thrust beneath on either side. The figure on the next
page shows more clearly what is intended. When the insect has
been set, the board should be put aside in a place where it will not
be molested or attacked by pests, and the specimens upon it
allowed to dry. A box with shelves in it is often used for this purpose.
This box should have a door at the front covered with wire gauze,
and the back should also be open, covered with gauze, so as to
allow a free circulation of air. A few balls of naphthaline placed in it
will tend to keep away mites and other pests. The time during which
the specimen should remain on the board until it is dried varies with
its size and the condition of the atmosphere. Most butterflies and
moths in dry weather will be sufficiently dried to permit of their
removal from the setting-boards in a week; but large, stout-bodied
moths may require as much as two weeks, or even more time,
before they are dry enough to be taken off the boards. The process
of drying may be hastened by placing the boards in an oven, but the
temperature of the oven must be quite low. If too much heat is
applied, great injury is sure to result. Only a careful and expert
operator should resort to the use of the oven, a temperature above
120°F. being sure to work mischief.

Fig. 57.—Setting-board
with moth expanded
upon it (Riley).
Fig. 58.—Butterfly
pinned on board,
showing method of
holding up body and
pinning down antennæ.

Fig. 59.—Drying-box: a, setting-


board partly pulled out; b, T-
shaped strip working in groove on
setting-board; c, front door, sliding
down by tongue, d, working in a
groove at side in front.

Relaxing Specimens.—When butterflies or moths have been put up


in papers or mounted on pins without having their wings expanded
and set it becomes necessary, before setting them, to relax them.
This may be accomplished in several ways. If the specimens have
been pinned it is best to place them on pieces of sheet-cork on a
tray of sand which has been thoroughly moistened and treated with
a good dose of carbolic acid. Over all a bell-glass is put. A tight tin
box will serve the same purpose, but a broad sheet of bibulous
paper should always be put over the box, under the lid, before
closing it, and in such a way as to leave the edges of the paper
projecting around the edges of the lid. This is done to absorb the
moisture which might settle by condensation upon the lid and drop
upon the specimens. In a bell-glass the moisture generally trickles
down the sides. Earthenware crocks with closely fitting lids are even
better than tin boxes, but they must have paper put over them,
before closing, in the same way as is done when tin boxes are used.
When specimens have been preserved in papers or envelopes these
should be opened a little and laid upon damp, carbolized sand under
a bell-glass or in a closed receptacle of some kind. Papered
specimens may also be placed in their envelopes between clean
towels, which have been moistened in water to which a little carbolic
acid has been added. The towels should be wrung out quite dry
before using them. The method of placing between towels should
never be used in the case of very small and delicate species and
those which are blue or green in color. Great care must be exercised
not to allow the insects to become soaked or unduly wet. This ruins
them. They should, however, be damp enough to allow the wings
and other organs to be freely moved. When the insects have been
relaxed they may be pinned and expanded on setting-boards like
freshly caught specimens. It is well in setting the wings of relaxed
specimens, after having thrust the pin through the body, to take a
small forceps and, seizing the wings just where they join the body,
gently move them so as to open them and make their movement
easy before pinning them upon the setting-board. The skilful
manipulator in this way quickly ascertains whether they have been
sufficiently relaxed to admit of their being readily set. If discovered
to be too stiff and liable to break they must be still further relaxed.
Dried specimens which have been relaxed and then mounted
generally require only a short time to dry again, and need rarely be
kept more than twenty-four hours upon the setting-boards.
Fig. 60.—Drying-box (Riley).

The process of setting insects upon setting-blocks is exactly the


same as when setting-boards are used, with the simple difference
that, instead of pinning strips of paper or tracing-muslin over the
wings, the wings are held in place by threads or very narrow tapes,
which are wound around the block. When the wings are not covered
with a very deep and velvety covering of scales the threads or tapes
maybe used alone; but when the wings are thus clothed it becomes
necessary to put bits of paper or cardboard over the wings before
wrapping with the threads. Unless this is done the marks of the
threads will be left upon the wings. Some little skill, which is easily
acquired by practice, is necessary in order to employ setting-blocks
to advantage, but in the case of small species and species which
have refractory wings they are much to be preferred to the boards.
The Preparation and Preservation of Eggs.—The eggs of butterflies
may be preserved by simply putting them into tubes containing
alcohol, or they may be placed in vials containing dilute glycerine or
a solution of common salt. The vials should be kept tightly corked
and should be marked by a label written with a lead-pencil and
placed within the bottle, upon which the name of the species and
the date of collection should be noted, or a reference made to the
collector's note-book. Unless the eggs of insects are preserved in
fluid they are apt in many cases to dry up and become distorted,
because, on account of their small size, it is impossible to void them
of their contents. The larvæ escaping from eggs often void the shell
very neatly, leaving, however, a large orifice. Such remnants of shells
may be preserved, as they often are useful in showing some of the
details of marking; but great vigilance in securing them should be
exercised, for almost all the larvæ of butterflies have the curious
habit of whetting their appetites for future repasts by turning around
and either wholly or partially devouring the shell of the egg which
they have quitted. Eggs are most neatly mounted in the form of
microscopic slides in glycerine jelly contained in cells of appropriate
depth and diameter. It is best, if possible, to mount several
specimens upon the same slide, showing the side of the egg as well
as the end. A cabinet filled with the eggs of butterflies thus mounted
is valuable and curious.
The Preservation of Chrysalids.—Chrysalids may be deprived of
their vitality by simply immersing them in alcohol, or they may be
killed by means of chloroform, and they may then be fastened upon
pins like the imago, and arranged appropriately in the collection with
the species. Some chrysalids, however, lose their color when killed in
this way, and it is occasionally well to void them of their contents by
making an opening and carefully removing the parts that are
contained within, replacing with some material which will prevent
the chrysalis from shrinking and shriveling. This method of
preserving need, however, be resorted to only in exceptional cases.
When a butterfly has escaped from its chrysalis it frequently leaves
the entire shell behind, with the parts somewhat sundered, yet,
nevertheless, furnishing a clear idea of the structure of the chrysalis.
If no other specimen of the chrysalis can be obtained than these
voided shells they should be preserved.
The Preservation of Caterpillars.—The caterpillars of butterflies
when they first emerge from the egg, and before they make the first
moult, are, for the most part, extremely small, and are best
preserved as microscopic objects in cells filled with glycerine. After
each successive moult the larva increases rapidly in size. These
various stages in the development of the caterpillar should all be
noted and preserved, and it is customary to put up these collections
in vials filled with alcohol or a solution of formaline (which latter, by
the by, is preferable to alcohol), or to inflate them. The method of
inflation secures the best specimens.
In inflating larvæ the first step is carefully to remove the contents
of the larval skin. This may be done by making an incision with a
stout pin or a needle at the anal extremity, and then, between the
folds of a soft towel or cloth, pressing out the contents of the
abdominal cavity. The pressure should be first applied near the point
where the pellicle has been punctured, and should then be carried
forward until the region of the head is reached. Care must be
exercised to apply only enough pressure to expel the contents of the
skin without disturbing the tissues which lie nearest to the
epidermis, in which the pigments are located, and not to remove the
hairs which are attached to the body. Pressure sufficient to bruise
the skin should never be applied. A little practice soon imparts the
required dexterity. The contents of the larval skin having been
removed, the next step is to inflate and dry the empty skin. A
compact statement of the method of performing this operation is
contained in Hornaday's "Taxidermy and Zoölogical Collecting," from
the pen of the writer, and I herewith reproduce it:

Plate
V.
Fig. 61.—Apparatus for inflating
larvæ: B, foot-bellows; K, rubber
tube; C, flask; D, anhydrous
sulphuric acid; E, overflow-flask; F,
rubber tube from flask; G, standard
with cock to regulate flow of air; H,
glass tube with larva upon it; I,
copper drying-plate; J, spirit-lamp.

"The simplest method of inflating the skins of larvæ after the


contents have been withdrawn is to insert a straw or grass stem of
appropriate thickness into the opening through which the contents
have been removed, and then by the breath to inflate the specimen,
while holding over the chimney of an Argand lamp, the flame of
which must be regulated so as not to scorch or singe it. Care must
be taken in the act of inflating not to unduly distend the larval skin,
thus producing a distortion, and also to dry it thoroughly. Unless the
latter precaution is observed a subsequent shrinking and
disfigurement will take place. The process of inflating in the manner
just described is somewhat laborious, and while some of the finest
specimens which the writer has ever seen were prepared in this
primitive manner, various expedients for lessening the labor involved
have been devised, some of which are to be highly commended.
"A comparatively inexpensive arrangement for inflating larvæ is a
modification of that described in the 'Entomologische Nachrichten'
(1879, vol. v, p. 7),
devised by Mr. Fritz
Fig. 62.—Tip of A. Wachtel (Fig.
inflating-tube, with 61). It consists of
armature for holding a foot-bellows such
larval skin. as is used by
chemists in the
laboratory, or, better still, of a small cylinder
such as is used for holding gas in operating Fig. 63.—Drying-oven:
the oxyhydrogen lamp of a sciopticon. In A, lamp; B, pin to hold
the latter case the compressed air should door open; C, door
not have a pressure exceeding twenty open; D, glass cover.
pounds to the square inch, and the cock
regulating the flow from the cylinder should be capable of very fine
adjustment. By means of a rubber tube the air is conveyed from the
cylinder to a couple of flasks, one of which contains concentrated
sulphuric acid, and the other is intended for the reception of any
overflow of the hydrated sulphuric acid which may occur. The object
of passing the air through sulphuric acid is to rob it, so far as
possible, of its moisture. It is then conveyed into a flask, which is
heated upon a sand-bath, and thence by a piece of flexible tubing to
a tip mounted on a joint allowing vertical and horizontal motion and
secured by a standard to the working-table. The flow of air through
the tip is regulated by a cock. Upon the tip is fastened a small
rubber tube, into the free extremity of which is inserted a fine-
pointed glass tube. This is provided with an armature consisting of
two steel springs fastened upon opposite sides, and their ends bent
at right angles in such a way as to hold the larval skin firmly to the
extremity of the tube. The skin having been adjusted upon the fine
point of the tube, the bellows is put into operation, and the skin is
inflated. A drying apparatus is provided in several ways. A copper
plate mounted upon four legs, and heated by an alcohol-lamp placed
below, has been advocated by some. A better arrangement, used by
the writer, consists of a small oven heated by the flame of an
alcohol-lamp or by jets of natural gas, and provided with circular
openings of various sizes, into which the larval skin is introduced
(Fig. 63).
"A less commendable method of preserving larvæ is to place them
in alcohol. The larvæ should be tied up in sacks of light gauze
netting, and a label of tough paper, with the date and locality of
capture, and the name, if known, written with a lead-pencil, should
be attached to each such little sack. Do not use ink on labels to be
immersed, but a hard lead-pencil. Alcoholic specimens are liable to
become shriveled and discolored, and are not nearly as valuable as
well-inflated and dried skins.

Fig. 64.—Drying-oven: a, sliding


door; b, lid; c, body of oven with
glass sides; d, opening for inserting
inflating-tube; e, copper bottom; f,
spirit-lamp; g, base (Riley).

"When the skins have been inflated they may be mounted readily
by being placed upon wires wrapped with green silk, or upon
annealed aluminium wire. The wires are bent and twisted together
for a short distance and then made to diverge. The diverging ends
are pressed together, a little shellac is placed upon their tips, and
they are then inserted into the opening at the anal extremity of the
larval skin. Upon the release of pressure they spread apart, and after
the shellac has dried the skin is firmly held by them. They may then
be attached to pins by simply twisting the free end of the wire about
the pin, or they may be placed upon artificial imitations of the leaves
and twigs of their appropriate food-plants."
THE PRESERVATION AND ARRANGEMENT OF COLLECTIONS
The secret of preserving collections of lepidoptera in beautiful
condition is to exclude light, moisture, and insect pests. Light
ultimately bleaches many species, moisture leads to mould and
mildew, and insect pests devour the specimens. The main thing is
therefore to have the receptacles in which the specimens are placed
dark and as nearly as possible hermetically sealed and kept in a dry
place. In order to accomplish this, various devices have been
resorted to.
Boxes.—Boxes for the preservation of
specimens are made with a tongue on the
edges of the bottom fitting into a groove
upon the lid, or they may be made with
inside pieces fastened around the inner
edge of the bottom and projecting so as to
catch the lid. The accompanying outlines
show the method of joining different forms
of boxes (Figs. 65-67). The bottom of the
box should be lined with some substance
Fig. 65.—Detail drawing which will enable the specimens to be
of front of box, made to pinned into it securely. For this purpose
resemble a book: s, s, sheet-cork about a quarter of an inch thick
sides, made of two is to be preferred to all other substances.
pieces of wood glued Ground cork pressed into layers and
together across the covered with white paper is manufactured
for the purpose of lining boxes. Turf
grain; t, tongue; g, compressed into
groove; c, cork; p, sheets about half
paper covering the an inch thick and
cork. covered with paper
is used by many
European collectors. Sheets of aloe-pith or
of the wood of the yucca, half an inch thick,
are used, and the pith of corn-stalks (Indian
corn or maize) may also be employed, laid
into the box and glued neatly to the
bottom. The corn-pith should be cut into
pieces about half an inch square and joined Fig. 66.—Detail drawing
together neatly, covering it with thin white of front of box: t, top;
paper after the surface has been made b, bottom; e, side; f,
quite even and true. Cork is, however, the strip, nailed around
best material, for, though more expensive inside as at n; c, cork;
than the other things named, it has greater p, paper lining.
power to hold the pins, and unless these
are securely fixed and held in place great damage is sure to result. A
loose specimen in a box will work incalculable damage. Boxes should
be made of light, thoroughly seasoned wood, and should be very
tight. They are sometimes made so that specimens may be pinned
both upon the top and the bottom, but this is not to be commended.
The depth of the box should be sufficient to admit of the use of the
longest insect-pin in use, and a depth between top and bottom of
two and a quarter inches is therefore sufficient. Boxes are
sometimes made with backs in imitation of books, and a collection
arranged in such boxes presents an attractive external appearance.
A very good box is made for the United States Department of
Agriculture and for the Carnegie Museum in Pittsburgh (Fig. 68).
This box is thirteen inches long, nine inches wide, and three inches
thick (external measurement). The depth between the bottom and
the lid on the inside is two and one eighth inches. The ends and
sides are dovetailed; the top and bottom are each made of two
pieces of light stuff, about one eighth of an inch thick, glued
together in such a way that the grain of the two pieces crosses at
right angles, and all cracking and warping are thus prevented. The
lids are secured to the bottoms by brass hooks fitting into eyelets.
Such boxes provided with cork do not cost more than fifty-five cents
apiece when bought in quantities. Boxes may be made of stout
pasteboard about one eighth or three sixteenths of an inch thick,
with a rabbet-tongue on the inside. Such boxes are much used in
France and England, and when well and substantially made are most
excellent. They may be obtained for about thirty-five cents apiece
lined with compressed cork.
Cabinets and
Drawers.—Large
collections which
are intended to be
frequently
Fig. 68.—Insect-box for
consulted are best
preservation of
preserved in
collections.
cabinets fitted with
glass-covered
drawers. A great
deal of variety exists in the plans which are
adopted for the display of specimens in
cabinets. Much depends upon the taste and Fig. 67.—Detail drawing
the financial ability of the collector. Large of box, in which the
sums of money may be expended upon tongue, z, is made of
cabinets, but the main thing is to secure the strips of zinc let into a
specimens from dust, mould, and insect groove and fastened as
pests. The point to be observed most at n; g, groove to catch
carefully is so to arrange the drawers that tongue; s, s, top and
they are, like the boxes, practically air-tight. bottom; c, cork.
The writer employs as the standard size for
the drawers in his own collection and in the Carnegie Museum a
drawer which is twenty-two inches long, sixteen inches wide, and
two inches deep (inside measurement). The outside dimensions are:
length, twenty-three inches exclusive of face; breadth, seventeen
inches; height, two and three eighths inches. The covers are glazed
with double-strength glass. They are held upon the bottoms by a
rabbet placed inside of the bottom and nearly reaching the lower
surface of the glass on the cover when closed. The drawers are lined
upon the bottom with cork five sixteenths of an inch thick, and are
papered on the bottom and sides with good linen paper, which does
not easily become discolored. Each drawer is faced with cherry and
has a knob. These drawers are arranged in cabinets built in sections
for convenience in handling. The two lower sections each contain
thirty drawers, the upper section nine. The drawers are arranged in
three perpendicular series and are made interchangeable, so that
any drawer will fit into any place in any one of the cabinets. This is
very necessary, as it admits of the easy rearrangement of
collections. On the sides of each drawer a pocket is cut on the inner
surface, which communicates through an opening in the rabbet with
the interior. The paper lining the inside is perforated over this
opening with a number of small holes. The pocket is kept filled with
naphthaline crystals, the fumes of which pass into the interior and
tend to keep away pests. The accompanying figure gives the details
of construction (Fig. 69). Such drawers can be made at a cost of
about $3.50 apiece, and the cost of a cabinet finished and supplied
with them is about $325, made of cherry, finished in imitation of
mahogany.

Fig. 69.—Detail drawing of drawer


for cabinet: e, e, ends; b, bottom; c,
cork; p, p, paper strips in corners of
lid to exclude dust; g, g, glass of
cover, held in place by top strips, s,
s; m, m, side pieces serving as
rabbets on inside; po, pocket in
ends and sides, sawn out of the
wood; x, opening through the
rabbet into this pocket; y, holes
through the paper lining, p1,
allowing fumes of naphthaline to
enter interior of drawer; f, front; k,
knob; o, lunette cut in edge of the
top piece to enable the lid to be
raised by inserting the fingers.

Some persons prefer to have the bottoms as well as the tops of


the drawers in their cabinets made of glass. In such cases the
specimens are pinned upon narrow strips of wood covered with cork,
securely fastened across the inside of the drawers. This arrangement
enables the under side of specimens to be examined and compared
with as much freedom as the upper side, and without removing
them from the drawers; but the strips are liable at times to become
loosened, and when this happens great havoc is wrought among the
specimens if the drawer is moved carelessly. Besides, there is more
danger of breakage.
Another way of providing a cheap and very sightly lining for the
bottom of an insect-box is illustrated in Fig. 70. A frame of wood like
a slate-frame is provided, and on both sides paper is stretched. To
stretch the paper it ought to be soaked in water before pasting to
the frame; then when it dries it is as tight and smooth as a drum-
head.
The beginner who has not a long purse will do well to preserve his
collections in boxes such as have been described. They can be
obtained quite cheaply and are most excellent. Cabinets are more or
less of a luxury for the amateur, and are only a necessity in the case
of great collections which are constantly being consulted. The boxes
may be arranged upon shelves. Some of the largest and best
collections in the world are preserved in boxes, notably those of the
United States National Museum.
Labeling.—Each specimen should have on the pin below the
specimen a small label giving the date of capture, if known, and the
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy