IncludeCPP 3.7.13__py3-none-any.whl → 3.7.14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,90 +1,181 @@
1
1
  """
2
- CSSL Built-in Functions Type Stubs
3
- ===================================
2
+ CSSL Built-in Functions - Complete Type Stubs & Documentation
3
+ ==============================================================
4
4
 
5
- This file provides type hints and documentation for all CSSL built-in functions.
6
- Total: 150+ functions across 15 categories.
5
+ This file provides comprehensive type hints and documentation for all CSSL
6
+ built-in functions and container types. All are available in CSSL scripts
7
+ without imports.
8
+
9
+ Total: 200+ functions + 9 container classes across 19 categories.
7
10
 
8
11
  Categories:
9
- - Output Functions (6)
10
- - Type Conversion (6)
11
- - Type Checking (8)
12
- - String Operations (22)
13
- - Array/List Operations (17)
14
- - Dictionary Operations (13)
15
- - Math Functions (26)
16
- - Date/Time Functions (7)
17
- - File System Functions (23)
18
- - JSON Functions (13)
19
- - Instance Introspection (8)
20
- - Regex Functions (4)
21
- - Hash Functions (3)
22
- - System/Control Functions (15)
23
- - CSSL-Specific Functions (10)
12
+ - Output Functions (7)
13
+ - Type Conversion (6)
14
+ - Type Checking (9)
15
+ - String Operations (30)
16
+ - Array/List Operations (25)
17
+ - Dictionary Operations (15)
18
+ - Math Functions (28)
19
+ - Date/Time Functions (8)
20
+ - File System Functions (23)
21
+ - JSON Functions (12) - json:: namespace
22
+ - Instance Introspection (9) - instance:: namespace
23
+ - Regex Functions (4)
24
+ - Hash Functions (3)
25
+ - System/Control Functions (18)
26
+ - Platform Detection (3)
27
+ - Container Classes (9) - stack<T>, vector<T>, array<T>, map<K,V>, etc.
28
+ - Function Keywords (10)
29
+ - Classes & OOP
30
+ - Special Syntax Reference
31
+
32
+ Container Types with Methods (use lowercase names for quick lookup):
33
+ - stack: stack<T> - LIFO with push(), pop(), peek(), etc.
34
+ - vector: vector<T> - Dynamic array with at(), front(), back(), etc.
35
+ - array: array<T> - Standard array with similar methods
36
+ - map: map<K,V> - Ordered key-value with insert(), find(), erase(), etc.
37
+ - datastruct: datastruct<T> - Universal container for BruteInjection
38
+ - iterator: iterator<T> - Programmable with insert(), fill(), at()
39
+ - shuffled: shuffled<T> - Multi-value returns
40
+ - combo: combo<T> - Filter/search space
41
+ - dataspace: dataspace<T> - SQL-like data storage
42
+
43
+ Type "vector." to see all available methods with documentation.
44
+
45
+ Usage from Python:
46
+ from includecpp import CSSL
47
+
48
+ CSSL.run('''
49
+ stack<string> names;
50
+ names.push("Alice");
51
+ names.push("Bob");
52
+ printl(names.pop()); // "Bob"
53
+ ''')
24
54
  """
25
55
 
26
- from typing import Any, List, Dict, Optional, Callable, Union, Tuple
56
+ from typing import Any, List, Dict, Optional, Callable, Union, Tuple, TypeVar
57
+
58
+ T = TypeVar('T')
27
59
 
28
60
  # =============================================================================
29
61
  # OUTPUT FUNCTIONS
30
62
  # =============================================================================
31
63
 
32
64
  def print(*args: Any, sep: str = " ", end: str = "") -> None:
33
- """Print values without newline.
65
+ """Print values without trailing newline.
66
+
67
+ Outputs text to the console without automatically adding a newline at the end.
68
+ Multiple arguments are joined with the separator.
34
69
 
35
70
  Args:
36
- *args: Values to print
37
- sep: Separator between values (default: space)
38
- end: String appended after last value (default: empty)
71
+ *args: Values to print (any type, automatically converted to string)
72
+ sep: Separator between values (default: single space)
73
+ end: String appended after output (default: empty string)
39
74
 
40
75
  Example:
41
- print("Hello", "World"); // Output: Hello World
76
+ print("Loading");
77
+ print(".");
78
+ print(".");
79
+ printl("Done!");
80
+ // Output: Loading...Done!
81
+
82
+ print("A", "B", "C", sep="-");
83
+ // Output: A-B-C
42
84
  """
43
85
  ...
44
86
 
45
87
  def printl(*args: Any, sep: str = " ") -> None:
46
- """Print values with newline (primary CSSL print function).
88
+ """Print values with trailing newline (primary CSSL output function).
89
+
90
+ The most commonly used output function in CSSL. Prints values followed
91
+ by a newline character. Automatically converts all types to strings.
47
92
 
48
93
  Args:
49
- *args: Values to print
50
- sep: Separator between values (default: space)
94
+ *args: Values to print (any type)
95
+ sep: Separator between multiple values (default: space)
51
96
 
52
97
  Example:
53
- printl("Hello World"); // Output: Hello World\\n
98
+ printl("Hello World");
99
+ // Output: Hello World
100
+
101
+ string name = "Alice";
102
+ int age = 30;
103
+ printl("Name:", name, "Age:", age);
104
+ // Output: Name: Alice Age: 30
105
+
106
+ // String concatenation also works:
107
+ printl("Value: " + 42); // Auto-conversion
108
+ // Output: Value: 42
54
109
  """
55
110
  ...
56
111
 
57
112
  def println(*args: Any, sep: str = " ") -> None:
58
- """Alias for printl. Print values with newline."""
113
+ """Alias for printl(). Print values with newline."""
59
114
  ...
60
115
 
61
116
  def debug(*args: Any) -> None:
62
117
  """Print debug information with [DEBUG] prefix.
63
118
 
119
+ Useful for development and troubleshooting. Output is prefixed
120
+ with [DEBUG] to distinguish from regular output.
121
+
64
122
  Args:
65
123
  *args: Debug values to display
66
124
 
67
125
  Example:
68
- debug("Variable x =", x); // Output: [DEBUG] Variable x = 42
126
+ int x = 42;
127
+ debug("Variable x =", x);
128
+ // Output: [DEBUG] Variable x = 42
129
+
130
+ debug("Entering function processData()");
131
+ debug("items.length =", len(items));
69
132
  """
70
133
  ...
71
134
 
72
135
  def error(*args: Any) -> None:
73
136
  """Print error message with [ERROR] prefix.
74
137
 
138
+ Used for reporting errors. Output is prefixed with [ERROR].
139
+ Does NOT throw an exception - just prints the message.
140
+
75
141
  Args:
76
142
  *args: Error message components
77
143
 
78
144
  Example:
79
145
  error("File not found:", path);
146
+ // Output: [ERROR] File not found: /path/to/file.txt
147
+
148
+ if (!pathexists(file)) {
149
+ error("Cannot read file:", file);
150
+ }
80
151
  """
81
152
  ...
82
153
 
83
154
  def warn(*args: Any) -> None:
84
155
  """Print warning message with [WARN] prefix.
85
156
 
157
+ Used for non-critical issues that should be noted.
158
+ Output is prefixed with [WARN].
159
+
86
160
  Args:
87
161
  *args: Warning message components
162
+
163
+ Example:
164
+ warn("Configuration file missing, using defaults");
165
+ // Output: [WARN] Configuration file missing, using defaults
166
+ """
167
+ ...
168
+
169
+ def log(level: str, *args: Any) -> None:
170
+ """Print message with custom log level prefix.
171
+
172
+ Args:
173
+ level: Log level string (e.g., "INFO", "TRACE", "VERBOSE")
174
+ *args: Message components
175
+
176
+ Example:
177
+ log("INFO", "Server started on port", 8080);
178
+ // Output: [INFO] Server started on port 8080
88
179
  """
89
180
  ...
90
181
 
@@ -92,19 +183,27 @@ def warn(*args: Any) -> None:
92
183
  # TYPE CONVERSION FUNCTIONS
93
184
  # =============================================================================
94
185
 
95
- def int(value: Any) -> int:
186
+ def int(value: Any, base: int = 10) -> int:
96
187
  """Convert value to integer.
97
188
 
189
+ Converts strings, floats, or booleans to integer representation.
190
+ For strings, optionally specify the numeric base.
191
+
98
192
  Args:
99
193
  value: Value to convert (string, float, bool)
194
+ base: Numeric base for string conversion (default: 10)
100
195
 
101
196
  Returns:
102
- Integer representation
197
+ Integer representation of the value
103
198
 
104
199
  Example:
105
- int("42"); // 42
106
- int(3.14); // 3
107
- int(true); // 1
200
+ int("42"); // 42
201
+ int(3.14); // 3 (truncated, not rounded)
202
+ int(3.9); // 3
203
+ int(true); // 1
204
+ int(false); // 0
205
+ int("ff", 16); // 255 (hexadecimal)
206
+ int("1010", 2); // 10 (binary)
108
207
  """
109
208
  ...
110
209
 
@@ -112,35 +211,46 @@ def float(value: Any) -> float:
112
211
  """Convert value to floating-point number.
113
212
 
114
213
  Args:
115
- value: Value to convert
214
+ value: Value to convert (string, int, bool)
116
215
 
117
216
  Returns:
118
- Float representation
217
+ Float representation of the value
119
218
 
120
219
  Example:
121
- float("3.14"); // 3.14
122
- float(42); // 42.0
220
+ float("3.14"); // 3.14
221
+ float(42); // 42.0
222
+ float("1e-5"); // 0.00001 (scientific notation)
223
+ float(true); // 1.0
123
224
  """
124
225
  ...
125
226
 
126
227
  def str(value: Any) -> str:
127
- """Convert value to string.
228
+ """Convert value to string representation.
128
229
 
129
230
  Args:
130
- value: Value to convert
231
+ value: Any value to convert
131
232
 
132
233
  Returns:
133
234
  String representation
134
235
 
135
236
  Example:
136
- str(42); // "42"
137
- str(true); // "True"
237
+ str(42); // "42"
238
+ str(3.14); // "3.14"
239
+ str(true); // "True"
240
+ str([1, 2, 3]); // "[1, 2, 3]"
138
241
  """
139
242
  ...
140
243
 
141
244
  def bool(value: Any) -> bool:
142
245
  """Convert value to boolean.
143
246
 
247
+ Conversion rules:
248
+ - Empty string "", "0", "false", "no", "null", "none" -> false
249
+ - Any other non-empty string -> true
250
+ - 0 -> false, any other number -> true
251
+ - Empty list/dict -> false, non-empty -> true
252
+ - null/None -> false
253
+
144
254
  Args:
145
255
  value: Value to convert
146
256
 
@@ -148,9 +258,13 @@ def bool(value: Any) -> bool:
148
258
  Boolean representation
149
259
 
150
260
  Example:
151
- bool(1); // true
152
- bool(""); // false
153
- bool("text"); // true
261
+ bool(1); // true
262
+ bool(0); // false
263
+ bool(""); // false
264
+ bool("text"); // true
265
+ bool("false"); // false (special case)
266
+ bool([]); // false
267
+ bool([1, 2]); // true
154
268
  """
155
269
  ...
156
270
 
@@ -158,14 +272,17 @@ def list(value: Any = None) -> List[Any]:
158
272
  """Convert value to list or create empty list.
159
273
 
160
274
  Args:
161
- value: Optional value to convert (string, iterable)
275
+ value: Optional value to convert (string splits to chars,
276
+ dict converts to list of tuples)
162
277
 
163
278
  Returns:
164
279
  List representation
165
280
 
166
281
  Example:
167
- list("abc"); // ["a", "b", "c"]
168
- list(); // []
282
+ list(); // []
283
+ list("abc"); // ["a", "b", "c"]
284
+ list((1, 2, 3)); // [1, 2, 3]
285
+ list({"a": 1}); // [("a", 1)]
169
286
  """
170
287
  ...
171
288
 
@@ -173,10 +290,14 @@ def dict(value: Any = None) -> Dict[str, Any]:
173
290
  """Convert value to dictionary or create empty dict.
174
291
 
175
292
  Args:
176
- value: Optional value to convert
293
+ value: Optional value to convert (list of tuples)
177
294
 
178
295
  Returns:
179
296
  Dictionary representation
297
+
298
+ Example:
299
+ dict(); // {}
300
+ dict([("a", 1), ("b", 2)]); // {"a": 1, "b": 2}
180
301
  """
181
302
  ...
182
303
 
@@ -185,59 +306,116 @@ def dict(value: Any = None) -> Dict[str, Any]:
185
306
  # =============================================================================
186
307
 
187
308
  def typeof(value: Any) -> str:
188
- """Get type name of value.
309
+ """Get the type name of a value as string.
189
310
 
190
311
  Args:
191
312
  value: Value to check
192
313
 
193
314
  Returns:
194
- Type name as string
315
+ Type name: "int", "float", "str", "bool", "list", "dict", "null"
195
316
 
196
317
  Example:
197
- typeof(42); // "int"
198
- typeof("hello"); // "str"
199
- typeof([1,2,3]); // "list"
318
+ typeof(42); // "int"
319
+ typeof(3.14); // "float"
320
+ typeof("hello"); // "str"
321
+ typeof(true); // "bool"
322
+ typeof([1, 2, 3]); // "list"
323
+ typeof({"a": 1}); // "dict"
324
+ typeof(null); // "null"
200
325
  """
201
326
  ...
202
327
 
203
328
  def isinstance(value: Any, type_name: str) -> bool:
204
- """Check if value is instance of type.
329
+ """Check if value is instance of specified type.
205
330
 
206
331
  Args:
207
332
  value: Value to check
208
- type_name: Type name string
333
+ type_name: Type name string ("int", "float", "str", "bool",
334
+ "list", "dict", "null")
209
335
 
210
336
  Returns:
211
- True if value is instance of type
337
+ True if value matches the type
338
+
339
+ Example:
340
+ isinstance(42, "int"); // true
341
+ isinstance("hello", "str"); // true
342
+ isinstance([1, 2], "list"); // true
343
+ isinstance(null, "null"); // true
212
344
  """
213
345
  ...
214
346
 
215
347
  def isint(value: Any) -> bool:
216
- """Check if value is an integer."""
348
+ """Check if value is an integer.
349
+
350
+ Note: Returns false for booleans even though bool is subclass of int.
351
+
352
+ Example:
353
+ isint(42); // true
354
+ isint(3.14); // false
355
+ isint("42"); // false
356
+ isint(true); // false
357
+ """
217
358
  ...
218
359
 
219
360
  def isfloat(value: Any) -> bool:
220
- """Check if value is a float."""
361
+ """Check if value is a floating-point number.
362
+
363
+ Example:
364
+ isfloat(3.14); // true
365
+ isfloat(42); // false
366
+ isfloat(42.0); // true
367
+ """
221
368
  ...
222
369
 
223
370
  def isstr(value: Any) -> bool:
224
- """Check if value is a string."""
371
+ """Check if value is a string.
372
+
373
+ Example:
374
+ isstr("hello"); // true
375
+ isstr(42); // false
376
+ isstr(""); // true
377
+ """
225
378
  ...
226
379
 
227
380
  def isbool(value: Any) -> bool:
228
- """Check if value is a boolean."""
381
+ """Check if value is a boolean.
382
+
383
+ Example:
384
+ isbool(true); // true
385
+ isbool(false); // true
386
+ isbool(1); // false
387
+ isbool("true"); // false
388
+ """
229
389
  ...
230
390
 
231
391
  def islist(value: Any) -> bool:
232
- """Check if value is a list/array."""
392
+ """Check if value is a list/array.
393
+
394
+ Example:
395
+ islist([1, 2, 3]); // true
396
+ islist("abc"); // false
397
+ islist([]); // true
398
+ """
233
399
  ...
234
400
 
235
401
  def isdict(value: Any) -> bool:
236
- """Check if value is a dictionary."""
402
+ """Check if value is a dictionary.
403
+
404
+ Example:
405
+ isdict({"a": 1}); // true
406
+ isdict([]); // false
407
+ """
237
408
  ...
238
409
 
239
410
  def isnull(value: Any) -> bool:
240
- """Check if value is null/None."""
411
+ """Check if value is null/None.
412
+
413
+ Example:
414
+ isnull(null); // true
415
+ isnull(None); // true
416
+ isnull(""); // false
417
+ isnull(0); // false
418
+ """
241
419
  ...
242
420
 
243
421
  # =============================================================================
@@ -248,14 +426,17 @@ def len(value: Union[str, List, Dict]) -> int:
248
426
  """Get length of string, list, or dictionary.
249
427
 
250
428
  Args:
251
- value: String, list, or dictionary
429
+ value: String (returns character count), list (element count),
430
+ or dictionary (key count)
252
431
 
253
432
  Returns:
254
- Number of characters/elements/keys
433
+ Number of items
255
434
 
256
435
  Example:
257
- len("hello"); // 5
258
- len([1,2,3]); // 3
436
+ len("hello"); // 5
437
+ len([1, 2, 3]); // 3
438
+ len({"a": 1, "b": 2}); // 2
439
+ len(""); // 0
259
440
  """
260
441
  ...
261
442
 
@@ -263,7 +444,8 @@ def upper(s: str) -> str:
263
444
  """Convert string to uppercase.
264
445
 
265
446
  Example:
266
- upper("hello"); // "HELLO"
447
+ upper("hello"); // "HELLO"
448
+ upper("Hello World"); // "HELLO WORLD"
267
449
  """
268
450
  ...
269
451
 
@@ -271,79 +453,103 @@ def lower(s: str) -> str:
271
453
  """Convert string to lowercase.
272
454
 
273
455
  Example:
274
- lower("HELLO"); // "hello"
456
+ lower("HELLO"); // "hello"
457
+ lower("Hello World"); // "hello world"
275
458
  """
276
459
  ...
277
460
 
278
- def trim(s: str) -> str:
279
- """Remove whitespace from both ends of string.
461
+ def trim(s: str, chars: str = None) -> str:
462
+ """Remove whitespace (or specified chars) from both ends.
463
+
464
+ Args:
465
+ s: String to trim
466
+ chars: Optional specific characters to remove
280
467
 
281
468
  Example:
282
- trim(" hello "); // "hello"
469
+ trim(" hello "); // "hello"
470
+ trim("...hello...", "."); // "hello"
471
+ trim("\\n\\thello\\n"); // "hello"
283
472
  """
284
473
  ...
285
474
 
286
- def ltrim(s: str) -> str:
287
- """Remove whitespace from left side of string."""
475
+ def ltrim(s: str, chars: str = None) -> str:
476
+ """Remove whitespace (or specified chars) from left side only.
477
+
478
+ Example:
479
+ ltrim(" hello "); // "hello "
480
+ """
288
481
  ...
289
482
 
290
- def rtrim(s: str) -> str:
291
- """Remove whitespace from right side of string."""
483
+ def rtrim(s: str, chars: str = None) -> str:
484
+ """Remove whitespace (or specified chars) from right side only.
485
+
486
+ Example:
487
+ rtrim(" hello "); // " hello"
488
+ """
292
489
  ...
293
490
 
294
- def split(s: str, delimiter: str = " ") -> List[str]:
491
+ def split(s: str, delimiter: str = None, maxsplit: int = -1) -> List[str]:
295
492
  """Split string into list by delimiter.
296
493
 
297
494
  Args:
298
495
  s: String to split
299
- delimiter: Split delimiter (default: space)
496
+ delimiter: Split character/string (default: whitespace)
497
+ maxsplit: Maximum number of splits (-1 for unlimited)
300
498
 
301
499
  Returns:
302
500
  List of substrings
303
501
 
304
502
  Example:
305
- split("a,b,c", ","); // ["a", "b", "c"]
503
+ split("a,b,c", ","); // ["a", "b", "c"]
504
+ split("hello world"); // ["hello", "world"]
505
+ split("a-b-c-d", "-", 2); // ["a", "b", "c-d"]
306
506
  """
307
507
  ...
308
508
 
309
- def join(arr: List[str], delimiter: str = "") -> str:
310
- """Join list elements into string.
509
+ def join(delimiter: str, items: List[str]) -> str:
510
+ """Join list elements into string with delimiter.
311
511
 
312
512
  Args:
313
- arr: List of strings
314
- delimiter: Join delimiter
513
+ delimiter: String to place between elements
514
+ items: List of strings to join
315
515
 
316
516
  Returns:
317
517
  Joined string
318
518
 
319
519
  Example:
320
- join(["a", "b", "c"], "-"); // "a-b-c"
520
+ join("-", ["a", "b", "c"]); // "a-b-c"
521
+ join(", ", ["Alice", "Bob"]); // "Alice, Bob"
522
+ join("", ["H", "i"]); // "Hi"
321
523
  """
322
524
  ...
323
525
 
324
- def replace(s: str, old: str, new: str) -> str:
325
- """Replace all occurrences of substring.
526
+ def replace(s: str, old: str, new: str, count: int = -1) -> str:
527
+ """Replace occurrences of substring.
326
528
 
327
529
  Args:
328
530
  s: Original string
329
- old: Substring to replace
531
+ old: Substring to find
330
532
  new: Replacement string
533
+ count: Max replacements (-1 for all)
331
534
 
332
535
  Example:
333
- replace("hello", "l", "x"); // "hexxo"
536
+ replace("hello", "l", "x"); // "hexxo"
537
+ replace("aaa", "a", "b", 2); // "bba"
334
538
  """
335
539
  ...
336
540
 
337
541
  def substr(s: str, start: int, length: int = None) -> str:
338
- """Extract substring.
542
+ """Extract substring by start position and length.
339
543
 
340
544
  Args:
341
545
  s: Original string
342
546
  start: Start index (0-based)
343
- length: Number of characters (optional)
547
+ length: Number of characters (optional, defaults to end)
344
548
 
345
549
  Example:
346
- substr("hello", 1, 3); // "ell"
550
+ substr("hello", 1, 3); // "ell"
551
+ substr("hello", 2); // "llo"
552
+ substr("hello", 0, 1); // "h"
347
553
  """
348
554
  ...
349
555
 
@@ -351,7 +557,9 @@ def contains(s: str, substring: str) -> bool:
351
557
  """Check if string contains substring.
352
558
 
353
559
  Example:
354
- contains("hello", "ell"); // true
560
+ contains("hello world", "world"); // true
561
+ contains("hello", "xyz"); // false
562
+ contains("", ""); // true
355
563
  """
356
564
  ...
357
565
 
@@ -359,7 +567,8 @@ def startswith(s: str, prefix: str) -> bool:
359
567
  """Check if string starts with prefix.
360
568
 
361
569
  Example:
362
- startswith("hello", "he"); // true
570
+ startswith("hello", "he"); // true
571
+ startswith("hello", "lo"); // false
363
572
  """
364
573
  ...
365
574
 
@@ -367,27 +576,32 @@ def endswith(s: str, suffix: str) -> bool:
367
576
  """Check if string ends with suffix.
368
577
 
369
578
  Example:
370
- endswith("hello", "lo"); // true
579
+ endswith("hello", "lo"); // true
580
+ endswith("hello.txt", ".txt"); // true
371
581
  """
372
582
  ...
373
583
 
374
584
  def format(template: str, *args: Any) -> str:
375
- """Format string with placeholders.
585
+ """Format string with {} placeholders.
376
586
 
377
587
  Args:
378
588
  template: String with {} placeholders
379
- *args: Values to insert
589
+ *args: Values to insert (in order)
380
590
 
381
591
  Example:
382
- format("Hello, {}!", "World"); // "Hello, World!"
592
+ format("Hello, {}!", "World"); // "Hello, World!"
593
+ format("{} + {} = {}", 2, 3, 5); // "2 + 3 = 5"
383
594
  """
384
595
  ...
385
596
 
386
597
  def concat(*strings: str) -> str:
387
- """Concatenate multiple strings.
598
+ """Concatenate multiple strings efficiently.
599
+
600
+ More efficient than repeated + for many strings.
388
601
 
389
602
  Example:
390
- concat("a", "b", "c"); // "abc"
603
+ concat("a", "b", "c"); // "abc"
604
+ concat("Hello", " ", "World"); // "Hello World"
391
605
  """
392
606
  ...
393
607
 
@@ -395,15 +609,17 @@ def repeat(s: str, count: int) -> str:
395
609
  """Repeat string n times.
396
610
 
397
611
  Example:
398
- repeat("ab", 3); // "ababab"
612
+ repeat("ab", 3); // "ababab"
613
+ repeat("-", 10); // "----------"
399
614
  """
400
615
  ...
401
616
 
402
617
  def reverse(s: str) -> str:
403
- """Reverse string.
618
+ """Reverse string character order.
404
619
 
405
620
  Example:
406
- reverse("hello"); // "olleh"
621
+ reverse("hello"); // "olleh"
622
+ reverse("12345"); // "54321"
407
623
  """
408
624
  ...
409
625
 
@@ -413,13 +629,15 @@ def indexof(s: str, substring: str, start: int = 0) -> int:
413
629
  Args:
414
630
  s: String to search in
415
631
  substring: Substring to find
416
- start: Start position (default: 0)
632
+ start: Starting position for search (default: 0)
417
633
 
418
634
  Returns:
419
635
  Index of first occurrence, -1 if not found
420
636
 
421
637
  Example:
422
- indexof("hello", "l"); // 2
638
+ indexof("hello", "l"); // 2
639
+ indexof("hello", "l", 3); // 3
640
+ indexof("hello", "xyz"); // -1
423
641
  """
424
642
  ...
425
643
 
@@ -428,30 +646,42 @@ def lastindexof(s: str, substring: str) -> int:
428
646
 
429
647
  Returns:
430
648
  Index of last occurrence, -1 if not found
649
+
650
+ Example:
651
+ lastindexof("hello", "l"); // 3
652
+ lastindexof("abcabc", "bc"); // 4
431
653
  """
432
654
  ...
433
655
 
434
- def padleft(s: str, length: int, char: str = " ") -> str:
435
- """Pad string on left to specified length.
656
+ def padleft(s: str, width: int, char: str = " ") -> str:
657
+ """Pad string on left to specified width.
658
+
659
+ Args:
660
+ s: Original string
661
+ width: Target width
662
+ char: Padding character (default: space)
436
663
 
437
664
  Example:
438
- padleft("42", 5, "0"); // "00042"
665
+ padleft("42", 5, "0"); // "00042"
666
+ padleft("hi", 6); // " hi"
439
667
  """
440
668
  ...
441
669
 
442
- def padright(s: str, length: int, char: str = " ") -> str:
443
- """Pad string on right to specified length.
670
+ def padright(s: str, width: int, char: str = " ") -> str:
671
+ """Pad string on right to specified width.
444
672
 
445
673
  Example:
446
- padright("42", 5, "0"); // "42000"
674
+ padright("42", 5, "0"); // "42000"
675
+ padright("hi", 6); // "hi "
447
676
  """
448
677
  ...
449
678
 
450
679
  def capitalize(s: str) -> str:
451
- """Capitalize first character.
680
+ """Capitalize first character of string.
452
681
 
453
682
  Example:
454
- capitalize("hello"); // "Hello"
683
+ capitalize("hello"); // "Hello"
684
+ capitalize("hELLO"); // "Hello"
455
685
  """
456
686
  ...
457
687
 
@@ -459,7 +689,88 @@ def title(s: str) -> str:
459
689
  """Capitalize first character of each word.
460
690
 
461
691
  Example:
462
- title("hello world"); // "Hello World"
692
+ title("hello world"); // "Hello World"
693
+ title("the quick fox"); // "The Quick Fox"
694
+ """
695
+ ...
696
+
697
+ def swapcase(s: str) -> str:
698
+ """Swap uppercase and lowercase characters.
699
+
700
+ Example:
701
+ swapcase("Hello"); // "hELLO"
702
+ swapcase("PyThOn"); // "pYtHoN"
703
+ """
704
+ ...
705
+
706
+ def center(s: str, width: int, fillchar: str = " ") -> str:
707
+ """Center string within specified width.
708
+
709
+ Example:
710
+ center("hi", 10); // " hi "
711
+ center("hi", 10, "-"); // "----hi----"
712
+ """
713
+ ...
714
+
715
+ def zfill(s: str, width: int) -> str:
716
+ """Pad numeric string with leading zeros.
717
+
718
+ Example:
719
+ zfill("42", 5); // "00042"
720
+ zfill("-42", 5); // "-0042"
721
+ """
722
+ ...
723
+
724
+ def chars(s: str) -> List[str]:
725
+ """Convert string to list of characters.
726
+
727
+ Example:
728
+ chars("hello"); // ["h", "e", "l", "l", "o"]
729
+ """
730
+ ...
731
+
732
+ def ord(c: str) -> int:
733
+ """Get ASCII/Unicode code point of character.
734
+
735
+ Example:
736
+ ord("A"); // 65
737
+ ord("a"); // 97
738
+ ord("0"); // 48
739
+ """
740
+ ...
741
+
742
+ def chr(n: int) -> str:
743
+ """Convert ASCII/Unicode code point to character.
744
+
745
+ Example:
746
+ chr(65); // "A"
747
+ chr(97); // "a"
748
+ chr(8364); // "€"
749
+ """
750
+ ...
751
+
752
+ def isalpha(s: str) -> bool:
753
+ """Check if string contains only alphabetic characters."""
754
+ ...
755
+
756
+ def isdigit(s: str) -> bool:
757
+ """Check if string contains only digits."""
758
+ ...
759
+
760
+ def isalnum(s: str) -> bool:
761
+ """Check if string contains only alphanumeric characters."""
762
+ ...
763
+
764
+ def isspace(s: str) -> bool:
765
+ """Check if string contains only whitespace."""
766
+ ...
767
+
768
+ def sprintf(fmt: str, *args: Any) -> str:
769
+ """C-style format string with % placeholders.
770
+
771
+ Example:
772
+ sprintf("%s: %d", "Count", 42); // "Count: 42"
773
+ sprintf("%.2f", 3.14159); // "3.14"
463
774
  """
464
775
  ...
465
776
 
@@ -467,133 +778,163 @@ def title(s: str) -> str:
467
778
  # ARRAY/LIST OPERATIONS
468
779
  # =============================================================================
469
780
 
470
- def push(arr: List[Any], value: Any) -> List[Any]:
471
- """Add element to end of array.
781
+ def push(arr: List[Any], *values: Any) -> List[Any]:
782
+ """Add one or more elements to end of array.
472
783
 
473
784
  Args:
474
785
  arr: Target array
475
- value: Value to add
786
+ *values: Values to add
476
787
 
477
788
  Returns:
478
789
  Modified array
479
790
 
480
791
  Example:
481
- push([1, 2], 3); // [1, 2, 3]
792
+ stack<int> nums = [1, 2];
793
+ nums = push(nums, 3); // [1, 2, 3]
794
+ nums = push(nums, 4, 5); // [1, 2, 3, 4, 5]
482
795
  """
483
796
  ...
484
797
 
485
- def pop(arr: List[Any]) -> Any:
486
- """Remove and return last element.
798
+ def pop(arr: List[Any], index: int = -1) -> Any:
799
+ """Remove and return element at index (default: last).
800
+
801
+ Args:
802
+ arr: Source array (modified in place)
803
+ index: Index to remove (default: -1 for last element)
487
804
 
488
805
  Returns:
489
806
  Removed element
490
807
 
491
808
  Example:
492
- pop([1, 2, 3]); // 3, array becomes [1, 2]
809
+ stack<int> nums = [1, 2, 3];
810
+ int last = pop(nums); // 3, nums is now [1, 2]
811
+ int first = pop(nums, 0); // 1, nums is now [2]
493
812
  """
494
813
  ...
495
814
 
496
815
  def shift(arr: List[Any]) -> Any:
497
816
  """Remove and return first element.
498
817
 
499
- Returns:
500
- Removed element
818
+ Example:
819
+ stack<string> names = ["Alice", "Bob"];
820
+ string first = shift(names); // "Alice", names is ["Bob"]
501
821
  """
502
822
  ...
503
823
 
504
- def unshift(arr: List[Any], value: Any) -> List[Any]:
505
- """Add element to beginning of array.
824
+ def unshift(arr: List[Any], *values: Any) -> List[Any]:
825
+ """Add elements to beginning of array.
506
826
 
507
- Returns:
508
- Modified array
827
+ Example:
828
+ stack<int> nums = [3, 4];
829
+ nums = unshift(nums, 1, 2); // [1, 2, 3, 4]
509
830
  """
510
831
  ...
511
832
 
512
833
  def slice(arr: List[Any], start: int, end: int = None) -> List[Any]:
513
- """Extract portion of array.
834
+ """Extract portion of array (does not modify original).
514
835
 
515
836
  Args:
516
837
  arr: Source array
517
- start: Start index
838
+ start: Start index (inclusive)
518
839
  end: End index (exclusive, optional)
519
840
 
520
841
  Returns:
521
842
  New array with extracted elements
522
843
 
523
844
  Example:
524
- slice([1, 2, 3, 4], 1, 3); // [2, 3]
845
+ slice([1, 2, 3, 4, 5], 1, 4); // [2, 3, 4]
846
+ slice([1, 2, 3, 4, 5], 2); // [3, 4, 5]
847
+ slice([1, 2, 3, 4, 5], -2); // [4, 5]
525
848
  """
526
849
  ...
527
850
 
528
- def sort(arr: List[Any]) -> List[Any]:
851
+ def sort(arr: List[Any], key: str = None) -> List[Any]:
529
852
  """Sort array in ascending order.
530
853
 
854
+ Args:
855
+ arr: Array to sort
856
+ key: Optional key name for sorting dicts/objects
857
+
531
858
  Returns:
532
859
  Sorted array
860
+
861
+ Example:
862
+ sort([3, 1, 2]); // [1, 2, 3]
863
+ sort(["c", "a", "b"]); // ["a", "b", "c"]
864
+
865
+ // Sort objects by key
866
+ stack<json> users = [{"name": "Bob"}, {"name": "Alice"}];
867
+ sort(users, "name"); // [{name: "Alice"}, {name: "Bob"}]
533
868
  """
534
869
  ...
535
870
 
536
- def rsort(arr: List[Any]) -> List[Any]:
871
+ def rsort(arr: List[Any], key: str = None) -> List[Any]:
537
872
  """Sort array in descending order.
538
873
 
539
- Returns:
540
- Reverse sorted array
874
+ Example:
875
+ rsort([1, 3, 2]); // [3, 2, 1]
541
876
  """
542
877
  ...
543
878
 
544
879
  def unique(arr: List[Any]) -> List[Any]:
545
- """Remove duplicate elements.
546
-
547
- Returns:
548
- Array with unique elements only
880
+ """Remove duplicate elements (preserves first occurrence order).
549
881
 
550
882
  Example:
551
- unique([1, 2, 2, 3]); // [1, 2, 3]
883
+ unique([1, 2, 2, 3, 1]); // [1, 2, 3]
884
+ unique(["a", "b", "a"]); // ["a", "b"]
552
885
  """
553
886
  ...
554
887
 
555
- def flatten(arr: List[Any]) -> List[Any]:
556
- """Flatten nested arrays.
888
+ def flatten(arr: List[Any], depth: int = 1) -> List[Any]:
889
+ """Flatten nested arrays to specified depth.
890
+
891
+ Args:
892
+ arr: Nested array
893
+ depth: How many levels to flatten (default: 1)
557
894
 
558
895
  Example:
559
- flatten([[1, 2], [3, 4]]); // [1, 2, 3, 4]
896
+ flatten([[1, 2], [3, 4]]); // [1, 2, 3, 4]
897
+ flatten([[[1]], [[2]]]); // [[1], [2]]
898
+ flatten([[[1]], [[2]]], 2); // [1, 2]
560
899
  """
561
900
  ...
562
901
 
563
902
  def filter(arr: List[Any], predicate: Callable[[Any], bool]) -> List[Any]:
564
903
  """Filter array by predicate function.
565
904
 
905
+ Note: In CSSL, use inline conditions or lambda-like syntax.
906
+
566
907
  Args:
567
908
  arr: Source array
568
909
  predicate: Function returning true for elements to keep
569
910
 
570
911
  Returns:
571
- Filtered array
912
+ Filtered array (only elements where predicate returned true)
572
913
  """
573
914
  ...
574
915
 
575
916
  def map(arr: List[Any], func: Callable[[Any], Any]) -> List[Any]:
576
- """Apply function to each element.
917
+ """Apply transformation function to each element.
577
918
 
578
919
  Args:
579
920
  arr: Source array
580
921
  func: Transformation function
581
922
 
582
923
  Returns:
583
- Transformed array
924
+ Array of transformed elements
584
925
  """
585
926
  ...
586
927
 
587
928
  def reduce(arr: List[Any], func: Callable[[Any, Any], Any], initial: Any = None) -> Any:
588
- """Reduce array to single value.
929
+ """Reduce array to single value using accumulator function.
589
930
 
590
931
  Args:
591
932
  arr: Source array
592
- func: Reducer function (accumulator, current) -> result
593
- initial: Initial accumulator value
933
+ func: Reducer (accumulator, current) -> result
934
+ initial: Starting accumulator value
594
935
 
595
936
  Returns:
596
- Reduced value
937
+ Final accumulated value
597
938
  """
598
939
  ...
599
940
 
@@ -601,33 +942,146 @@ def find(arr: List[Any], predicate: Callable[[Any], bool]) -> Optional[Any]:
601
942
  """Find first element matching predicate.
602
943
 
603
944
  Returns:
604
- First matching element or null
945
+ First matching element or null if none found
605
946
  """
606
947
  ...
607
948
 
608
949
  def findindex(arr: List[Any], predicate: Callable[[Any], bool]) -> int:
609
- """Find index of first matching element.
950
+ """Find index of first element matching predicate.
951
+
952
+ Returns:
953
+ Index of first match, -1 if not found
954
+ """
955
+ ...
956
+
957
+ def every(arr: List[Any], predicate: Callable[[Any], bool]) -> bool:
958
+ """Check if ALL elements satisfy predicate.
959
+
960
+ Returns:
961
+ True if predicate returns true for all elements
962
+ """
963
+ ...
964
+
965
+ def some(arr: List[Any], predicate: Callable[[Any], bool]) -> bool:
966
+ """Check if ANY element satisfies predicate.
610
967
 
611
968
  Returns:
612
- Index or -1 if not found
969
+ True if predicate returns true for at least one element
613
970
  """
614
971
  ...
615
972
 
616
973
  def range(start_or_stop: int, stop: int = None, step: int = 1) -> List[int]:
617
- """Generate range of integers.
974
+ """Generate list of integers in range.
618
975
 
619
976
  Args:
620
- start_or_stop: Start value (or stop if only arg)
621
- stop: Stop value (exclusive)
622
- step: Step increment
977
+ start_or_stop: If only arg, this is stop (start=0). Otherwise start.
978
+ stop: End value (exclusive)
979
+ step: Increment between values (default: 1)
623
980
 
624
981
  Returns:
625
982
  List of integers
626
983
 
627
984
  Example:
628
- range(5); // [0, 1, 2, 3, 4]
629
- range(1, 5); // [1, 2, 3, 4]
630
- range(0, 10, 2); // [0, 2, 4, 6, 8]
985
+ range(5); // [0, 1, 2, 3, 4]
986
+ range(1, 5); // [1, 2, 3, 4]
987
+ range(0, 10, 2); // [0, 2, 4, 6, 8]
988
+ range(10, 0, -1); // [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
989
+ """
990
+ ...
991
+
992
+ def enumerate(arr: List[Any], start: int = 0) -> List[Tuple[int, Any]]:
993
+ """Return list of (index, value) pairs.
994
+
995
+ Args:
996
+ arr: Array to enumerate
997
+ start: Starting index number (default: 0)
998
+
999
+ Example:
1000
+ enumerate(["a", "b", "c"]); // [(0, "a"), (1, "b"), (2, "c")]
1001
+ enumerate(["a", "b"], 1); // [(1, "a"), (2, "b")]
1002
+ """
1003
+ ...
1004
+
1005
+ def zip(*arrays: List[Any]) -> List[Tuple[Any, ...]]:
1006
+ """Combine multiple arrays into array of tuples.
1007
+
1008
+ Example:
1009
+ zip([1, 2], ["a", "b"]); // [(1, "a"), (2, "b")]
1010
+ """
1011
+ ...
1012
+
1013
+ def reversed(arr: List[Any]) -> List[Any]:
1014
+ """Return reversed copy of array.
1015
+
1016
+ Example:
1017
+ reversed([1, 2, 3]); // [3, 2, 1]
1018
+ """
1019
+ ...
1020
+
1021
+ def count(collection: Union[List, str], item: Any) -> int:
1022
+ """Count occurrences of item in list or string.
1023
+
1024
+ Example:
1025
+ count([1, 2, 2, 3, 2], 2); // 3
1026
+ count("hello", "l"); // 2
1027
+ """
1028
+ ...
1029
+
1030
+ def first(arr: List[Any], default: Any = None) -> Any:
1031
+ """Get first element or default if empty.
1032
+
1033
+ Example:
1034
+ first([1, 2, 3]); // 1
1035
+ first([], "none"); // "none"
1036
+ """
1037
+ ...
1038
+
1039
+ def last(arr: List[Any], default: Any = None) -> Any:
1040
+ """Get last element or default if empty.
1041
+
1042
+ Example:
1043
+ last([1, 2, 3]); // 3
1044
+ last([], "none"); // "none"
1045
+ """
1046
+ ...
1047
+
1048
+ def take(arr: List[Any], n: int) -> List[Any]:
1049
+ """Take first n elements.
1050
+
1051
+ Example:
1052
+ take([1, 2, 3, 4, 5], 3); // [1, 2, 3]
1053
+ """
1054
+ ...
1055
+
1056
+ def drop(arr: List[Any], n: int) -> List[Any]:
1057
+ """Drop first n elements, return rest.
1058
+
1059
+ Example:
1060
+ drop([1, 2, 3, 4, 5], 2); // [3, 4, 5]
1061
+ """
1062
+ ...
1063
+
1064
+ def chunk(arr: List[Any], size: int) -> List[List[Any]]:
1065
+ """Split array into chunks of specified size.
1066
+
1067
+ Example:
1068
+ chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
1069
+ """
1070
+ ...
1071
+
1072
+ def shuffle(arr: List[Any]) -> List[Any]:
1073
+ """Return randomly shuffled copy of array.
1074
+
1075
+ Example:
1076
+ shuffle([1, 2, 3, 4]); // [3, 1, 4, 2] (random)
1077
+ """
1078
+ ...
1079
+
1080
+ def sample(arr: List[Any], k: int) -> List[Any]:
1081
+ """Return k random elements from array (without replacement).
1082
+
1083
+ Example:
1084
+ sample([1, 2, 3, 4, 5], 3); // [2, 5, 1] (random 3 elements)
631
1085
  """
632
1086
  ...
633
1087
 
@@ -636,26 +1090,26 @@ def range(start_or_stop: int, stop: int = None, step: int = 1) -> List[int]:
636
1090
  # =============================================================================
637
1091
 
638
1092
  def keys(d: Dict[str, Any]) -> List[str]:
639
- """Get all dictionary keys.
1093
+ """Get all keys from dictionary.
640
1094
 
641
- Returns:
642
- List of keys
1095
+ Example:
1096
+ keys({"a": 1, "b": 2}); // ["a", "b"]
643
1097
  """
644
1098
  ...
645
1099
 
646
1100
  def values(d: Dict[str, Any]) -> List[Any]:
647
- """Get all dictionary values.
1101
+ """Get all values from dictionary.
648
1102
 
649
- Returns:
650
- List of values
1103
+ Example:
1104
+ values({"a": 1, "b": 2}); // [1, 2]
651
1105
  """
652
1106
  ...
653
1107
 
654
1108
  def items(d: Dict[str, Any]) -> List[Tuple[str, Any]]:
655
- """Get all key-value pairs.
1109
+ """Get all key-value pairs as list of tuples.
656
1110
 
657
- Returns:
658
- List of (key, value) tuples
1111
+ Example:
1112
+ items({"a": 1, "b": 2}); // [("a", 1), ("b", 2)]
659
1113
  """
660
1114
  ...
661
1115
 
@@ -663,7 +1117,8 @@ def haskey(d: Dict[str, Any], key: str) -> bool:
663
1117
  """Check if dictionary has key.
664
1118
 
665
1119
  Example:
666
- haskey({"a": 1}, "a"); // true
1120
+ haskey({"a": 1}, "a"); // true
1121
+ haskey({"a": 1}, "b"); // false
667
1122
  """
668
1123
  ...
669
1124
 
@@ -673,143 +1128,325 @@ def getkey(d: Dict[str, Any], key: str, default: Any = None) -> Any:
673
1128
  Args:
674
1129
  d: Dictionary
675
1130
  key: Key to look up
676
- default: Default value if key not found
1131
+ default: Value to return if key not found
677
1132
 
678
- Returns:
679
- Value or default
1133
+ Example:
1134
+ getkey({"a": 1}, "a", 0); // 1
1135
+ getkey({"a": 1}, "b", 0); // 0
1136
+ getkey({"a": 1}, "b"); // null
680
1137
  """
681
1138
  ...
682
1139
 
683
1140
  def setkey(d: Dict[str, Any], key: str, value: Any) -> Dict[str, Any]:
684
- """Set key-value pair in dictionary.
1141
+ """Set key-value pair in dictionary (returns modified copy).
685
1142
 
686
- Returns:
687
- Modified dictionary
1143
+ Example:
1144
+ json obj = {"a": 1};
1145
+ obj = setkey(obj, "b", 2); // {"a": 1, "b": 2}
688
1146
  """
689
1147
  ...
690
1148
 
691
1149
  def delkey(d: Dict[str, Any], key: str) -> Dict[str, Any]:
692
- """Delete key from dictionary.
1150
+ """Delete key from dictionary (returns modified copy).
693
1151
 
694
- Returns:
695
- Modified dictionary
1152
+ Example:
1153
+ json obj = {"a": 1, "b": 2};
1154
+ obj = delkey(obj, "a"); // {"b": 2}
696
1155
  """
697
1156
  ...
698
1157
 
699
1158
  def merge(*dicts: Dict[str, Any]) -> Dict[str, Any]:
700
- """Merge multiple dictionaries.
1159
+ """Merge multiple dictionaries (later values override).
701
1160
 
702
- Returns:
703
- Merged dictionary (later values override earlier)
1161
+ Example:
1162
+ merge({"a": 1}, {"b": 2}, {"a": 3}); // {"a": 3, "b": 2}
704
1163
  """
705
1164
  ...
706
1165
 
707
- # =============================================================================
708
- # MATH FUNCTIONS
709
- # =============================================================================
1166
+ def update(d: Dict[str, Any], other: Dict[str, Any]) -> Dict[str, Any]:
1167
+ """Update dictionary with another (returns new dict).
710
1168
 
711
- def abs(x: Union[int, float]) -> Union[int, float]:
712
- """Absolute value."""
1169
+ Example:
1170
+ update({"a": 1}, {"b": 2}); // {"a": 1, "b": 2}
1171
+ """
713
1172
  ...
714
1173
 
715
- def min(*values: Union[int, float]) -> Union[int, float]:
716
- """Minimum value."""
717
- ...
1174
+ def fromkeys(keys: List[str], value: Any = None) -> Dict[str, Any]:
1175
+ """Create dictionary from list of keys with default value.
718
1176
 
719
- def max(*values: Union[int, float]) -> Union[int, float]:
720
- """Maximum value."""
1177
+ Example:
1178
+ fromkeys(["a", "b", "c"], 0); // {"a": 0, "b": 0, "c": 0}
1179
+ """
721
1180
  ...
722
1181
 
723
- def sum(arr: List[Union[int, float]]) -> Union[int, float]:
724
- """Sum of array elements."""
725
- ...
1182
+ def invert(d: Dict[str, Any]) -> Dict[Any, str]:
1183
+ """Swap keys and values (values must be hashable).
726
1184
 
727
- def avg(arr: List[Union[int, float]]) -> float:
728
- """Average of array elements."""
1185
+ Example:
1186
+ invert({"a": 1, "b": 2}); // {1: "a", 2: "b"}
1187
+ """
729
1188
  ...
730
1189
 
731
- def round(x: float, decimals: int = 0) -> float:
732
- """Round to specified decimal places."""
733
- ...
1190
+ def pick(d: Dict[str, Any], *keys: str) -> Dict[str, Any]:
1191
+ """Pick only specified keys from dictionary.
734
1192
 
735
- def floor(x: float) -> int:
736
- """Round down to nearest integer."""
1193
+ Example:
1194
+ pick({"a": 1, "b": 2, "c": 3}, "a", "c"); // {"a": 1, "c": 3}
1195
+ """
737
1196
  ...
738
1197
 
739
- def ceil(x: float) -> int:
740
- """Round up to nearest integer."""
741
- ...
1198
+ def omit(d: Dict[str, Any], *keys: str) -> Dict[str, Any]:
1199
+ """Omit specified keys from dictionary.
742
1200
 
743
- def pow(base: float, exponent: float) -> float:
744
- """Raise base to power."""
1201
+ Example:
1202
+ omit({"a": 1, "b": 2, "c": 3}, "b"); // {"a": 1, "c": 3}
1203
+ """
745
1204
  ...
746
1205
 
747
- def sqrt(x: float) -> float:
748
- """Square root."""
749
- ...
1206
+ def groupby(arr: List[Any], key: str) -> Dict[Any, List[Any]]:
1207
+ """Group list of dicts/objects by key value.
750
1208
 
751
- def random() -> float:
752
- """Random float between 0 and 1."""
1209
+ Example:
1210
+ stack<json> users = [
1211
+ {"name": "Alice", "role": "admin"},
1212
+ {"name": "Bob", "role": "user"},
1213
+ {"name": "Carol", "role": "admin"}
1214
+ ];
1215
+ groupby(users, "role");
1216
+ // {"admin": [{Alice}, {Carol}], "user": [{Bob}]}
1217
+ """
753
1218
  ...
754
1219
 
755
- def randint(min_val: int, max_val: int) -> int:
756
- """Random integer in range [min, max]."""
757
- ...
1220
+ # =============================================================================
1221
+ # MATH FUNCTIONS
1222
+ # =============================================================================
758
1223
 
759
- def sin(x: float) -> float:
760
- """Sine (radians)."""
761
- ...
1224
+ def abs(x: Union[int, float]) -> Union[int, float]:
1225
+ """Absolute value.
762
1226
 
763
- def cos(x: float) -> float:
764
- """Cosine (radians)."""
1227
+ Example:
1228
+ abs(-5); // 5
1229
+ abs(3.14); // 3.14
1230
+ abs(-3.14); // 3.14
1231
+ """
765
1232
  ...
766
1233
 
767
- def tan(x: float) -> float:
768
- """Tangent (radians)."""
769
- ...
1234
+ def min(*values: Union[int, float, List]) -> Union[int, float]:
1235
+ """Minimum value from arguments or list.
770
1236
 
771
- def asin(x: float) -> float:
772
- """Arc sine (returns radians)."""
1237
+ Example:
1238
+ min(3, 1, 2); // 1
1239
+ min([3, 1, 2]); // 1
1240
+ """
773
1241
  ...
774
1242
 
775
- def acos(x: float) -> float:
776
- """Arc cosine (returns radians)."""
1243
+ def max(*values: Union[int, float, List]) -> Union[int, float]:
1244
+ """Maximum value from arguments or list.
1245
+
1246
+ Example:
1247
+ max(3, 1, 2); // 3
1248
+ max([3, 1, 2]); // 3
1249
+ """
1250
+ ...
1251
+
1252
+ def sum(arr: List[Union[int, float]], start: Union[int, float] = 0) -> Union[int, float]:
1253
+ """Sum of list elements.
1254
+
1255
+ Args:
1256
+ arr: List of numbers
1257
+ start: Starting value to add to sum (default: 0)
1258
+
1259
+ Example:
1260
+ sum([1, 2, 3, 4]); // 10
1261
+ sum([1, 2, 3], 10); // 16
1262
+ """
1263
+ ...
1264
+
1265
+ def avg(arr: List[Union[int, float]]) -> float:
1266
+ """Average (mean) of list elements.
1267
+
1268
+ Example:
1269
+ avg([1, 2, 3, 4, 5]); // 3.0
1270
+ avg([10, 20]); // 15.0
1271
+ """
1272
+ ...
1273
+
1274
+ def round(x: float, decimals: int = 0) -> float:
1275
+ """Round to specified decimal places.
1276
+
1277
+ Example:
1278
+ round(3.14159, 2); // 3.14
1279
+ round(3.5); // 4.0
1280
+ round(2.5); // 2.0 (banker's rounding)
1281
+ """
1282
+ ...
1283
+
1284
+ def floor(x: float) -> int:
1285
+ """Round down to nearest integer.
1286
+
1287
+ Example:
1288
+ floor(3.9); // 3
1289
+ floor(3.1); // 3
1290
+ floor(-3.1); // -4
1291
+ """
1292
+ ...
1293
+
1294
+ def ceil(x: float) -> int:
1295
+ """Round up to nearest integer.
1296
+
1297
+ Example:
1298
+ ceil(3.1); // 4
1299
+ ceil(3.9); // 4
1300
+ ceil(-3.9); // -3
1301
+ """
1302
+ ...
1303
+
1304
+ def pow(base: float, exponent: float) -> float:
1305
+ """Raise base to power.
1306
+
1307
+ Example:
1308
+ pow(2, 3); // 8.0
1309
+ pow(9, 0.5); // 3.0 (square root)
1310
+ pow(2, -1); // 0.5
1311
+ """
1312
+ ...
1313
+
1314
+ def sqrt(x: float) -> float:
1315
+ """Square root.
1316
+
1317
+ Example:
1318
+ sqrt(16); // 4.0
1319
+ sqrt(2); // 1.41421...
1320
+ """
1321
+ ...
1322
+
1323
+ def mod(a: int, b: int) -> int:
1324
+ """Modulo (remainder after division).
1325
+
1326
+ Example:
1327
+ mod(7, 3); // 1
1328
+ mod(10, 5); // 0
1329
+ """
1330
+ ...
1331
+
1332
+ def random() -> float:
1333
+ """Random float between 0.0 (inclusive) and 1.0 (exclusive).
1334
+
1335
+ Example:
1336
+ float r = random(); // 0.0 <= r < 1.0
1337
+ """
1338
+ ...
1339
+
1340
+ def randint(min_val: int, max_val: int) -> int:
1341
+ """Random integer in inclusive range [min, max].
1342
+
1343
+ Example:
1344
+ randint(1, 6); // 1, 2, 3, 4, 5, or 6
1345
+ randint(0, 100); // 0 to 100 inclusive
1346
+ """
1347
+ ...
1348
+
1349
+ def sin(x: float) -> float:
1350
+ """Sine (argument in radians).
1351
+
1352
+ Example:
1353
+ sin(0); // 0.0
1354
+ sin(pi() / 2); // 1.0
1355
+ """
1356
+ ...
1357
+
1358
+ def cos(x: float) -> float:
1359
+ """Cosine (argument in radians).
1360
+
1361
+ Example:
1362
+ cos(0); // 1.0
1363
+ cos(pi()); // -1.0
1364
+ """
1365
+ ...
1366
+
1367
+ def tan(x: float) -> float:
1368
+ """Tangent (argument in radians)."""
1369
+ ...
1370
+
1371
+ def asin(x: float) -> float:
1372
+ """Arc sine (result in radians)."""
1373
+ ...
1374
+
1375
+ def acos(x: float) -> float:
1376
+ """Arc cosine (result in radians)."""
777
1377
  ...
778
1378
 
779
1379
  def atan(x: float) -> float:
780
- """Arc tangent (returns radians)."""
1380
+ """Arc tangent (result in radians)."""
781
1381
  ...
782
1382
 
783
1383
  def atan2(y: float, x: float) -> float:
784
- """Two-argument arc tangent."""
1384
+ """Two-argument arc tangent (result in radians).
1385
+
1386
+ Returns angle from positive x-axis to point (x, y).
1387
+ """
785
1388
  ...
786
1389
 
787
1390
  def log(x: float, base: float = None) -> float:
788
- """Natural logarithm (or log with specified base)."""
1391
+ """Logarithm. Natural log if base not specified.
1392
+
1393
+ Example:
1394
+ log(e()); // 1.0 (natural log)
1395
+ log(100, 10); // 2.0 (log base 10)
1396
+ log(8, 2); // 3.0 (log base 2)
1397
+ """
789
1398
  ...
790
1399
 
791
1400
  def log10(x: float) -> float:
792
- """Base-10 logarithm."""
1401
+ """Base-10 logarithm.
1402
+
1403
+ Example:
1404
+ log10(100); // 2.0
1405
+ log10(1000); // 3.0
1406
+ """
793
1407
  ...
794
1408
 
795
1409
  def exp(x: float) -> float:
796
- """Exponential function (e^x)."""
1410
+ """Exponential function (e^x).
1411
+
1412
+ Example:
1413
+ exp(1); // 2.71828...
1414
+ exp(0); // 1.0
1415
+ """
797
1416
  ...
798
1417
 
799
1418
  def pi() -> float:
800
- """Mathematical constant pi (3.14159...)."""
1419
+ """Mathematical constant pi (3.14159265358979...).
1420
+
1421
+ Example:
1422
+ float circumference = 2 * pi() * radius;
1423
+ """
801
1424
  ...
802
1425
 
803
1426
  def e() -> float:
804
- """Mathematical constant e (2.71828...)."""
1427
+ """Mathematical constant e (2.71828182845904...).
1428
+
1429
+ Example:
1430
+ float growth = e() ** rate;
1431
+ """
805
1432
  ...
806
1433
 
807
1434
  def radians(degrees: float) -> float:
808
- """Convert degrees to radians."""
1435
+ """Convert degrees to radians.
1436
+
1437
+ Example:
1438
+ radians(180); // 3.14159... (pi)
1439
+ radians(90); // 1.5708... (pi/2)
1440
+ """
809
1441
  ...
810
1442
 
811
1443
  def degrees(radians: float) -> float:
812
- """Convert radians to degrees."""
1444
+ """Convert radians to degrees.
1445
+
1446
+ Example:
1447
+ degrees(pi()); // 180.0
1448
+ degrees(pi() / 2); // 90.0
1449
+ """
813
1450
  ...
814
1451
 
815
1452
  # =============================================================================
@@ -817,18 +1454,39 @@ def degrees(radians: float) -> float:
817
1454
  # =============================================================================
818
1455
 
819
1456
  def now() -> float:
820
- """Current timestamp as float (seconds since epoch)."""
1457
+ """Current timestamp as float (seconds since Unix epoch).
1458
+
1459
+ Example:
1460
+ float ts = now(); // 1703956800.123456
1461
+ """
821
1462
  ...
822
1463
 
823
1464
  def timestamp() -> int:
824
- """Current timestamp as integer."""
1465
+ """Current timestamp as integer (seconds since Unix epoch).
1466
+
1467
+ Example:
1468
+ int ts = timestamp(); // 1703956800
1469
+ """
825
1470
  ...
826
1471
 
827
1472
  def sleep(seconds: float) -> None:
828
1473
  """Pause execution for specified seconds.
829
1474
 
1475
+ Args:
1476
+ seconds: Duration to sleep (can be fractional)
1477
+
830
1478
  Example:
831
- sleep(1.5); // Wait 1.5 seconds
1479
+ sleep(1.5); // Wait 1.5 seconds
1480
+ sleep(0.1); // Wait 100 milliseconds
1481
+ """
1482
+ ...
1483
+
1484
+ def delay(ms: float) -> None:
1485
+ """Pause execution for specified milliseconds.
1486
+
1487
+ Example:
1488
+ delay(500); // Wait 500 milliseconds
1489
+ delay(1000); // Wait 1 second
832
1490
  """
833
1491
  ...
834
1492
 
@@ -838,9 +1496,18 @@ def date(format: str = "%Y-%m-%d") -> str:
838
1496
  Args:
839
1497
  format: strftime format string
840
1498
 
1499
+ Common format codes:
1500
+ %Y - 4-digit year
1501
+ %m - 2-digit month
1502
+ %d - 2-digit day
1503
+ %H - Hour (24-hour)
1504
+ %M - Minute
1505
+ %S - Second
1506
+
841
1507
  Example:
842
- date(); // "2025-12-30"
843
- date("%d/%m/%Y"); // "30/12/2025"
1508
+ date(); // "2025-12-30"
1509
+ date("%d/%m/%Y"); // "30/12/2025"
1510
+ date("%Y%m%d"); // "20251230"
844
1511
  """
845
1512
  ...
846
1513
 
@@ -848,12 +1515,18 @@ def time(format: str = "%H:%M:%S") -> str:
848
1515
  """Current time as formatted string.
849
1516
 
850
1517
  Example:
851
- time(); // "14:30:45"
1518
+ time(); // "14:30:45"
1519
+ time("%H:%M"); // "14:30"
1520
+ time("%I:%M %p"); // "02:30 PM"
852
1521
  """
853
1522
  ...
854
1523
 
855
1524
  def datetime(format: str = "%Y-%m-%d %H:%M:%S") -> str:
856
- """Current date and time as formatted string."""
1525
+ """Current date and time as formatted string.
1526
+
1527
+ Example:
1528
+ datetime(); // "2025-12-30 14:30:45"
1529
+ """
857
1530
  ...
858
1531
 
859
1532
  def strftime(format: str, timestamp: float = None) -> str:
@@ -861,7 +1534,10 @@ def strftime(format: str, timestamp: float = None) -> str:
861
1534
 
862
1535
  Args:
863
1536
  format: strftime format string
864
- timestamp: Unix timestamp (default: now)
1537
+ timestamp: Unix timestamp (default: current time)
1538
+
1539
+ Example:
1540
+ strftime("%Y-%m-%d", 0); // "1970-01-01"
865
1541
  """
866
1542
  ...
867
1543
 
@@ -870,17 +1546,18 @@ def strftime(format: str, timestamp: float = None) -> str:
870
1546
  # =============================================================================
871
1547
 
872
1548
  def read(path: str, encoding: str = "utf-8") -> str:
873
- """Read entire file content.
1549
+ """Read entire file content as string.
874
1550
 
875
1551
  Args:
876
- path: File path
1552
+ path: File path (absolute or relative)
877
1553
  encoding: Character encoding (default: utf-8)
878
1554
 
879
1555
  Returns:
880
1556
  File content as string
881
1557
 
882
1558
  Example:
883
- string content = read("/path/to/file.txt");
1559
+ string content = read("config.txt");
1560
+ string data = read("/path/to/file.txt");
884
1561
  """
885
1562
  ...
886
1563
 
@@ -888,19 +1565,20 @@ def readline(line: int, path: str) -> str:
888
1565
  """Read specific line from file (1-indexed).
889
1566
 
890
1567
  Args:
891
- line: Line number (1-based)
1568
+ line: Line number (1-based, first line is 1)
892
1569
  path: File path
893
1570
 
894
1571
  Returns:
895
- Line content
1572
+ Content of that line (without newline)
896
1573
 
897
1574
  Example:
898
1575
  string line5 = readline(5, "file.txt");
1576
+ string first = readline(1, "config.ini");
899
1577
  """
900
1578
  ...
901
1579
 
902
1580
  def write(path: str, content: str) -> int:
903
- """Write content to file (overwrites).
1581
+ """Write content to file (overwrites existing).
904
1582
 
905
1583
  Args:
906
1584
  path: File path
@@ -908,91 +1586,171 @@ def write(path: str, content: str) -> int:
908
1586
 
909
1587
  Returns:
910
1588
  Number of characters written
1589
+
1590
+ Example:
1591
+ write("output.txt", "Hello World");
1592
+ write("data.json", json::stringify(myData));
911
1593
  """
912
1594
  ...
913
1595
 
914
1596
  def writeline(line: int, content: str, path: str) -> bool:
915
- """Write/replace specific line in file.
1597
+ """Write/replace specific line in file (1-indexed).
1598
+
1599
+ Creates lines if file is shorter than specified line number.
916
1600
 
917
1601
  Args:
918
1602
  line: Line number (1-based)
919
- content: New line content
1603
+ content: New content for that line
920
1604
  path: File path
921
1605
 
922
1606
  Returns:
923
1607
  Success status
1608
+
1609
+ Example:
1610
+ writeline(3, "New third line", "file.txt");
924
1611
  """
925
1612
  ...
926
1613
 
927
1614
  def appendfile(path: str, content: str) -> int:
928
- """Append content to file.
1615
+ """Append content to end of file.
929
1616
 
930
1617
  Returns:
931
1618
  Number of characters written
1619
+
1620
+ Example:
1621
+ appendfile("log.txt", "New log entry\\n");
932
1622
  """
933
1623
  ...
934
1624
 
935
1625
  def readlines(path: str) -> List[str]:
936
- """Read all lines from file.
1626
+ """Read all lines from file as list.
937
1627
 
938
1628
  Returns:
939
- List of lines
1629
+ List of lines (including newline characters)
1630
+
1631
+ Example:
1632
+ stack<string> lines = readlines("file.txt");
1633
+ foreach (line in lines) {
1634
+ printl(trim(line));
1635
+ }
940
1636
  """
941
1637
  ...
942
1638
 
943
1639
  def pathexists(path: str) -> bool:
944
- """Check if path exists (file or directory)."""
1640
+ """Check if path exists (file or directory).
1641
+
1642
+ Example:
1643
+ if (pathexists("config.json")) {
1644
+ json config = json::read("config.json");
1645
+ }
1646
+ """
945
1647
  ...
946
1648
 
947
1649
  def isfile(path: str) -> bool:
948
- """Check if path is a file."""
1650
+ """Check if path is a file (not directory).
1651
+
1652
+ Example:
1653
+ if (isfile("data.txt")) {
1654
+ string content = read("data.txt");
1655
+ }
1656
+ """
949
1657
  ...
950
1658
 
951
1659
  def isdir(path: str) -> bool:
952
- """Check if path is a directory."""
1660
+ """Check if path is a directory.
1661
+
1662
+ Example:
1663
+ if (isdir("output")) {
1664
+ // Directory exists
1665
+ } else {
1666
+ makedirs("output");
1667
+ }
1668
+ """
953
1669
  ...
954
1670
 
955
- def listdir(path: str) -> List[str]:
956
- """List directory contents.
1671
+ def listdir(path: str = ".") -> List[str]:
1672
+ """List directory contents (file and folder names).
1673
+
1674
+ Args:
1675
+ path: Directory path (default: current directory)
957
1676
 
958
1677
  Returns:
959
- List of file/folder names
1678
+ List of file/folder names (not full paths)
1679
+
1680
+ Example:
1681
+ stack<string> files = listdir("./data");
1682
+ foreach (f in files) {
1683
+ printl(f);
1684
+ }
960
1685
  """
961
1686
  ...
962
1687
 
963
1688
  def makedirs(path: str) -> bool:
964
- """Create directory and parent directories.
1689
+ """Create directory and all parent directories.
965
1690
 
966
- Returns:
967
- Success status
1691
+ Does not raise error if directory already exists.
1692
+
1693
+ Example:
1694
+ makedirs("output/reports/2025");
968
1695
  """
969
1696
  ...
970
1697
 
971
1698
  def removefile(path: str) -> bool:
972
- """Delete a file."""
1699
+ """Delete a file.
1700
+
1701
+ Example:
1702
+ removefile("temp.txt");
1703
+ """
973
1704
  ...
974
1705
 
975
1706
  def removedir(path: str) -> bool:
976
- """Delete an empty directory."""
1707
+ """Delete an empty directory.
1708
+
1709
+ Note: Directory must be empty. Use with caution.
1710
+
1711
+ Example:
1712
+ removedir("empty_folder");
1713
+ """
977
1714
  ...
978
1715
 
979
- def copyfile(src: str, dst: str) -> bool:
980
- """Copy file from source to destination."""
1716
+ def copyfile(src: str, dst: str) -> str:
1717
+ """Copy file from source to destination.
1718
+
1719
+ Returns:
1720
+ Destination path
1721
+
1722
+ Example:
1723
+ copyfile("original.txt", "backup.txt");
1724
+ """
981
1725
  ...
982
1726
 
983
- def movefile(src: str, dst: str) -> bool:
984
- """Move/rename file."""
1727
+ def movefile(src: str, dst: str) -> str:
1728
+ """Move or rename file.
1729
+
1730
+ Returns:
1731
+ Destination path
1732
+
1733
+ Example:
1734
+ movefile("old_name.txt", "new_name.txt");
1735
+ movefile("file.txt", "archive/file.txt");
1736
+ """
985
1737
  ...
986
1738
 
987
1739
  def filesize(path: str) -> int:
988
- """Get file size in bytes."""
1740
+ """Get file size in bytes.
1741
+
1742
+ Example:
1743
+ int size = filesize("large_file.zip");
1744
+ printl("Size: " + size + " bytes");
1745
+ """
989
1746
  ...
990
1747
 
991
1748
  def basename(path: str) -> str:
992
1749
  """Get filename from path.
993
1750
 
994
1751
  Example:
995
- basename("/path/to/file.txt"); // "file.txt"
1752
+ basename("/path/to/file.txt"); // "file.txt"
1753
+ basename("C:\\Users\\file.txt"); // "file.txt"
996
1754
  """
997
1755
  ...
998
1756
 
@@ -1000,20 +1758,41 @@ def dirname(path: str) -> str:
1000
1758
  """Get directory from path.
1001
1759
 
1002
1760
  Example:
1003
- dirname("/path/to/file.txt"); // "/path/to"
1761
+ dirname("/path/to/file.txt"); // "/path/to"
1004
1762
  """
1005
1763
  ...
1006
1764
 
1007
1765
  def joinpath(*parts: str) -> str:
1008
- """Join path components.
1766
+ """Join path components with correct separator.
1009
1767
 
1010
1768
  Example:
1011
1769
  joinpath("/path", "to", "file.txt"); // "/path/to/file.txt"
1770
+ joinpath("data", "output.csv"); // "data/output.csv"
1012
1771
  """
1013
1772
  ...
1014
1773
 
1015
1774
  def abspath(path: str) -> str:
1016
- """Get absolute path."""
1775
+ """Get absolute path from relative path.
1776
+
1777
+ Example:
1778
+ abspath("./file.txt"); // "/current/working/dir/file.txt"
1779
+ """
1780
+ ...
1781
+
1782
+ def normpath(path: str) -> str:
1783
+ """Normalize path (resolve .. and ., fix separators).
1784
+
1785
+ Example:
1786
+ normpath("/path/to/../file.txt"); // "/path/file.txt"
1787
+ """
1788
+ ...
1789
+
1790
+ def splitpath(path: str) -> List[str]:
1791
+ """Split path into [directory, filename].
1792
+
1793
+ Example:
1794
+ splitpath("/path/to/file.txt"); // ["/path/to", "file.txt"]
1795
+ """
1017
1796
  ...
1018
1797
 
1019
1798
  # =============================================================================
@@ -1023,94 +1802,154 @@ def abspath(path: str) -> str:
1023
1802
  def json_read(path: str) -> Any:
1024
1803
  """Read and parse JSON file.
1025
1804
 
1026
- Usage: json::read("/path/to/file.json")
1805
+ Usage in CSSL: json::read("/path/to/file.json")
1806
+
1807
+ Args:
1808
+ path: Path to JSON file
1027
1809
 
1028
1810
  Returns:
1029
- Parsed JSON data
1811
+ Parsed JSON data (dict, list, or primitive)
1812
+
1813
+ Example:
1814
+ json config = json::read("config.json");
1815
+ printl(config.name);
1816
+ printl(config.settings.theme);
1030
1817
  """
1031
1818
  ...
1032
1819
 
1033
1820
  def json_write(path: str, data: Any, indent: int = 2) -> bool:
1034
- """Write data to JSON file.
1821
+ """Write data to JSON file with formatting.
1035
1822
 
1036
- Usage: json::write("/path/to/file.json", data)
1823
+ Usage in CSSL: json::write("/path/to/file.json", data)
1824
+
1825
+ Args:
1826
+ path: Output file path
1827
+ data: Data to serialize (dict, list, primitives)
1828
+ indent: Indentation spaces (default: 2)
1037
1829
 
1038
1830
  Returns:
1039
1831
  Success status
1832
+
1833
+ Example:
1834
+ json data = {"name": "Alice", "age": 30};
1835
+ json::write("user.json", data);
1040
1836
  """
1041
1837
  ...
1042
1838
 
1043
1839
  def json_parse(s: str) -> Any:
1044
- """Parse JSON string.
1840
+ """Parse JSON string to object.
1045
1841
 
1046
- Usage: json::parse('{"key": "value"}')
1842
+ Usage in CSSL: json::parse('{"key": "value"}')
1047
1843
 
1048
- Returns:
1049
- Parsed object/array
1844
+ Example:
1845
+ string jsonStr = '{"name": "Bob", "active": true}';
1846
+ json obj = json::parse(jsonStr);
1847
+ printl(obj.name); // "Bob"
1050
1848
  """
1051
1849
  ...
1052
1850
 
1053
1851
  def json_stringify(data: Any) -> str:
1054
- """Convert data to JSON string.
1852
+ """Convert object to JSON string (compact).
1055
1853
 
1056
- Usage: json::stringify(data)
1854
+ Usage in CSSL: json::stringify(data)
1855
+
1856
+ Example:
1857
+ json obj = {"a": 1, "b": [1, 2, 3]};
1858
+ string s = json::stringify(obj);
1859
+ // '{"a":1,"b":[1,2,3]}'
1057
1860
  """
1058
1861
  ...
1059
1862
 
1060
1863
  def json_pretty(data: Any, indent: int = 2) -> str:
1061
- """Pretty print JSON with indentation.
1864
+ """Convert object to formatted JSON string.
1062
1865
 
1063
- Usage: json::pretty(data)
1866
+ Usage in CSSL: json::pretty(data)
1867
+
1868
+ Example:
1869
+ string formatted = json::pretty(config);
1870
+ printl(formatted);
1064
1871
  """
1065
1872
  ...
1066
1873
 
1067
1874
  def json_get(data: Any, path: str, default: Any = None) -> Any:
1068
- """Get value by dot-path.
1875
+ """Get value by dot-path from nested structure.
1069
1876
 
1070
- Usage: json::get(data, "user.name")
1877
+ Usage in CSSL: json::get(data, "user.profile.name")
1878
+
1879
+ Supports array indexing with numeric path segments.
1071
1880
 
1072
1881
  Args:
1073
- data: JSON object
1074
- path: Dot-separated path (e.g., "user.profile.age")
1075
- default: Default value if path not found
1882
+ data: JSON object/dict
1883
+ path: Dot-separated path (e.g., "user.address.city")
1884
+ default: Value if path not found
1885
+
1886
+ Example:
1887
+ json data = {"user": {"name": "Alice", "tags": ["a", "b"]}};
1888
+ json::get(data, "user.name"); // "Alice"
1889
+ json::get(data, "user.tags.0"); // "a"
1890
+ json::get(data, "user.email", "N/A"); // "N/A"
1076
1891
  """
1077
1892
  ...
1078
1893
 
1079
1894
  def json_set(data: Any, path: str, value: Any) -> Any:
1080
- """Set value by dot-path.
1895
+ """Set value by dot-path in nested structure.
1896
+
1897
+ Usage in CSSL: json::set(data, "user.name", "Bob")
1081
1898
 
1082
- Usage: json::set(data, "user.name", "John")
1899
+ Creates intermediate objects if they don't exist.
1083
1900
 
1084
1901
  Returns:
1085
- Modified data
1902
+ Modified data (new copy)
1903
+
1904
+ Example:
1905
+ json data = {"user": {}};
1906
+ data = json::set(data, "user.name", "Alice");
1907
+ data = json::set(data, "user.profile.age", 30);
1086
1908
  """
1087
1909
  ...
1088
1910
 
1089
1911
  def json_has(data: Any, path: str) -> bool:
1090
- """Check if path exists.
1912
+ """Check if dot-path exists in structure.
1091
1913
 
1092
- Usage: json::has(data, "user.email")
1914
+ Usage in CSSL: json::has(data, "user.email")
1915
+
1916
+ Example:
1917
+ if (json::has(config, "database.host")) {
1918
+ string host = json::get(config, "database.host");
1919
+ }
1093
1920
  """
1094
1921
  ...
1095
1922
 
1096
1923
  def json_keys(data: Dict) -> List[str]:
1097
- """Get all keys from JSON object.
1924
+ """Get all top-level keys from JSON object.
1098
1925
 
1099
- Usage: json::keys(data)
1926
+ Usage in CSSL: json::keys(data)
1927
+
1928
+ Example:
1929
+ stack<string> k = json::keys(config);
1930
+ // ["name", "version", "settings"]
1100
1931
  """
1101
1932
  ...
1102
1933
 
1103
1934
  def json_values(data: Dict) -> List[Any]:
1104
- """Get all values from JSON object.
1935
+ """Get all top-level values from JSON object.
1105
1936
 
1106
- Usage: json::values(data)
1937
+ Usage in CSSL: json::values(data)
1107
1938
  """
1108
1939
  ...
1109
1940
 
1110
1941
  def json_merge(*dicts: Dict) -> Dict:
1111
1942
  """Deep merge multiple JSON objects.
1112
1943
 
1113
- Usage: json::merge(obj1, obj2, obj3)
1944
+ Usage in CSSL: json::merge(obj1, obj2, obj3)
1945
+
1946
+ Later objects override earlier ones. Nested objects are merged recursively.
1947
+
1948
+ Example:
1949
+ json defaults = {"theme": "light", "lang": "en"};
1950
+ json user = {"theme": "dark"};
1951
+ json config = json::merge(defaults, user);
1952
+ // {"theme": "dark", "lang": "en"}
1114
1953
  """
1115
1954
  ...
1116
1955
 
@@ -1119,67 +1958,112 @@ def json_merge(*dicts: Dict) -> Dict:
1119
1958
  # =============================================================================
1120
1959
 
1121
1960
  def instance_getMethods(obj: Any) -> List[str]:
1122
- """Get all method names from object/module.
1961
+ """Get all public method names from object/module.
1123
1962
 
1124
- Usage: instance::getMethods(@module)
1963
+ Usage in CSSL: instance::getMethods(@module)
1125
1964
 
1126
- Returns:
1127
- List of callable method names
1965
+ Returns list of callable method names (excludes private _ methods).
1966
+
1967
+ Example:
1968
+ @tk = include("tkinter.cssl-mod");
1969
+ stack<string> methods = instance::getMethods(@tk);
1970
+ foreach (m in methods) {
1971
+ printl("Method: " + m);
1972
+ }
1128
1973
  """
1129
1974
  ...
1130
1975
 
1131
1976
  def instance_getClasses(obj: Any) -> List[str]:
1132
1977
  """Get all class names from module.
1133
1978
 
1134
- Usage: instance::getClasses(@module)
1979
+ Usage in CSSL: instance::getClasses(@module)
1980
+
1981
+ Example:
1982
+ stack<string> classes = instance::getClasses(@tk);
1983
+ // ["Tk", "Frame", "Button", "Label", ...]
1135
1984
  """
1136
1985
  ...
1137
1986
 
1138
1987
  def instance_getVars(obj: Any) -> List[str]:
1139
- """Get all variable/attribute names.
1988
+ """Get all public variable/attribute names (non-callable).
1140
1989
 
1141
- Usage: instance::getVars(@module)
1990
+ Usage in CSSL: instance::getVars(@module)
1991
+
1992
+ Example:
1993
+ stack<string> vars = instance::getVars(@config);
1994
+ // ["VERSION", "DEBUG", "API_URL", ...]
1142
1995
  """
1143
1996
  ...
1144
1997
 
1145
1998
  def instance_getAll(obj: Any) -> Dict[str, List[str]]:
1146
- """Get all attributes categorized.
1999
+ """Get all attributes categorized by type.
1147
2000
 
1148
- Usage: instance::getAll(@module)
2001
+ Usage in CSSL: instance::getAll(@module)
1149
2002
 
1150
- Returns:
1151
- Dict with 'methods', 'classes', 'vars' keys
2003
+ Returns dict with keys: 'methods', 'classes', 'vars'
2004
+
2005
+ Example:
2006
+ json all = instance::getAll(@module);
2007
+ printl("Methods: " + len(all.methods));
2008
+ printl("Classes: " + len(all.classes));
2009
+ printl("Variables: " + len(all.vars));
1152
2010
  """
1153
2011
  ...
1154
2012
 
1155
2013
  def instance_call(obj: Any, method_name: str, *args: Any, **kwargs: Any) -> Any:
1156
- """Dynamically call method on object.
2014
+ """Dynamically call method on object by name.
2015
+
2016
+ Usage in CSSL: instance::call(@module, "methodName", arg1, arg2)
2017
+
2018
+ Example:
2019
+ // Instead of @module.process(data)
2020
+ result = instance::call(@module, "process", data);
1157
2021
 
1158
- Usage: instance::call(@module, "methodName", arg1, arg2)
2022
+ // Useful for dynamic method selection
2023
+ string action = "save";
2024
+ instance::call(@handler, action, document);
1159
2025
  """
1160
2026
  ...
1161
2027
 
1162
2028
  def instance_has(obj: Any, name: str) -> bool:
1163
- """Check if object has attribute.
2029
+ """Check if object has attribute (method or variable).
1164
2030
 
1165
- Usage: instance::has(@module, "methodName")
2031
+ Usage in CSSL: instance::has(@module, "methodName")
2032
+
2033
+ Example:
2034
+ if (instance::has(@plugin, "initialize")) {
2035
+ instance::call(@plugin, "initialize");
2036
+ }
1166
2037
  """
1167
2038
  ...
1168
2039
 
1169
2040
  def instance_type(obj: Any) -> str:
1170
2041
  """Get type name of object.
1171
2042
 
1172
- Usage: instance::type(@module)
2043
+ Usage in CSSL: instance::type(@module)
2044
+
2045
+ Example:
2046
+ string t = instance::type(@data);
2047
+ printl("Type: " + t); // "dict", "list", "CSSLModule", etc.
1173
2048
  """
1174
2049
  ...
1175
2050
 
1176
2051
  def isavailable(name_or_obj: Any) -> bool:
1177
2052
  """Check if shared instance exists.
1178
2053
 
2054
+ Can check by name string or by shared reference.
2055
+
1179
2056
  Usage:
1180
- isavailable("MyInstance") // Check by name
1181
- isavailable($MyInstance) // Check if not null
1182
- instance::exists("Name") // Alias
2057
+ isavailable("MyInstance") // Check by name
2058
+ isavailable($MyInstance) // Check if shared ref is not null
2059
+ instance::exists("Name") // Alias
2060
+
2061
+ Example:
2062
+ if (isavailable("DatabaseConnection")) {
2063
+ $DatabaseConnection.query("SELECT * FROM users");
2064
+ } else {
2065
+ error("Database not connected");
2066
+ }
1183
2067
  """
1184
2068
  ...
1185
2069
 
@@ -1188,34 +2072,62 @@ def isavailable(name_or_obj: Any) -> bool:
1188
2072
  # =============================================================================
1189
2073
 
1190
2074
  def match(pattern: str, string: str) -> Optional[Dict]:
1191
- """Match regex at start of string.
2075
+ """Match regex pattern at START of string.
2076
+
2077
+ Args:
2078
+ pattern: Regular expression pattern
2079
+ string: String to match against
1192
2080
 
1193
2081
  Returns:
1194
- Dict with 'match', 'groups', 'start', 'end' or null
2082
+ Dict with 'match', 'groups', 'start', 'end' if matched, null otherwise
2083
+
2084
+ Example:
2085
+ json m = match("\\d+", "123abc");
2086
+ if (m != null) {
2087
+ printl(m.match); // "123"
2088
+ printl(m.start); // 0
2089
+ printl(m.end); // 3
2090
+ }
1195
2091
  """
1196
2092
  ...
1197
2093
 
1198
2094
  def search(pattern: str, string: str) -> Optional[Dict]:
1199
- """Search for regex anywhere in string.
2095
+ """Search for regex pattern ANYWHERE in string.
1200
2096
 
1201
2097
  Returns:
1202
2098
  Dict with match info or null
2099
+
2100
+ Example:
2101
+ json m = search("\\d+", "abc123def");
2102
+ printl(m.match); // "123"
2103
+ printl(m.start); // 3
1203
2104
  """
1204
2105
  ...
1205
2106
 
1206
2107
  def findall(pattern: str, string: str) -> List[str]:
1207
- """Find all regex matches.
2108
+ """Find all non-overlapping matches of pattern.
1208
2109
 
1209
2110
  Returns:
1210
- List of all matches
2111
+ List of all matching strings
2112
+
2113
+ Example:
2114
+ stack<string> nums = findall("\\d+", "a1b22c333");
2115
+ // ["1", "22", "333"]
1211
2116
  """
1212
2117
  ...
1213
2118
 
1214
- def sub(pattern: str, replacement: str, string: str) -> str:
1215
- """Replace all regex matches.
2119
+ def sub(pattern: str, replacement: str, string: str, count: int = 0) -> str:
2120
+ """Replace regex matches with replacement string.
2121
+
2122
+ Args:
2123
+ pattern: Regex pattern to find
2124
+ replacement: Replacement string
2125
+ string: Source string
2126
+ count: Max replacements (0 = unlimited)
1216
2127
 
1217
2128
  Example:
1218
- sub("\\d+", "X", "a1b2c3"); // "aXbXcX"
2129
+ sub("\\d+", "X", "a1b2c3"); // "aXbXcX"
2130
+ sub("\\d+", "X", "a1b2c3", 2); // "aXbXc3"
1219
2131
  """
1220
2132
  ...
1221
2133
 
@@ -1224,19 +2136,36 @@ def sub(pattern: str, replacement: str, string: str) -> str:
1224
2136
  # =============================================================================
1225
2137
 
1226
2138
  def md5(s: str) -> str:
1227
- """Calculate MD5 hash.
2139
+ """Calculate MD5 hash of string.
1228
2140
 
1229
2141
  Returns:
1230
- Hexadecimal hash string
2142
+ 32-character hexadecimal hash string
2143
+
2144
+ Example:
2145
+ md5("hello"); // "5d41402abc4b2a76b9719d911017c592"
1231
2146
  """
1232
2147
  ...
1233
2148
 
1234
2149
  def sha1(s: str) -> str:
1235
- """Calculate SHA1 hash."""
2150
+ """Calculate SHA-1 hash of string.
2151
+
2152
+ Returns:
2153
+ 40-character hexadecimal hash string
2154
+
2155
+ Example:
2156
+ sha1("hello"); // "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d"
2157
+ """
1236
2158
  ...
1237
2159
 
1238
2160
  def sha256(s: str) -> str:
1239
- """Calculate SHA256 hash."""
2161
+ """Calculate SHA-256 hash of string.
2162
+
2163
+ Returns:
2164
+ 64-character hexadecimal hash string
2165
+
2166
+ Example:
2167
+ sha256("hello"); // "2cf24dba5fb0a30e26e83b2ac5b9e29e..."
2168
+ """
1240
2169
  ...
1241
2170
 
1242
2171
  # =============================================================================
@@ -1244,135 +2173,239 @@ def sha256(s: str) -> str:
1244
2173
  # =============================================================================
1245
2174
 
1246
2175
  def exit(code: int = 0) -> None:
1247
- """Exit CSSL execution.
2176
+ """Exit CSSL script execution.
2177
+
2178
+ Can be intercepted with CodeInfusion for cleanup.
1248
2179
 
1249
2180
  Args:
1250
- code: Exit code (default: 0)
2181
+ code: Exit code (0 = success, non-zero = error)
2182
+
2183
+ Example:
2184
+ // Basic exit
2185
+ exit();
2186
+ exit(0); // Success
2187
+ exit(1); // Error
2188
+
2189
+ // With cleanup via CodeInfusion
2190
+ exit() <<== {
2191
+ printl("Cleaning up...");
2192
+ // cleanup code
2193
+ }
1251
2194
  """
1252
2195
  ...
1253
2196
 
1254
2197
  def input(prompt: str = "") -> str:
1255
- """Read user input from console.
2198
+ """Read line of user input from console.
1256
2199
 
1257
2200
  Args:
1258
- prompt: Optional prompt message
2201
+ prompt: Optional prompt message to display
1259
2202
 
1260
2203
  Returns:
1261
- User input string
2204
+ User input string (without newline)
2205
+
2206
+ Example:
2207
+ string name = input("Enter your name: ");
2208
+ printl("Hello, " + name);
2209
+
2210
+ string answer = input("Continue? (y/n): ");
2211
+ if (answer == "y") {
2212
+ // continue
2213
+ }
1262
2214
  """
1263
2215
  ...
1264
2216
 
1265
- def env(name: str) -> Optional[str]:
1266
- """Get environment variable.
2217
+ def env(name: str, default: str = None) -> Optional[str]:
2218
+ """Get environment variable value.
1267
2219
 
1268
2220
  Args:
1269
- name: Variable name
2221
+ name: Environment variable name
2222
+ default: Default if not set
1270
2223
 
1271
2224
  Returns:
1272
- Variable value or null
2225
+ Variable value or default/null
2226
+
2227
+ Example:
2228
+ string home = env("HOME");
2229
+ string path = env("MY_APP_PATH", "/default/path");
1273
2230
  """
1274
2231
  ...
1275
2232
 
1276
2233
  def setenv(name: str, value: str) -> None:
1277
- """Set environment variable."""
2234
+ """Set environment variable.
2235
+
2236
+ Example:
2237
+ setenv("MY_VAR", "my_value");
2238
+ """
1278
2239
  ...
1279
2240
 
1280
2241
  def clear() -> None:
1281
- """Clear console screen."""
2242
+ """Clear console screen.
2243
+
2244
+ Example:
2245
+ clear();
2246
+ printl("Fresh screen!");
2247
+ """
1282
2248
  ...
1283
2249
 
1284
2250
  def copy(obj: Any) -> Any:
1285
- """Create shallow copy of object."""
2251
+ """Create shallow copy of object.
2252
+
2253
+ For lists/dicts, creates new container but references same nested objects.
2254
+
2255
+ Example:
2256
+ stack<int> original = [1, 2, 3];
2257
+ stack<int> copied = copy(original);
2258
+ copied.push(4);
2259
+ // original is still [1, 2, 3]
2260
+ """
1286
2261
  ...
1287
2262
 
1288
2263
  def deepcopy(obj: Any) -> Any:
1289
- """Create deep copy of object."""
2264
+ """Create deep copy of object (recursively copies nested objects).
2265
+
2266
+ Example:
2267
+ json original = {"nested": {"value": 1}};
2268
+ json copied = deepcopy(original);
2269
+ copied.nested.value = 2;
2270
+ printl(original.nested.value); // Still 1
2271
+ """
1290
2272
  ...
1291
2273
 
1292
- def pyimport(module_name: str) -> Any:
1293
- """Import Python module dynamically.
2274
+ def assert_condition(condition: bool, message: str = "Assertion failed") -> None:
2275
+ """Assert condition is true, raise error if false.
2276
+
2277
+ Usage in CSSL: assert(condition, "message")
1294
2278
 
1295
2279
  Example:
1296
- @os = pyimport("os");
1297
- @os.getcwd();
2280
+ assert(x > 0, "x must be positive");
2281
+ assert(isstr(name), "name must be string");
1298
2282
  """
1299
2283
  ...
1300
2284
 
1301
- def include(path: str) -> Any:
1302
- """Include/import CSSL module.
2285
+ def pyimport(module_name: str) -> Any:
2286
+ """Import Python module for use in CSSL.
2287
+
2288
+ Provides access to Python's standard library and installed packages.
1303
2289
 
1304
2290
  Args:
1305
- path: Module path (e.g., "mymodule.cssl-mod")
2291
+ module_name: Python module name
1306
2292
 
1307
2293
  Returns:
1308
2294
  Imported module object
2295
+
2296
+ Example:
2297
+ @os = pyimport("os");
2298
+ string cwd = @os.getcwd();
2299
+
2300
+ @re = pyimport("re");
2301
+ json match = @re.search("\\d+", "abc123");
2302
+
2303
+ @datetime = pyimport("datetime");
2304
+ @datetime.datetime.now();
1309
2305
  """
1310
2306
  ...
1311
2307
 
1312
- def payload(path: str) -> Any:
1313
- """Load CSSL payload file.
2308
+ def include(path: str) -> Any:
2309
+ """Import CSSL module or file.
2310
+
2311
+ Supports .cssl files and .cssl-mod compiled modules.
2312
+ Returns module object with accessible functions and variables.
1314
2313
 
1315
2314
  Args:
1316
- path: Payload file path (e.g., "data.cssl-pl")
1317
- """
1318
- ...
2315
+ path: Path to module file
1319
2316
 
1320
- # =============================================================================
1321
- # CSSL-SPECIFIC FUNCTIONS
1322
- # =============================================================================
2317
+ Returns:
2318
+ Imported module object
1323
2319
 
1324
- def OpenFind(type_or_combo: Any, index: int = 0) -> Optional[Any]:
1325
- """Find open parameter by type or combo space.
2320
+ Example:
2321
+ // Import compiled Python module
2322
+ @Math = include("mathlib.cssl-mod");
2323
+ int result = @Math.add(5, 3);
1326
2324
 
1327
- Usage:
1328
- string name = OpenFind<string>(0);
1329
- value = OpenFind(&comboSpace);
2325
+ // Import CSSL file
2326
+ @Utils = include("utils.cssl");
2327
+ @Utils.formatDate(now());
1330
2328
  """
1331
2329
  ...
1332
2330
 
1333
- def datastruct(element_type: str = "dynamic") -> Any:
1334
- """Create datastruct container.
2331
+ def payload(path_or_name: str) -> None:
2332
+ """Load CSSL payload file into current scope.
2333
+
2334
+ Payloads are like headers - they define globals, functions, and
2335
+ can inject code into existing functions. All definitions become
2336
+ available in the current execution context.
2337
+
2338
+ Supports:
2339
+ - File paths: "helpers.cssl-pl"
2340
+ - Registered names: payload registered via CSSL.code() in Python
2341
+
2342
+ Args:
2343
+ path_or_name: Path to .cssl-pl file or registered payload name
1335
2344
 
1336
2345
  Example:
1337
- datastruct<string> data;
2346
+ // In helpers.cssl-pl:
2347
+ global DEBUG = true;
2348
+ void log(string msg) {
2349
+ if (@DEBUG) printl("[LOG] " + msg);
2350
+ }
2351
+
2352
+ // In main.cssl:
2353
+ payload("helpers.cssl-pl");
2354
+ log("Hello!"); // Works - function from payload
2355
+
2356
+ // From Python:
2357
+ CSSL.code("myhelper", "void greet() { printl('Hi'); }")
2358
+ CSSL.run('payload("myhelper"); greet();')
1338
2359
  """
1339
2360
  ...
1340
2361
 
1341
- def shuffled(element_type: str = "dynamic") -> Any:
1342
- """Create shuffled container for unorganized fast storage."""
1343
- ...
2362
+ def color(text: str, color_name: str) -> str:
2363
+ """Apply ANSI color to text for terminal output.
1344
2364
 
1345
- def iterator(element_type: str = "int", size: int = 16) -> Any:
1346
- """Create iterator with programmable tasks."""
1347
- ...
2365
+ Available colors:
2366
+ Basic: black, red, green, yellow, blue, magenta, cyan, white
2367
+ Bright: bright_black, bright_red, bright_green, etc.
2368
+ Styles: bold, dim, italic, underline, blink, reverse
1348
2369
 
1349
- def combo(element_type: str = "dynamic") -> Any:
1350
- """Create combo filter/search space."""
2370
+ Example:
2371
+ printl(color("Error!", "red"));
2372
+ printl(color("Success", "green"));
2373
+ printl(color("Warning", "yellow"));
2374
+ printl(color("Important", "bold"));
2375
+ """
1351
2376
  ...
1352
2377
 
1353
- def share(name: str, obj: Any) -> None:
1354
- """Share Python object with CSSL.
2378
+ def original(func_name: str, *args: Any) -> Any:
2379
+ """Call the original version of a replaced function.
1355
2380
 
1356
- Args:
1357
- name: Instance name for CSSL access
1358
- obj: Python object to share
2381
+ Used within CodeInfusion to call the function that was replaced.
1359
2382
 
1360
- Example (Python):
1361
- CSSL.share("mydata", data_object)
1362
-
1363
- Example (CSSL):
1364
- $mydata.property;
2383
+ Example:
2384
+ // Replace exit with custom behavior
2385
+ exit() <<== {
2386
+ printl("Custom cleanup...");
2387
+ original("exit"); // Call original exit
2388
+ }
1365
2389
  """
1366
2390
  ...
1367
2391
 
1368
2392
  def delete(name: str) -> bool:
1369
- """Delete shared object.
2393
+ """Delete a shared object by name.
2394
+
2395
+ Removes object from shared instance registry.
1370
2396
 
1371
2397
  Args:
1372
- name: Shared object name
2398
+ name: Shared object name (without $ prefix)
1373
2399
 
1374
2400
  Returns:
1375
2401
  True if deleted, False if not found
2402
+
2403
+ Example:
2404
+ // In Python: CSSL.share(myObj, "temp")
2405
+ // In CSSL:
2406
+ $temp.doSomething();
2407
+ delete("temp"); // Remove when done
2408
+ // $temp is now null
1376
2409
  """
1377
2410
  ...
1378
2411
 
@@ -1381,13 +2414,1805 @@ def delete(name: str) -> bool:
1381
2414
  # =============================================================================
1382
2415
 
1383
2416
  def isLinux() -> bool:
1384
- """Check if running on Linux."""
2417
+ """Check if running on Linux operating system.
2418
+
2419
+ Example:
2420
+ if (isLinux()) {
2421
+ string home = env("HOME");
2422
+ }
2423
+ """
1385
2424
  ...
1386
2425
 
1387
2426
  def isWindows() -> bool:
1388
- """Check if running on Windows."""
2427
+ """Check if running on Windows operating system.
2428
+
2429
+ Example:
2430
+ if (isWindows()) {
2431
+ string home = env("USERPROFILE");
2432
+ }
2433
+ """
1389
2434
  ...
1390
2435
 
1391
2436
  def isMac() -> bool:
1392
- """Check if running on macOS."""
2437
+ """Check if running on macOS operating system.
2438
+
2439
+ Example:
2440
+ if (isMac()) {
2441
+ printl("Running on Apple hardware");
2442
+ }
2443
+ """
2444
+ ...
2445
+
2446
+ # =============================================================================
2447
+ # CSSL CONTAINER TYPES - Class-based with method documentation
2448
+ # =============================================================================
2449
+
2450
+ class CSSLStack:
2451
+ """CSSL stack<T> container - LIFO (Last In, First Out) data structure.
2452
+
2453
+ A stack is a collection where elements are added and removed from the same end
2454
+ (the "top"). The last element added is the first one removed.
2455
+
2456
+ Declaration in CSSL:
2457
+ stack<string> names;
2458
+ stack<int> numbers;
2459
+ stack<dynamic> mixed; // Can hold any type
2460
+
2461
+ Example:
2462
+ stack<string> tasks;
2463
+ tasks.push("First task");
2464
+ tasks.push("Second task");
2465
+ tasks.push("Third task");
2466
+
2467
+ printl(tasks); // ['First task', 'Second task', 'Third task']
2468
+ printl(tasks.peek()); // "Third task" (view top without removing)
2469
+ printl(tasks.pop()); // "Third task" (removes and returns top)
2470
+ printl(tasks.length()); // 2
2471
+ printl(tasks[0]); // "First task" (index access)
2472
+ """
2473
+
2474
+ def push(self, value: T) -> 'CSSLStack':
2475
+ """Add element to top of stack.
2476
+
2477
+ Args:
2478
+ value: Element to add
2479
+
2480
+ Returns:
2481
+ The stack (for chaining)
2482
+
2483
+ Example:
2484
+ stack<int> nums;
2485
+ nums.push(1).push(2).push(3); // Chained calls
2486
+ printl(nums); // [1, 2, 3]
2487
+ """
2488
+ ...
2489
+
2490
+ def push_back(self, value: T) -> 'CSSLStack':
2491
+ """Alias for push(). Add element to top of stack."""
2492
+ ...
2493
+
2494
+ def pop(self) -> T:
2495
+ """Remove and return top element.
2496
+
2497
+ Returns:
2498
+ The removed element from top of stack
2499
+
2500
+ Example:
2501
+ stack<string> names = ["Alice", "Bob", "Charlie"];
2502
+ string last = names.pop(); // "Charlie"
2503
+ printl(names); // ["Alice", "Bob"]
2504
+ """
2505
+ ...
2506
+
2507
+ def peek(self) -> T:
2508
+ """View top element without removing it.
2509
+
2510
+ Returns:
2511
+ The top element (or None if empty)
2512
+
2513
+ Example:
2514
+ stack<int> nums = [1, 2, 3];
2515
+ printl(nums.peek()); // 3
2516
+ printl(nums.peek()); // 3 (still there)
2517
+ """
2518
+ ...
2519
+
2520
+ def isEmpty(self) -> bool:
2521
+ """Check if stack has no elements.
2522
+
2523
+ Returns:
2524
+ True if stack is empty, False otherwise
2525
+
2526
+ Example:
2527
+ stack<int> nums;
2528
+ printl(nums.isEmpty()); // true
2529
+ nums.push(1);
2530
+ printl(nums.isEmpty()); // false
2531
+ """
2532
+ ...
2533
+
2534
+ def is_empty(self) -> bool:
2535
+ """Alias for isEmpty(). Check if stack is empty."""
2536
+ ...
2537
+
2538
+ def size(self) -> int:
2539
+ """Get number of elements in stack.
2540
+
2541
+ Returns:
2542
+ Number of elements
2543
+
2544
+ Example:
2545
+ stack<string> names = ["A", "B", "C"];
2546
+ printl(names.size()); // 3
2547
+ """
2548
+ ...
2549
+
2550
+ def length(self) -> int:
2551
+ """Alias for size(). Get number of elements."""
2552
+ ...
2553
+
2554
+ def contains(self, value: T) -> bool:
2555
+ """Check if stack contains a specific value.
2556
+
2557
+ Args:
2558
+ value: Value to search for
2559
+
2560
+ Returns:
2561
+ True if found, False otherwise
2562
+
2563
+ Example:
2564
+ stack<string> names = ["Alice", "Bob"];
2565
+ printl(names.contains("Alice")); // true
2566
+ printl(names.contains("Carol")); // false
2567
+ """
2568
+ ...
2569
+
2570
+ def indexOf(self, value: T) -> int:
2571
+ """Find index of first occurrence of value.
2572
+
2573
+ Args:
2574
+ value: Value to find
2575
+
2576
+ Returns:
2577
+ Index (0-based), or -1 if not found
2578
+
2579
+ Example:
2580
+ stack<string> names = ["A", "B", "C", "B"];
2581
+ printl(names.indexOf("B")); // 1
2582
+ printl(names.indexOf("X")); // -1
2583
+ """
2584
+ ...
2585
+
2586
+ def toArray(self) -> List[T]:
2587
+ """Convert stack to plain array/list.
2588
+
2589
+ Returns:
2590
+ List containing all stack elements
2591
+
2592
+ Example:
2593
+ stack<int> nums = [1, 2, 3];
2594
+ array = nums.toArray();
2595
+ printl(array); // [1, 2, 3]
2596
+ """
2597
+ ...
2598
+
2599
+ def swap(self) -> 'CSSLStack':
2600
+ """Swap top two elements.
2601
+
2602
+ Returns:
2603
+ The stack (for chaining)
2604
+
2605
+ Example:
2606
+ stack<int> nums = [1, 2, 3];
2607
+ nums.swap();
2608
+ printl(nums); // [1, 3, 2]
2609
+ """
2610
+ ...
2611
+
2612
+ def dup(self) -> 'CSSLStack':
2613
+ """Duplicate top element.
2614
+
2615
+ Returns:
2616
+ The stack (for chaining)
2617
+
2618
+ Example:
2619
+ stack<int> nums = [1, 2, 3];
2620
+ nums.dup();
2621
+ printl(nums); // [1, 2, 3, 3]
2622
+ """
2623
+ ...
2624
+
2625
+ def begin(self) -> int:
2626
+ """Get iterator to first element (C++ style).
2627
+
2628
+ Returns:
2629
+ Index 0
2630
+ """
2631
+ ...
2632
+
2633
+ def end(self) -> int:
2634
+ """Get iterator past last element (C++ style).
2635
+
2636
+ Returns:
2637
+ Length of stack
2638
+ """
2639
+ ...
2640
+
2641
+
2642
+ class CSSLVector:
2643
+ """CSSL vector<T> container - Dynamic resizable array.
2644
+
2645
+ A vector provides random access to elements by index and automatically
2646
+ grows as elements are added. Ideal for collections that need frequent
2647
+ access by position.
2648
+
2649
+ Declaration in CSSL:
2650
+ vector<int> numbers;
2651
+ vector<string> names;
2652
+ vector<float> prices;
2653
+
2654
+ Example:
2655
+ vector<int> nums;
2656
+ nums.push(10);
2657
+ nums.push(20);
2658
+ nums.push(30);
2659
+
2660
+ printl(nums); // [10, 20, 30]
2661
+ printl(nums.at(1)); // 20
2662
+ printl(nums.front()); // 10
2663
+ printl(nums.back()); // 30
2664
+ printl(nums.size()); // 3
2665
+ """
2666
+
2667
+ def push(self, value: T) -> 'CSSLVector':
2668
+ """Add element to end of vector.
2669
+
2670
+ Args:
2671
+ value: Element to add
2672
+
2673
+ Returns:
2674
+ The vector (for chaining)
2675
+
2676
+ Example:
2677
+ vector<string> items;
2678
+ items.push("A").push("B").push("C");
2679
+ """
2680
+ ...
2681
+
2682
+ def push_back(self, value: T) -> 'CSSLVector':
2683
+ """Alias for push(). Add element to end."""
2684
+ ...
2685
+
2686
+ def push_front(self, value: T) -> 'CSSLVector':
2687
+ """Add element to front of vector.
2688
+
2689
+ Args:
2690
+ value: Element to add
2691
+
2692
+ Returns:
2693
+ The vector (for chaining)
2694
+
2695
+ Example:
2696
+ vector<int> nums = [2, 3];
2697
+ nums.push_front(1);
2698
+ printl(nums); // [1, 2, 3]
2699
+ """
2700
+ ...
2701
+
2702
+ def pop_back(self) -> T:
2703
+ """Remove and return last element.
2704
+
2705
+ Returns:
2706
+ The removed element
2707
+
2708
+ Example:
2709
+ vector<int> nums = [1, 2, 3];
2710
+ int last = nums.pop_back(); // 3
2711
+ printl(nums); // [1, 2]
2712
+ """
2713
+ ...
2714
+
2715
+ def pop_front(self) -> T:
2716
+ """Remove and return first element.
2717
+
2718
+ Returns:
2719
+ The removed element
2720
+
2721
+ Example:
2722
+ vector<int> nums = [1, 2, 3];
2723
+ int first = nums.pop_front(); // 1
2724
+ printl(nums); // [2, 3]
2725
+ """
2726
+ ...
2727
+
2728
+ def at(self, index: int) -> T:
2729
+ """Get element at index.
2730
+
2731
+ Args:
2732
+ index: Zero-based position
2733
+
2734
+ Returns:
2735
+ Element at position (or None if out of bounds)
2736
+
2737
+ Example:
2738
+ vector<string> names = ["Alice", "Bob", "Carol"];
2739
+ printl(names.at(1)); // "Bob"
2740
+ """
2741
+ ...
2742
+
2743
+ def set(self, index: int, value: T) -> 'CSSLVector':
2744
+ """Set element at index.
2745
+
2746
+ Args:
2747
+ index: Zero-based position
2748
+ value: New value
2749
+
2750
+ Returns:
2751
+ The vector (for chaining)
2752
+
2753
+ Example:
2754
+ vector<int> nums = [1, 2, 3];
2755
+ nums.set(1, 99);
2756
+ printl(nums); // [1, 99, 3]
2757
+ """
2758
+ ...
2759
+
2760
+ def size(self) -> int:
2761
+ """Get number of elements."""
2762
+ ...
2763
+
2764
+ def length(self) -> int:
2765
+ """Alias for size()."""
2766
+ ...
2767
+
2768
+ def empty(self) -> bool:
2769
+ """Check if vector is empty."""
2770
+ ...
2771
+
2772
+ def isEmpty(self) -> bool:
2773
+ """Alias for empty()."""
2774
+ ...
2775
+
2776
+ def front(self) -> T:
2777
+ """Get first element without removing.
2778
+
2779
+ Example:
2780
+ vector<int> nums = [1, 2, 3];
2781
+ printl(nums.front()); // 1
2782
+ """
2783
+ ...
2784
+
2785
+ def back(self) -> T:
2786
+ """Get last element without removing.
2787
+
2788
+ Example:
2789
+ vector<int> nums = [1, 2, 3];
2790
+ printl(nums.back()); // 3
2791
+ """
2792
+ ...
2793
+
2794
+ def contains(self, value: T) -> bool:
2795
+ """Check if vector contains value."""
2796
+ ...
2797
+
2798
+ def indexOf(self, value: T) -> int:
2799
+ """Find first index of value (-1 if not found)."""
2800
+ ...
2801
+
2802
+ def lastIndexOf(self, value: T) -> int:
2803
+ """Find last index of value (-1 if not found)."""
2804
+ ...
2805
+
2806
+ def find(self, predicate: Callable[[T], bool]) -> T:
2807
+ """Find first element matching predicate.
2808
+
2809
+ Args:
2810
+ predicate: Function returning True for match
2811
+
2812
+ Returns:
2813
+ First matching element or None
2814
+
2815
+ Example:
2816
+ vector<int> nums = [1, 5, 10, 15];
2817
+ int found = nums.find(x => x > 7); // 10
2818
+ """
2819
+ ...
2820
+
2821
+ def findIndex(self, predicate: Callable[[T], bool]) -> int:
2822
+ """Find index of first element matching predicate."""
2823
+ ...
2824
+
2825
+ def slice(self, start: int, end: int = None) -> 'CSSLVector':
2826
+ """Get sub-vector from start to end.
2827
+
2828
+ Args:
2829
+ start: Start index (inclusive)
2830
+ end: End index (exclusive), defaults to end
2831
+
2832
+ Example:
2833
+ vector<int> nums = [1, 2, 3, 4, 5];
2834
+ vector<int> sub = nums.slice(1, 4); // [2, 3, 4]
2835
+ """
2836
+ ...
2837
+
2838
+ def join(self, separator: str = ",") -> str:
2839
+ """Join elements into string.
2840
+
2841
+ Example:
2842
+ vector<string> words = ["hello", "world"];
2843
+ printl(words.join(" ")); // "hello world"
2844
+ """
2845
+ ...
2846
+
2847
+ def map(self, func: Callable[[T], Any]) -> 'CSSLVector':
2848
+ """Apply function to each element, return new vector.
2849
+
2850
+ Example:
2851
+ vector<int> nums = [1, 2, 3];
2852
+ vector<int> doubled = nums.map(x => x * 2); // [2, 4, 6]
2853
+ """
2854
+ ...
2855
+
2856
+ def filter(self, predicate: Callable[[T], bool]) -> 'CSSLVector':
2857
+ """Return new vector with elements matching predicate.
2858
+
2859
+ Example:
2860
+ vector<int> nums = [1, 2, 3, 4, 5];
2861
+ vector<int> evens = nums.filter(x => x % 2 == 0); // [2, 4]
2862
+ """
2863
+ ...
2864
+
2865
+ def forEach(self, func: Callable[[T], None]) -> 'CSSLVector':
2866
+ """Execute function for each element.
2867
+
2868
+ Example:
2869
+ vector<string> names = ["Alice", "Bob"];
2870
+ names.forEach(name => printl("Hello " + name));
2871
+ """
2872
+ ...
2873
+
2874
+ def fill(self, value: T, start: int = 0, end: int = None) -> 'CSSLVector':
2875
+ """Fill range with value.
2876
+
2877
+ Example:
2878
+ vector<int> nums = [1, 2, 3, 4, 5];
2879
+ nums.fill(0, 1, 4);
2880
+ printl(nums); // [1, 0, 0, 0, 5]
2881
+ """
2882
+ ...
2883
+
2884
+ def every(self, predicate: Callable[[T], bool]) -> bool:
2885
+ """Check if all elements match predicate.
2886
+
2887
+ Example:
2888
+ vector<int> nums = [2, 4, 6];
2889
+ printl(nums.every(x => x % 2 == 0)); // true
2890
+ """
2891
+ ...
2892
+
2893
+ def some(self, predicate: Callable[[T], bool]) -> bool:
2894
+ """Check if any element matches predicate.
2895
+
2896
+ Example:
2897
+ vector<int> nums = [1, 2, 3];
2898
+ printl(nums.some(x => x > 2)); // true
2899
+ """
2900
+ ...
2901
+
2902
+ def reduce(self, func: Callable[[Any, T], Any], initial: Any = None) -> Any:
2903
+ """Reduce vector to single value.
2904
+
2905
+ Example:
2906
+ vector<int> nums = [1, 2, 3, 4];
2907
+ int sum = nums.reduce((acc, x) => acc + x, 0); // 10
2908
+ """
2909
+ ...
2910
+
2911
+ def toArray(self) -> List[T]:
2912
+ """Convert to plain list."""
2913
+ ...
2914
+
2915
+ def begin(self) -> int:
2916
+ """Get iterator to first element (C++ style)."""
2917
+ ...
2918
+
2919
+ def end(self) -> int:
2920
+ """Get iterator past last element (C++ style)."""
2921
+ ...
2922
+
2923
+
2924
+ class CSSLArray:
2925
+ """CSSL array<T> container - Standard array with CSSL methods.
2926
+
2927
+ Similar to vector but conceptually represents a fixed-purpose collection.
2928
+ Supports all standard array operations.
2929
+
2930
+ Declaration in CSSL:
2931
+ array<string> items;
2932
+ array<int> scores;
2933
+
2934
+ Example:
2935
+ array<string> colors;
2936
+ colors.push("red");
2937
+ colors.push("green");
2938
+ colors.push("blue");
2939
+ printl(colors.length()); // 3
2940
+ printl(colors.first()); // "red"
2941
+ printl(colors.last()); // "blue"
2942
+ """
2943
+
2944
+ def push(self, value: T) -> 'CSSLArray':
2945
+ """Add element to end of array."""
2946
+ ...
2947
+
2948
+ def push_back(self, value: T) -> 'CSSLArray':
2949
+ """Alias for push()."""
2950
+ ...
2951
+
2952
+ def push_front(self, value: T) -> 'CSSLArray':
2953
+ """Add element to front of array."""
2954
+ ...
2955
+
2956
+ def pop(self) -> T:
2957
+ """Remove and return last element."""
2958
+ ...
2959
+
2960
+ def pop_back(self) -> T:
2961
+ """Alias for pop()."""
2962
+ ...
2963
+
2964
+ def pop_front(self) -> T:
2965
+ """Remove and return first element."""
2966
+ ...
2967
+
2968
+ def at(self, index: int) -> T:
2969
+ """Get element at index."""
2970
+ ...
2971
+
2972
+ def set(self, index: int, value: T) -> 'CSSLArray':
2973
+ """Set element at index."""
2974
+ ...
2975
+
2976
+ def size(self) -> int:
2977
+ """Get number of elements."""
2978
+ ...
2979
+
2980
+ def length(self) -> int:
2981
+ """Alias for size()."""
2982
+ ...
2983
+
2984
+ def empty(self) -> bool:
2985
+ """Check if array is empty."""
2986
+ ...
2987
+
2988
+ def isEmpty(self) -> bool:
2989
+ """Alias for empty()."""
2990
+ ...
2991
+
2992
+ def first(self) -> T:
2993
+ """Get first element."""
2994
+ ...
2995
+
2996
+ def last(self) -> T:
2997
+ """Get last element."""
2998
+ ...
2999
+
3000
+ def contains(self, value: T) -> bool:
3001
+ """Check if array contains value."""
3002
+ ...
3003
+
3004
+ def indexOf(self, value: T) -> int:
3005
+ """Find first index of value."""
3006
+ ...
3007
+
3008
+ def lastIndexOf(self, value: T) -> int:
3009
+ """Find last index of value."""
3010
+ ...
3011
+
3012
+ def find(self, predicate: Callable[[T], bool]) -> T:
3013
+ """Find first element matching predicate."""
3014
+ ...
3015
+
3016
+ def findIndex(self, predicate: Callable[[T], bool]) -> int:
3017
+ """Find index of first match."""
3018
+ ...
3019
+
3020
+ def slice(self, start: int, end: int = None) -> 'CSSLArray':
3021
+ """Get sub-array from start to end."""
3022
+ ...
3023
+
3024
+ def join(self, separator: str = ",") -> str:
3025
+ """Join elements into string."""
3026
+ ...
3027
+
3028
+ def map(self, func: Callable[[T], Any]) -> 'CSSLArray':
3029
+ """Apply function to each element."""
3030
+ ...
3031
+
3032
+ def filter(self, predicate: Callable[[T], bool]) -> 'CSSLArray':
3033
+ """Filter elements by predicate."""
3034
+ ...
3035
+
3036
+ def forEach(self, func: Callable[[T], None]) -> 'CSSLArray':
3037
+ """Execute function for each element."""
3038
+ ...
3039
+
3040
+ def fill(self, value: T, start: int = 0, end: int = None) -> 'CSSLArray':
3041
+ """Fill range with value."""
3042
+ ...
3043
+
3044
+ def every(self, predicate: Callable[[T], bool]) -> bool:
3045
+ """Check if all elements match."""
3046
+ ...
3047
+
3048
+ def some(self, predicate: Callable[[T], bool]) -> bool:
3049
+ """Check if any element matches."""
3050
+ ...
3051
+
3052
+ def reduce(self, func: Callable[[Any, T], Any], initial: Any = None) -> Any:
3053
+ """Reduce to single value."""
3054
+ ...
3055
+
3056
+ def toArray(self) -> List[T]:
3057
+ """Convert to plain list."""
3058
+ ...
3059
+
3060
+
3061
+ class CSSLMap:
3062
+ """CSSL map<K, V> container - C++ style ordered key-value pairs.
3063
+
3064
+ A map stores key-value pairs with keys maintained in sorted order.
3065
+ Provides efficient lookup, insertion, and deletion by key.
3066
+
3067
+ Declaration in CSSL:
3068
+ map<string, int> ages;
3069
+ map<string, string> config;
3070
+ map<int, bool> flags;
3071
+
3072
+ Example:
3073
+ map<string, int> ages;
3074
+ ages.insert("Alice", 30);
3075
+ ages.insert("Bob", 25);
3076
+ ages.insert("Carol", 28);
3077
+
3078
+ printl(ages.find("Alice")); // 30
3079
+ printl(ages.contains("Bob")); // true
3080
+ printl(ages.size()); // 3
3081
+
3082
+ ages.erase("Bob");
3083
+ printl(ages.size()); // 2
3084
+ """
3085
+
3086
+ def insert(self, key: Any, value: Any) -> 'CSSLMap':
3087
+ """Insert or update key-value pair.
3088
+
3089
+ Args:
3090
+ key: The key to insert
3091
+ value: The value to associate with the key
3092
+
3093
+ Returns:
3094
+ The map (for chaining)
3095
+
3096
+ Example:
3097
+ map<string, int> scores;
3098
+ scores.insert("Alice", 100);
3099
+ scores.insert("Bob", 95);
3100
+ scores.insert("Alice", 105); // Updates Alice's score
3101
+ printl(scores.find("Alice")); // 105
3102
+ """
3103
+ ...
3104
+
3105
+ def find(self, key: Any) -> Optional[Any]:
3106
+ """Find value by key.
3107
+
3108
+ Args:
3109
+ key: The key to search for
3110
+
3111
+ Returns:
3112
+ The value if found, None otherwise
3113
+
3114
+ Example:
3115
+ map<string, int> ages;
3116
+ ages.insert("Alice", 30);
3117
+ printl(ages.find("Alice")); // 30
3118
+ printl(ages.find("Bob")); // null
3119
+ """
3120
+ ...
3121
+
3122
+ def erase(self, key: Any) -> bool:
3123
+ """Remove key-value pair.
3124
+
3125
+ Args:
3126
+ key: The key to remove
3127
+
3128
+ Returns:
3129
+ True if key existed and was removed, False otherwise
3130
+
3131
+ Example:
3132
+ map<string, int> data;
3133
+ data.insert("x", 1);
3134
+ bool removed = data.erase("x"); // true
3135
+ bool again = data.erase("x"); // false (already gone)
3136
+ """
3137
+ ...
3138
+
3139
+ def contains(self, key: Any) -> bool:
3140
+ """Check if key exists.
3141
+
3142
+ Args:
3143
+ key: The key to check
3144
+
3145
+ Returns:
3146
+ True if key exists, False otherwise
3147
+
3148
+ Example:
3149
+ map<string, int> ages;
3150
+ ages.insert("Alice", 30);
3151
+ printl(ages.contains("Alice")); // true
3152
+ printl(ages.contains("Bob")); // false
3153
+ """
3154
+ ...
3155
+
3156
+ def count(self, key: Any) -> int:
3157
+ """Count occurrences of key (0 or 1 for map).
3158
+
3159
+ Returns:
3160
+ 1 if key exists, 0 otherwise
3161
+ """
3162
+ ...
3163
+
3164
+ def size(self) -> int:
3165
+ """Get number of key-value pairs.
3166
+
3167
+ Example:
3168
+ map<string, int> data;
3169
+ data.insert("a", 1);
3170
+ data.insert("b", 2);
3171
+ printl(data.size()); // 2
3172
+ """
3173
+ ...
3174
+
3175
+ def empty(self) -> bool:
3176
+ """Check if map has no elements.
3177
+
3178
+ Example:
3179
+ map<string, int> data;
3180
+ printl(data.empty()); // true
3181
+ data.insert("x", 1);
3182
+ printl(data.empty()); // false
3183
+ """
3184
+ ...
3185
+
3186
+ def at(self, key: Any) -> Any:
3187
+ """Get value at key (throws if not found).
3188
+
3189
+ Unlike find(), this throws an error if key doesn't exist.
3190
+
3191
+ Args:
3192
+ key: The key to access
3193
+
3194
+ Returns:
3195
+ The value at key
3196
+
3197
+ Raises:
3198
+ KeyError if key not found
3199
+
3200
+ Example:
3201
+ map<string, int> ages;
3202
+ ages.insert("Alice", 30);
3203
+ int age = ages.at("Alice"); // 30
3204
+ // ages.at("Bob"); // ERROR: Key not found
3205
+ """
3206
+ ...
3207
+
3208
+ def begin(self) -> Tuple[Any, Any]:
3209
+ """Get first key-value pair (smallest key).
3210
+
3211
+ Returns:
3212
+ Tuple of (key, value) or None if empty
3213
+
3214
+ Example:
3215
+ map<string, int> data;
3216
+ data.insert("banana", 2);
3217
+ data.insert("apple", 1);
3218
+ data.insert("cherry", 3);
3219
+ tuple first = data.begin(); // ("apple", 1)
3220
+ """
3221
+ ...
3222
+
3223
+ def end(self) -> Tuple[Any, Any]:
3224
+ """Get last key-value pair (largest key).
3225
+
3226
+ Returns:
3227
+ Tuple of (key, value) or None if empty
3228
+
3229
+ Example:
3230
+ map<string, int> data;
3231
+ data.insert("apple", 1);
3232
+ data.insert("cherry", 3);
3233
+ data.insert("banana", 2);
3234
+ tuple last = data.end(); // ("cherry", 3)
3235
+ """
3236
+ ...
3237
+
3238
+ def lower_bound(self, key: Any) -> Optional[Any]:
3239
+ """Find first key >= given key.
3240
+
3241
+ Useful for range queries on sorted keys.
3242
+
3243
+ Args:
3244
+ key: The key to search from
3245
+
3246
+ Returns:
3247
+ First key >= given key, or None if none found
3248
+
3249
+ Example:
3250
+ map<int, string> data;
3251
+ data.insert(10, "ten");
3252
+ data.insert(20, "twenty");
3253
+ data.insert(30, "thirty");
3254
+ printl(data.lower_bound(15)); // 20
3255
+ printl(data.lower_bound(20)); // 20
3256
+ """
3257
+ ...
3258
+
3259
+ def upper_bound(self, key: Any) -> Optional[Any]:
3260
+ """Find first key > given key.
3261
+
3262
+ Args:
3263
+ key: The key to search from
3264
+
3265
+ Returns:
3266
+ First key > given key, or None if none found
3267
+
3268
+ Example:
3269
+ map<int, string> data;
3270
+ data.insert(10, "ten");
3271
+ data.insert(20, "twenty");
3272
+ data.insert(30, "thirty");
3273
+ printl(data.upper_bound(15)); // 20
3274
+ printl(data.upper_bound(20)); // 30
3275
+ """
3276
+ ...
3277
+
3278
+
3279
+ class CSSLDataStruct:
3280
+ """CSSL datastruct<T> container - Universal flexible container.
3281
+
3282
+ DataStruct is a lazy declarator that can hold any type of data.
3283
+ It's the primary target container for BruteInjection operations.
3284
+
3285
+ Declaration in CSSL:
3286
+ datastruct<string> data;
3287
+ datastruct<int> numbers;
3288
+ datastruct<dynamic> anything;
3289
+
3290
+ Usage with BruteInjection:
3291
+ stack<string> source = ["A", "B", "C"];
3292
+ datastruct<string> target;
3293
+
3294
+ target +<== source; // Copy from source
3295
+ target +<== [string::contains="A"] source; // Filtered copy
3296
+
3297
+ Example:
3298
+ datastruct<string> names;
3299
+ names.add("Alice");
3300
+ names.add("Bob");
3301
+ printl(names.content()); // ["Alice", "Bob"]
3302
+ """
3303
+
3304
+ def content(self) -> List[T]:
3305
+ """Get all elements as a list.
3306
+
3307
+ Returns:
3308
+ List containing all elements
3309
+
3310
+ Example:
3311
+ datastruct<int> data;
3312
+ data.add(1);
3313
+ data.add(2);
3314
+ printl(data.content()); // [1, 2]
3315
+ """
3316
+ ...
3317
+
3318
+ def add(self, value: T) -> 'CSSLDataStruct':
3319
+ """Add an element to the datastruct.
3320
+
3321
+ Args:
3322
+ value: Element to add
3323
+
3324
+ Returns:
3325
+ The datastruct (for chaining)
3326
+
3327
+ Example:
3328
+ datastruct<string> data;
3329
+ data.add("first").add("second");
3330
+ """
3331
+ ...
3332
+
3333
+ def remove_where(self, predicate: Callable[[T], bool]) -> 'CSSLDataStruct':
3334
+ """Remove all elements matching predicate.
3335
+
3336
+ Args:
3337
+ predicate: Function returning True for items to remove
3338
+
3339
+ Returns:
3340
+ The datastruct (for chaining)
3341
+
3342
+ Example:
3343
+ datastruct<int> nums;
3344
+ nums.add(1);
3345
+ nums.add(2);
3346
+ nums.add(3);
3347
+ nums.remove_where(x => x > 1);
3348
+ printl(nums.content()); // [1]
3349
+ """
3350
+ ...
3351
+
3352
+ def find_where(self, predicate: Callable[[T], bool]) -> Optional[T]:
3353
+ """Find first element matching predicate.
3354
+
3355
+ Args:
3356
+ predicate: Function returning True for match
3357
+
3358
+ Returns:
3359
+ First matching element or None
3360
+
3361
+ Example:
3362
+ datastruct<int> nums = [5, 10, 15];
3363
+ int found = nums.find_where(x => x > 7); // 10
3364
+ """
3365
+ ...
3366
+
3367
+ def convert(self, target_type: type) -> Any:
3368
+ """Convert first element to target type.
3369
+
3370
+ Args:
3371
+ target_type: Type to convert to
3372
+
3373
+ Returns:
3374
+ Converted value or None if empty
3375
+ """
3376
+ ...
3377
+
3378
+ def begin(self) -> int:
3379
+ """Get iterator to first element (C++ style)."""
3380
+ ...
3381
+
3382
+ def end(self) -> int:
3383
+ """Get iterator past last element (C++ style)."""
3384
+ ...
3385
+
3386
+
3387
+ class CSSLIterator:
3388
+ """CSSL iterator<T, size> container - Advanced programmable iterator.
3389
+
3390
+ Iterator provides positions within a data container with the ability
3391
+ to attach tasks (functions) to specific positions. Can be nested
3392
+ for multi-dimensional structures.
3393
+
3394
+ Declaration in CSSL:
3395
+ iterator<int> it;
3396
+ iterator<int, 16> Map; // 16 positions
3397
+ iterator<iterator<int, 16>> Map2D; // 2D grid
3398
+
3399
+ Example:
3400
+ // 2D grid example
3401
+ iterator<iterator<int, 16>> Map;
3402
+ Map.insert(3, 12); // Set value 12 at position 3
3403
+ Map.fill(0); // Fill all with 0
3404
+ int value = Map.at(3); // Get value at position 3
3405
+ """
3406
+
3407
+ def insert(self, position: int, value: T) -> 'CSSLIterator':
3408
+ """Insert value at position.
3409
+
3410
+ Args:
3411
+ position: Index position
3412
+ value: Value to insert
3413
+
3414
+ Returns:
3415
+ The iterator (for chaining)
3416
+
3417
+ Example:
3418
+ iterator<int> it;
3419
+ it.insert(0, 100);
3420
+ it.insert(1, 200);
3421
+ """
3422
+ ...
3423
+
3424
+ def fill(self, value: T) -> 'CSSLIterator':
3425
+ """Fill all positions with value.
3426
+
3427
+ Args:
3428
+ value: Value to fill with
3429
+
3430
+ Returns:
3431
+ The iterator (for chaining)
3432
+
3433
+ Example:
3434
+ iterator<int, 10> grid;
3435
+ grid.fill(0); // All positions now 0
3436
+ """
3437
+ ...
3438
+
3439
+ def at(self, position: int) -> T:
3440
+ """Get value at position.
3441
+
3442
+ Args:
3443
+ position: Index position
3444
+
3445
+ Returns:
3446
+ Value at position
3447
+
3448
+ Example:
3449
+ iterator<int> it;
3450
+ it.insert(5, 42);
3451
+ printl(it.at(5)); // 42
3452
+ """
3453
+ ...
3454
+
3455
+ def set(self, position: int, value: T) -> 'CSSLIterator':
3456
+ """Set value at iterator position.
3457
+
3458
+ Args:
3459
+ position: Iterator index
3460
+ value: Value to set
3461
+
3462
+ Returns:
3463
+ The iterator (for chaining)
3464
+ """
3465
+ ...
3466
+
3467
+ def task(self, position: int, func: Callable) -> 'CSSLIterator':
3468
+ """Attach task (function) to iterator position.
3469
+
3470
+ Args:
3471
+ position: Iterator index
3472
+ func: Function to attach
3473
+
3474
+ Returns:
3475
+ The iterator (for chaining)
3476
+
3477
+ Example:
3478
+ iterator<int> it;
3479
+ it.task(0, myHandler); // Attach handler to position 0
3480
+ """
3481
+ ...
3482
+
3483
+
3484
+ class CSSLShuffled:
3485
+ """CSSL shuffled<T> container - Multi-value return container.
3486
+
3487
+ Shuffled is used with the 'shuffled' function keyword to enable
3488
+ functions to return multiple values. Values are unpacked using
3489
+ tuple assignment syntax.
3490
+
3491
+ Declaration in CSSL:
3492
+ shuffled getValues() {
3493
+ return "Alice", 30, true;
3494
+ }
3495
+
3496
+ Usage:
3497
+ shuffled string getNames() {
3498
+ return "first", "middle", "last";
3499
+ }
3500
+
3501
+ // Unpack all values
3502
+ a, b, c = getNames();
3503
+ printl(a); // "first"
3504
+ printl(b); // "middle"
3505
+ printl(c); // "last"
3506
+
3507
+ Example with mixed types:
3508
+ shuffled getData() {
3509
+ return "name", 42, 3.14, true;
3510
+ }
3511
+
3512
+ name, count, price, active = getData();
3513
+ printl(name); // "name"
3514
+ printl(count); // 42
3515
+ printl(price); // 3.14
3516
+ printl(active); // true
3517
+ """
3518
+ pass
3519
+
3520
+
3521
+ class CSSLCombo:
3522
+ """CSSL combo<T> container - Filter/search space for open parameters.
3523
+
3524
+ Combo is used for creating filtered search spaces, often in
3525
+ conjunction with 'open' parameter functions.
3526
+
3527
+ Declaration in CSSL:
3528
+ combo<string> searchSpace;
3529
+ combo<open&string> filter = combo<open&string>::like="pattern";
3530
+
3531
+ Example:
3532
+ combo<string> names;
3533
+ names.add("Alice");
3534
+ names.add("Bob");
3535
+ names.add("Anna");
3536
+
3537
+ // Use with filter pattern
3538
+ combo<open&string> filter = combo<open&string>::like="A*";
3539
+ """
3540
+ pass
3541
+
3542
+
3543
+ class CSSLDataSpace:
3544
+ """CSSL dataspace<T> container - SQL-like data storage.
3545
+
3546
+ DataSpace provides SQL-like operations for data manipulation.
3547
+ Used for complex data queries and transformations.
3548
+
3549
+ Declaration in CSSL:
3550
+ dataspace<sql::table> table;
3551
+
3552
+ Note: Advanced container for specialized data operations.
3553
+ """
3554
+ pass
3555
+
3556
+
3557
+ def OpenFind(type_or_combo: Any, index: int = 0) -> Optional[Any]:
3558
+ """Find parameter by type from open parameters.
3559
+
3560
+ Used inside functions declared with 'open' keyword to
3561
+ extract typed parameters from variadic argument list.
3562
+
3563
+ Args:
3564
+ type_or_combo: The type to search for (e.g., string, int)
3565
+ index: Which occurrence to get (0 = first, 1 = second, etc.)
3566
+
3567
+ Returns:
3568
+ The value at that index of that type, or None
3569
+
3570
+ Usage in CSSL:
3571
+ open define flexibleFunc(open Params) {
3572
+ string name = OpenFind<string>(0); // First string
3573
+ int num = OpenFind<int>(0); // First int
3574
+ float val = OpenFind<float>(1); // Second float
3575
+
3576
+ printl("Name: " + name);
3577
+ printl("Number: " + num);
3578
+ }
3579
+
3580
+ flexibleFunc("Hello", 42, 3.14, "World", 100);
3581
+ // name = "Hello" (first string)
3582
+ // num = 42 (first int)
3583
+ // val = (would need second float in args)
3584
+ """
1393
3585
  ...
3586
+
3587
+
3588
+ # =============================================================================
3589
+ # CONTAINER TYPE ALIASES (for direct lookup)
3590
+ # =============================================================================
3591
+ # These aliases allow looking up container methods directly by their CSSL name.
3592
+ # Example: typing "stack." shows all stack methods with documentation.
3593
+
3594
+ stack = CSSLStack
3595
+ """stack<T> - LIFO (Last In, First Out) container.
3596
+
3597
+ Methods:
3598
+ .push(value) Add element to top
3599
+ .pop() Remove and return top element
3600
+ .peek() View top without removing
3601
+ .isEmpty() Check if empty
3602
+ .size() Get element count
3603
+ .length() Alias for size()
3604
+ .contains(value) Check if value exists
3605
+ .indexOf(value) Find index of value
3606
+ .toArray() Convert to plain list
3607
+ .swap() Swap top two elements
3608
+ .dup() Duplicate top element
3609
+
3610
+ Example:
3611
+ stack<string> names;
3612
+ names.push("Alice");
3613
+ names.push("Bob");
3614
+ printl(names.pop()); // "Bob"
3615
+ printl(names.peek()); // "Alice"
3616
+ """
3617
+
3618
+ vector = CSSLVector
3619
+ """vector<T> - Dynamic resizable array with random access.
3620
+
3621
+ Methods:
3622
+ .push(value) Add to end
3623
+ .push_front(value) Add to front
3624
+ .pop_back() Remove last
3625
+ .pop_front() Remove first
3626
+ .at(index) Get element at index
3627
+ .set(index, value) Set element at index
3628
+ .front() Get first element
3629
+ .back() Get last element
3630
+ .size() Get element count
3631
+ .contains(value) Check if value exists
3632
+ .indexOf(value) Find index of value
3633
+ .slice(start, end) Get sub-vector
3634
+ .join(separator) Join to string
3635
+ .map(func) Transform elements
3636
+ .filter(predicate) Filter elements
3637
+ .forEach(func) Execute for each
3638
+ .every(predicate) Check all match
3639
+ .some(predicate) Check any match
3640
+ .reduce(func, init) Reduce to single value
3641
+
3642
+ Example:
3643
+ vector<int> nums;
3644
+ nums.push(10).push(20).push(30);
3645
+ printl(nums.at(1)); // 20
3646
+ printl(nums.front()); // 10
3647
+ printl(nums.back()); // 30
3648
+ """
3649
+
3650
+ array = CSSLArray
3651
+ """array<T> - Standard array with CSSL methods.
3652
+
3653
+ Methods:
3654
+ .push(value) Add to end
3655
+ .pop() Remove last
3656
+ .at(index) Get element at index
3657
+ .set(index, value) Set element at index
3658
+ .first() Get first element
3659
+ .last() Get last element
3660
+ .size() Get element count
3661
+ .length() Alias for size()
3662
+ .contains(value) Check if value exists
3663
+ .indexOf(value) Find index of value
3664
+ .slice(start, end) Get sub-array
3665
+ .join(separator) Join to string
3666
+ .map(func) Transform elements
3667
+ .filter(predicate) Filter elements
3668
+
3669
+ Example:
3670
+ array<string> colors;
3671
+ colors.push("red");
3672
+ colors.push("green");
3673
+ printl(colors.first()); // "red"
3674
+ printl(colors.length()); // 2
3675
+ """
3676
+
3677
+ map = CSSLMap
3678
+ """map<K, V> - C++ style ordered key-value container.
3679
+
3680
+ Methods:
3681
+ .insert(key, value) Insert or update key-value pair
3682
+ .find(key) Find value by key (returns None if not found)
3683
+ .erase(key) Remove key-value pair
3684
+ .contains(key) Check if key exists
3685
+ .at(key) Get value (throws if not found)
3686
+ .size() Get pair count
3687
+ .empty() Check if empty
3688
+ .begin() Get first (key, value) pair
3689
+ .end() Get last (key, value) pair
3690
+ .lower_bound(key) Find first key >= given key
3691
+ .upper_bound(key) Find first key > given key
3692
+
3693
+ Example:
3694
+ map<string, int> ages;
3695
+ ages.insert("Alice", 30);
3696
+ ages.insert("Bob", 25);
3697
+ printl(ages.find("Alice")); // 30
3698
+ printl(ages.contains("Bob")); // true
3699
+ ages.erase("Bob");
3700
+ """
3701
+
3702
+ datastruct = CSSLDataStruct
3703
+ """datastruct<T> - Universal container for BruteInjection operations.
3704
+
3705
+ Methods:
3706
+ .content() Get all elements as list
3707
+ .add(value) Add element
3708
+ .remove_where(pred) Remove matching elements
3709
+ .find_where(pred) Find first matching element
3710
+ .begin() Iterator to start
3711
+ .end() Iterator to end
3712
+
3713
+ Usage with BruteInjection:
3714
+ stack<string> source = ["A", "B", "C"];
3715
+ datastruct<string> target;
3716
+ target +<== source; // Copy all
3717
+ target +<== [string::contains="A"] source; // Filtered copy
3718
+
3719
+ Example:
3720
+ datastruct<string> data;
3721
+ data.add("Alice").add("Bob");
3722
+ printl(data.content()); // ["Alice", "Bob"]
3723
+ """
3724
+
3725
+ iterator = CSSLIterator
3726
+ """iterator<T, size> - Advanced programmable iterator container.
3727
+
3728
+ Methods:
3729
+ .insert(pos, value) Insert value at position
3730
+ .fill(value) Fill all positions with value
3731
+ .at(pos) Get value at position
3732
+ .set(pos, value) Set value at position
3733
+ .task(pos, func) Attach function to position
3734
+
3735
+ Example (2D grid):
3736
+ iterator<iterator<int, 16>> Map;
3737
+ Map.insert(3, 12); // Set value 12 at position 3
3738
+ Map.fill(0); // Fill all with 0
3739
+ int value = Map.at(3); // Get value at position 3
3740
+ """
3741
+
3742
+ shuffled = CSSLShuffled
3743
+ """shuffled<T> - Container for multi-value returns.
3744
+
3745
+ Used with 'shuffled' function keyword to return multiple values.
3746
+ Values are unpacked using tuple assignment syntax.
3747
+
3748
+ Example:
3749
+ shuffled string getNames() {
3750
+ return "first", "middle", "last";
3751
+ }
3752
+
3753
+ a, b, c = getNames();
3754
+ printl(a); // "first"
3755
+ printl(b); // "middle"
3756
+ printl(c); // "last"
3757
+
3758
+ // Mixed types
3759
+ shuffled getData() {
3760
+ return "name", 42, true;
3761
+ }
3762
+ name, count, flag = getData();
3763
+ """
3764
+
3765
+ combo = CSSLCombo
3766
+ """combo<T> - Filter/search space for open parameters.
3767
+
3768
+ Example:
3769
+ combo<string> searchSpace;
3770
+ combo<open&string> filter = combo<open&string>::like="A*";
3771
+ """
3772
+
3773
+ dataspace = CSSLDataSpace
3774
+ """dataspace<T> - SQL-like data storage container.
3775
+
3776
+ Example:
3777
+ dataspace<sql::table> table;
3778
+ """
3779
+
3780
+
3781
+ # =============================================================================
3782
+ # FUNCTION KEYWORDS (for defining functions)
3783
+ # =============================================================================
3784
+
3785
+ class FunctionKeywords:
3786
+ """
3787
+ CSSL Function Keywords - Special modifiers for function definitions.
3788
+
3789
+ These are not callable functions but keywords used when defining functions.
3790
+ """
3791
+
3792
+ def void(self) -> None:
3793
+ """Function without return value.
3794
+
3795
+ Example:
3796
+ void sayHello() {
3797
+ printl("Hello!");
3798
+ }
3799
+ """
3800
+ ...
3801
+
3802
+ def define(self) -> None:
3803
+ """Constant function without type declaration.
3804
+
3805
+ Does not require return type or 'void'. Used for simple procedures.
3806
+
3807
+ Example:
3808
+ define LOG_MESSAGE() {
3809
+ printl("Log entry");
3810
+ }
3811
+
3812
+ define processData() {
3813
+ // do something
3814
+ }
3815
+ """
3816
+ ...
3817
+
3818
+ def undefined(self) -> None:
3819
+ """Function that silently ignores errors.
3820
+
3821
+ Any exceptions during execution are caught and ignored.
3822
+ Useful for optional operations that may fail.
3823
+
3824
+ Example:
3825
+ undefined void mayFail() {
3826
+ riskyOperation(); // Errors ignored
3827
+ }
3828
+ mayFail(); // Won't crash even if error occurs
3829
+ """
3830
+ ...
3831
+
3832
+ def closed(self) -> None:
3833
+ """Function protected from EXTERNAL code injection.
3834
+
3835
+ Prevents external scripts from using <<== to modify this function.
3836
+ Internal injections (same file) still work.
3837
+
3838
+ Example:
3839
+ closed void protectedFunc() {
3840
+ printl("Protected from external injection");
3841
+ }
3842
+
3843
+ // This will be BLOCKED if from different file:
3844
+ protectedFunc() <<== { printl("Blocked!"); }
3845
+ """
3846
+ ...
3847
+
3848
+ def private(self) -> None:
3849
+ """Function with ALL injections blocked.
3850
+
3851
+ Completely protects function from any CodeInfusion.
3852
+ No <<==, +<<==, or -<<== operations will work.
3853
+
3854
+ Example:
3855
+ private void superSecure() {
3856
+ printl("Cannot be modified");
3857
+ }
3858
+ """
3859
+ ...
3860
+
3861
+ def virtual(self) -> None:
3862
+ """Function safe for import cycles.
3863
+
3864
+ Prevents infinite recursion when modules import each other.
3865
+
3866
+ Example:
3867
+ virtual void safeForImport() {
3868
+ // Safe to call from circular imports
3869
+ }
3870
+ """
3871
+ ...
3872
+
3873
+ def meta(self) -> None:
3874
+ """Function declared as source provider (must return).
3875
+
3876
+ Indicates function provides metadata or source information.
3877
+
3878
+ Example:
3879
+ meta string getSource() {
3880
+ return "source code here";
3881
+ }
3882
+ """
3883
+ ...
3884
+
3885
+ def super_keyword(self) -> None:
3886
+ """Function that forces execution without exceptions.
3887
+
3888
+ Function will complete even if errors occur internally.
3889
+
3890
+ Example:
3891
+ super void forceRun() {
3892
+ printl("Will ALWAYS complete");
3893
+ }
3894
+ """
3895
+ ...
3896
+
3897
+ def shuffled_keyword(self) -> None:
3898
+ """Function that can return multiple values.
3899
+
3900
+ Return statement can have comma-separated values.
3901
+ Caller can unpack using tuple assignment.
3902
+
3903
+ Example:
3904
+ shuffled string getNames() {
3905
+ return "Alice", "Bob", "Charlie";
3906
+ }
3907
+
3908
+ // Unpack all values
3909
+ a, b, c = getNames();
3910
+
3911
+ // Or with mixed types
3912
+ shuffled getValues() {
3913
+ return "hello", 42, true;
3914
+ }
3915
+ text, num, flag = getValues();
3916
+ """
3917
+ ...
3918
+
3919
+ def open(self) -> None:
3920
+ """Function that accepts any number/type of parameters.
3921
+
3922
+ Use with 'open Params' to accept variadic arguments.
3923
+ Use OpenFind<type>(index) to extract typed values.
3924
+
3925
+ Example:
3926
+ open define flexibleFunc(open Params) {
3927
+ string name = OpenFind<string>(0);
3928
+ int count = OpenFind<int>(0);
3929
+ printl("Name: " + name + ", Count: " + count);
3930
+ }
3931
+
3932
+ flexibleFunc("Alice", 42, true, "extra");
3933
+ // Extracts: name="Alice", count=42
3934
+ """
3935
+ ...
3936
+
3937
+ # =============================================================================
3938
+ # CLASSES & OOP
3939
+ # =============================================================================
3940
+
3941
+ class ClassSyntax:
3942
+ """
3943
+ CSSL Class Syntax - Object-Oriented Programming support.
3944
+
3945
+ CSSL supports classes with constructors, members, and methods.
3946
+ Use 'this->' to access instance members inside methods.
3947
+ Use 'new' keyword to instantiate classes.
3948
+ """
3949
+
3950
+ def class_definition(self) -> None:
3951
+ """Define a class with members and methods.
3952
+
3953
+ Example:
3954
+ class Person {
3955
+ // Member variables
3956
+ string name;
3957
+ int age;
3958
+
3959
+ // Constructor (same name as class)
3960
+ void Person(string n, int a) {
3961
+ this->name = n;
3962
+ this->age = a;
3963
+ }
3964
+
3965
+ // Methods
3966
+ void greet() {
3967
+ printl("Hello, I'm " + this->name);
3968
+ }
3969
+
3970
+ string getName() {
3971
+ return this->name;
3972
+ }
3973
+
3974
+ void setAge(int a) {
3975
+ this->age = a;
3976
+ }
3977
+ }
3978
+ """
3979
+ ...
3980
+
3981
+ def new_keyword(self) -> None:
3982
+ """Instantiate a class using 'new' keyword.
3983
+
3984
+ Example:
3985
+ Person p = new Person("Alice", 30);
3986
+ p.greet(); // "Hello, I'm Alice"
3987
+ string name = p.getName(); // "Alice"
3988
+ p.setAge(31);
3989
+ """
3990
+ ...
3991
+
3992
+ def this_keyword(self) -> None:
3993
+ """Access instance members with 'this->' inside methods.
3994
+
3995
+ Example:
3996
+ class Counter {
3997
+ int count;
3998
+
3999
+ void Counter() {
4000
+ this->count = 0;
4001
+ }
4002
+
4003
+ void increment() {
4004
+ this->count = this->count + 1;
4005
+ }
4006
+
4007
+ int get() {
4008
+ return this->count;
4009
+ }
4010
+ }
4011
+ """
4012
+ ...
4013
+
4014
+ # =============================================================================
4015
+ # SPECIAL SYNTAX REFERENCE
4016
+ # =============================================================================
4017
+
4018
+ class SpecialSyntax:
4019
+ """
4020
+ CSSL Special Syntax Reference
4021
+
4022
+ Reference for CSSL-specific syntax elements.
4023
+ """
4024
+
4025
+ def global_variables(self) -> None:
4026
+ """Global variable syntax.
4027
+
4028
+ Declare with 'global' keyword, access with '@' prefix.
4029
+
4030
+ Example:
4031
+ // Declaration
4032
+ global myGlobal = "visible everywhere";
4033
+ r@anotherGlobal = "alternative syntax";
4034
+
4035
+ // Access
4036
+ printl(@myGlobal);
4037
+ @myGlobal = "new value";
4038
+
4039
+ // In functions
4040
+ void increment() {
4041
+ @counter = @counter + 1;
4042
+ }
4043
+ """
4044
+ ...
4045
+
4046
+ def shared_objects(self) -> None:
4047
+ """Shared Python object syntax ($name).
4048
+
4049
+ Access Python objects shared via CSSL.share().
4050
+ Changes reflect back to Python.
4051
+
4052
+ Example:
4053
+ // Python: cssl.share(myObj, "data")
4054
+
4055
+ // CSSL:
4056
+ $data.property = "value";
4057
+ $data.method();
4058
+ printl($data.result);
4059
+
4060
+ // Delete when done
4061
+ delete("data");
4062
+ """
4063
+ ...
4064
+
4065
+ def captured_references(self) -> None:
4066
+ """Value capture syntax (%identifier).
4067
+
4068
+ Captures value at registration time, not execution time.
4069
+ Useful for saving original functions before replacement.
4070
+
4071
+ Example:
4072
+ string version = "1.0";
4073
+ savedVersion <== { %version; }
4074
+ version = "2.0";
4075
+ printl(savedVersion); // Still "1.0"
4076
+
4077
+ // Save original function
4078
+ originalExit <<== { %exit(); }
4079
+ exit() <<== {
4080
+ printl("Custom exit");
4081
+ originalExit(); // Call saved original
4082
+ }
4083
+ """
4084
+ ...
4085
+
4086
+ def code_infusion(self) -> None:
4087
+ """CodeInfusion operators for modifying functions.
4088
+
4089
+ IMPORTANT: Write operators WITHOUT spaces!
4090
+
4091
+ Operators:
4092
+ <<== Replace function content
4093
+ +<<== Add code BEFORE original
4094
+ -<<== Remove matching code
4095
+
4096
+ Example:
4097
+ void original() { printl("Original"); }
4098
+
4099
+ // Replace
4100
+ original() <<== { printl("Replaced"); }
4101
+
4102
+ // Add before
4103
+ original() +<<== { printl("Before"); }
4104
+
4105
+ // Remove code
4106
+ original() -<<== { printl("Unwanted"); }
4107
+ """
4108
+ ...
4109
+
4110
+ def brute_injection(self) -> None:
4111
+ """BruteInjection operators for data transfer.
4112
+
4113
+ Operators:
4114
+ +<== Copy data (source unchanged)
4115
+ -<== Move data (removes from source)
4116
+ ==> Replace target data
4117
+ ==>- Remove matching items from target
4118
+
4119
+ Example:
4120
+ stack<string> source = ["A", "B", "C"];
4121
+ datastruct<string> target;
4122
+
4123
+ target +<== source; // Copy
4124
+ target -<== source; // Move (source empty)
4125
+ target ==> newData; // Replace
4126
+ target ==>- ["A"]; // Remove "A" from target
4127
+
4128
+ // With filters
4129
+ target +<== [string::contains="X"] source;
4130
+ """
4131
+ ...
4132
+
4133
+ def filter_syntax(self) -> None:
4134
+ """Filter syntax for BruteInjection.
4135
+
4136
+ Format: [type::filter=value]
4137
+
4138
+ String filters:
4139
+ string::where="value" Exact match
4140
+ string::not="value" Exclude
4141
+ string::contains="sub" Contains substring
4142
+ string::length=5 Exact length
4143
+ string::cut=3 First N chars
4144
+ string::cutAfter="sub" After substring
4145
+
4146
+ Example:
4147
+ stack<string> names = ["Alice", "Bob", "Anna"];
4148
+ datastruct<string> result;
4149
+ result +<== [string::contains="A"] names;
4150
+ // result = ["Alice", "Anna"]
4151
+ """
4152
+ ...
4153
+
4154
+ # =============================================================================
4155
+ # EXPORTS
4156
+ # =============================================================================
4157
+
4158
+ __all__ = [
4159
+ # Output
4160
+ "print", "printl", "println", "debug", "error", "warn", "log",
4161
+ # Type conversion
4162
+ "int", "float", "str", "bool", "list", "dict",
4163
+ # Type checking
4164
+ "typeof", "isinstance", "isint", "isfloat", "isstr", "isbool",
4165
+ "islist", "isdict", "isnull",
4166
+ # String
4167
+ "len", "upper", "lower", "trim", "ltrim", "rtrim", "split", "join",
4168
+ "replace", "substr", "contains", "startswith", "endswith", "format",
4169
+ "concat", "repeat", "reverse", "indexof", "lastindexof", "padleft",
4170
+ "padright", "capitalize", "title", "swapcase", "center", "zfill",
4171
+ "chars", "ord", "chr", "isalpha", "isdigit", "isalnum", "isspace",
4172
+ "sprintf",
4173
+ # Array/List
4174
+ "push", "pop", "shift", "unshift", "slice", "sort", "rsort",
4175
+ "unique", "flatten", "filter", "map", "reduce", "find", "findindex",
4176
+ "every", "some", "range", "enumerate", "zip", "reversed", "count",
4177
+ "first", "last", "take", "drop", "chunk", "shuffle", "sample",
4178
+ # Dictionary
4179
+ "keys", "values", "items", "haskey", "getkey", "setkey", "delkey",
4180
+ "merge", "update", "fromkeys", "invert", "pick", "omit", "groupby",
4181
+ # Math
4182
+ "abs", "min", "max", "sum", "avg", "round", "floor", "ceil",
4183
+ "pow", "sqrt", "mod", "random", "randint", "sin", "cos", "tan",
4184
+ "asin", "acos", "atan", "atan2", "log", "log10", "exp", "pi", "e",
4185
+ "radians", "degrees",
4186
+ # Date/Time
4187
+ "now", "timestamp", "sleep", "delay", "date", "time", "datetime",
4188
+ "strftime",
4189
+ # File System
4190
+ "read", "readline", "write", "writeline", "appendfile", "readlines",
4191
+ "pathexists", "isfile", "isdir", "listdir", "makedirs", "removefile",
4192
+ "removedir", "copyfile", "movefile", "filesize", "basename", "dirname",
4193
+ "joinpath", "abspath", "normpath", "splitpath",
4194
+ # JSON (json:: namespace)
4195
+ "json_read", "json_write", "json_parse", "json_stringify", "json_pretty",
4196
+ "json_get", "json_set", "json_has", "json_keys", "json_values", "json_merge",
4197
+ # Instance (instance:: namespace)
4198
+ "instance_getMethods", "instance_getClasses", "instance_getVars",
4199
+ "instance_getAll", "instance_call", "instance_has", "instance_type",
4200
+ "isavailable",
4201
+ # Regex
4202
+ "match", "search", "findall", "sub",
4203
+ # Hash
4204
+ "md5", "sha1", "sha256",
4205
+ # System/Control
4206
+ "exit", "input", "env", "setenv", "clear", "copy", "deepcopy",
4207
+ "assert_condition", "pyimport", "include", "payload", "color",
4208
+ "original", "delete",
4209
+ # Platform
4210
+ "isLinux", "isWindows", "isMac",
4211
+ # Container Classes (with methods)
4212
+ "CSSLStack", "CSSLVector", "CSSLArray", "CSSLMap", "CSSLDataStruct",
4213
+ "CSSLIterator", "CSSLShuffled", "CSSLCombo", "CSSLDataSpace", "OpenFind",
4214
+ # Container Type Aliases (use these for quick method lookup)
4215
+ "stack", "vector", "array", "map", "datastruct", "iterator", "shuffled", "combo", "dataspace",
4216
+ # Syntax Reference Classes
4217
+ "FunctionKeywords", "ClassSyntax", "SpecialSyntax",
4218
+ ]