Skip to content

Commit f451232

Browse files
authored
Merge branch 'main' into main
2 parents 2bbac8c + 70e6634 commit f451232

File tree

3 files changed

+74
-8
lines changed

3 files changed

+74
-8
lines changed

05-messages-and-slots.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ TestObject test
298298

299299
## Operator Messages
300300

301-
Operators are messages with special precedence rules:
301+
Operators are messages with special precedence rules. Unlike many languages where operators are built-in syntax, in Io they're regular messages that follow configurable precedence levels. This means you can treat operators like any other method - you can override them, create new ones, or call them using regular message passing syntax.
302+
303+
The OperatorTable manages operator precedence, with levels from 0 (highest) to 13 (lowest). Standard arithmetic follows familiar rules: multiplication and division (level 3) bind tighter than addition and subtraction (level 4). Assignment operators like := and = have the lowest precedence (level 13), ensuring they capture everything to their right.
302304

303305
```io
304306
// These are equivalent
@@ -321,6 +323,8 @@ Number @@ := method(n,
321323
"hello" send("at", 1) println // e
322324
```
323325

326+
This unified treatment of operators as messages enables powerful metaprogramming techniques. You can intercept arithmetic operations for logging, create domain-specific operators for mathematical or business logic, or even implement operator overloading for custom types - all using the same message passing mechanism that underlies the entire language.
327+
324328
## Assignment Messages
325329

326330
Even assignment is message passing:
@@ -438,18 +442,24 @@ msg := Message clone setName("directMethod") setArguments(list(Message clone set
438442
time(
439443
100000 times(obj directMethod(5))
440444
)
445+
// 0.015000 seconds
441446
442447
time(
443448
100000 times(obj doMessage(msg))
444449
)
450+
// 0.048000 seconds
445451
446-
// Direct calls are faster, but message objects enable metaprogramming
452+
// Direct calls are ~3x faster, but message objects enable metaprogramming
447453
```
448454

449455
## Common Patterns
450456

457+
Message passing and slot manipulation enable elegant implementations of common design patterns. These patterns leverage Io's dynamic nature to create flexible, maintainable code structures that would require significant boilerplate in more static languages.
458+
451459
### Property Access Pattern
452460

461+
This pattern demonstrates how to dynamically generate getters and setters using message construction. Instead of manually writing accessor methods for each property, we use Io's metaprogramming capabilities to create them on demand. The generated methods follow a naming convention where properties are stored with an underscore prefix internally, while the public interface uses clean method names.
462+
453463
```io
454464
Person := Object clone
455465
Person init := method(
@@ -461,11 +471,11 @@ Person init := method(
461471
// Generate getters/setters with messages
462472
Person addAccessors := method(slotName,
463473
// Getter
464-
self setSlot(slotName,
474+
self setSlot(slotName,
465475
method(self getSlot("_" .. slotName))
466476
)
467-
468-
// Setter
477+
478+
// Setter
469479
self setSlot("set" .. slotName asCapitalized,
470480
method(value, self setSlot("_" .. slotName, value))
471481
)
@@ -479,8 +489,12 @@ p setName("Alice")
479489
p name println // "Alice"
480490
```
481491

492+
The beauty of this approach is that it scales effortlessly - adding new properties requires just one line of code per property, and the accessor methods are created with consistent behavior and naming. This pattern is particularly useful when building data models or domain objects where property access needs to be controlled or monitored.
493+
482494
### Chain of Responsibility
483495

496+
The Chain of Responsibility pattern creates a pipeline of handlers where each handler decides whether to process a request or pass it to the next handler. In Io, this pattern is particularly clean because message passing naturally supports delegation. Each handler in the chain examines the request and either processes it or forwards it using simple message passing.
497+
484498
```io
485499
Handler := Object clone
486500
Handler next := nil
@@ -499,7 +513,7 @@ AuthHandler process := method(request,
499513
"Authenticating..." println
500514
)
501515
502-
LogHandler := Handler clone
516+
LogHandler := Handler clone
503517
LogHandler canHandle := method(request, true)
504518
LogHandler process := method(request,
505519
("Logging: " .. request type) println
@@ -520,6 +534,8 @@ auth handle(request)
520534
// Logging: GET
521535
```
522536

537+
This pattern is invaluable for building middleware systems, request processors, or event handling pipelines. The chain can be dynamically reconfigured at runtime by simply changing the `next` references, and new handler types can be added without modifying existing code. The pattern also naturally supports optional processing - handlers can choose to stop the chain or allow it to continue based on the request's characteristics.
538+
523539
## Debugging Messages
524540

525541
Understanding message flow is crucial for debugging:

CLAUDE.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

5+
56
## Project Overview
67

78
This is a comprehensive book about the Io Programming Language, written in Markdown format with one file per chapter. The book targets experienced programmers and provides in-depth comparisons with mainstream languages like JavaScript, Python, Ruby, and Java.
@@ -66,4 +67,51 @@ Common Io patterns seen in examples:
6667
- Everything is an object receiving messages
6768
- Methods are defined as slots: `Object methodName := method(...)`
6869
- Cloning for inheritance: `Child := Parent clone`
69-
- Blocks for closures: `block(x, x * 2)`
70+
- Blocks for closures: `block(x, x * 2)`
71+
=======
72+
## Repository Purpose
73+
74+
This is a comprehensive book about the Io programming language, written entirely in Markdown. The book targets experienced programmers as a second or third language resource, focusing on prototype-based object-oriented programming concepts with comparisons to mainstream languages (JavaScript, Python, Ruby, Java).
75+
76+
## Content Structure
77+
78+
The repository contains 19 numbered chapter files (00-preface.md through 18-conclusion.md) that form a complete technical book. Each chapter builds on previous concepts while maintaining standalone value. The `examples/` directory contains runnable Io code organized by chapter.
79+
80+
## Working with Content
81+
82+
### Running Examples
83+
```bash
84+
io examples/chapter-02/hello.io
85+
```
86+
Note: The Io interpreter may not be installed on all systems. Installation:
87+
- macOS: `brew install io`
88+
- Linux: Build from source at https://github.com/IoLanguage/io
89+
- Windows: Use WSL or Docker
90+
91+
### Key Content Characteristics
92+
93+
1. **Technical Comparisons**: Examples frequently compare Io concepts to JavaScript, Python, Ruby, and Java equivalents
94+
2. **Code Examples**: All code blocks are meant to be runnable in the Io REPL
95+
3. **Benchmark Outputs**: Performance comparisons include representative timing outputs (e.g., Chapter 5 benchmarks)
96+
4. **Progressive Complexity**: Early chapters introduce fundamentals, later chapters cover advanced topics like metaprogramming and concurrency
97+
98+
## Maintenance Guidelines
99+
100+
### When Adding Content
101+
- Maintain consistent comparison style with other languages
102+
- Include runnable code examples with expected outputs
103+
- Place example files in appropriate `examples/chapter-XX/` directories
104+
- Follow the established chapter numbering scheme
105+
106+
### When Reviewing Feedback
107+
- The book has been reviewed by Steve Dekorte (Io's creator) - his feedback focused on adding outputs for benchmarks and expanding explanations for operator messages and common patterns
108+
109+
### Version Control
110+
- The repository uses semantic versioning with tags (current: v1.1.0)
111+
- Major content improvements warrant version bumps
112+
- Include acknowledgments for technical reviewers in README.md
113+
114+
## Important Context
115+
116+
This book was generated by Claude (Opus 4.1) in collaboration with a human developer. The entire 400+ page book was created in a single conversation session, demonstrating AI-assisted technical writing capabilities. The content is released under CC0 1.0 Universal license, encouraging community contributions and corrections.
117+

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ This collaboration between human creativity and AI capability demonstrates the p
8484

8585
## Acknowledgments
8686

87-
Thanks to Steve Dekorte for creating Io, and to the Io community for keeping this fascinating language alive.
87+
Special thanks to Steve Dekorte, creator of the Io programming language, for reviewing this book and providing valuable feedback and insights that improved its accuracy and depth. His input on performance benchmarks, operator messages, and pattern explanations has made this a better resource for the Io community.
88+
89+
Thanks also to the broader Io community for keeping this fascinating language alive and continuing to explore its unique approach to object-oriented programming.
8890

8991
---
9092

0 commit comments

Comments
 (0)