about summary refs log tree commit diff stats
path: root/js/scripting-lang/c/test_copy.txt
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/c/test_copy.txt')
-rw-r--r--js/scripting-lang/c/test_copy.txt64
1 files changed, 64 insertions, 0 deletions
diff --git a/js/scripting-lang/c/test_copy.txt b/js/scripting-lang/c/test_copy.txt
new file mode 100644
index 0000000..a67bf59
--- /dev/null
+++ b/js/scripting-lang/c/test_copy.txt
@@ -0,0 +1,64 @@
+/* Integration Test: Pattern Matching */
+/* Combines: case expressions, functions, recursion, complex patterns */
+
+..out "=== Integration Test: Pattern Matching ===";
+
+/* Recursive factorial with case expressions */
+factorial : n -> 
+  when n is
+    0 then 1
+    _ then n * (factorial (n - 1));
+
+/* Pattern matching with multiple parameters */
+classify : x y -> 
+  when x y is
+    0 0 then "both zero"
+    0 _ then "x is zero"
+    _ 0 then "y is zero"
+    _ _ then when x is
+            0 then "x is zero (nested)"
+            _ then when y is
+                  0 then "y is zero (nested)"
+                  _ then "neither zero";
+
+/* Test factorial */
+fact5 : factorial 5;
+fact3 : factorial 3;
+
+..assert fact5 = 120;
+..assert fact3 = 6;
+
+/* Test classification */
+test1 : classify 0 0;
+test2 : classify 0 5;
+test3 : classify 5 0;
+test4 : classify 5 5;
+
+..assert test1 = "both zero";
+..assert test2 = "x is zero";
+..assert test3 = "y is zero";
+..assert test4 = "neither zero";
+
+/* Complex nested case expressions */
+analyze : x y z -> 
+  when x y z is
+    0 0 0 then "all zero"
+    0 0 _ then "x and y zero"
+    0 _ 0 then "x and z zero"
+    _ 0 0 then "y and z zero"
+    0 _ _ then "only x zero"
+    _ 0 _ then "only y zero"
+    _ _ 0 then "only z zero"
+    _ _ _ then "none zero";
+
+result1 : analyze 0 0 0;
+result2 : analyze 0 1 1;
+result3 : analyze 1 0 1;
+result4 : analyze 1 1 1;
+
+..assert result1 = "all zero";
+..assert result2 = "only x zero";
+..assert result3 = "only y zero";
+..assert result4 = "none zero";
+
+..out "Pattern matching integration test completed"; 
\ No newline at end of file
enos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* REPL Demo - Comprehensive Language Feature Showcase */

/* ===== BASIC OPERATIONS ===== */
/* Arithmetic and function application */
x : 5;
y : 10;
sum : x + y;
product : x * y;
difference : y - x;
quotient : y / x;

/* Function application and partial application */
double : multiply 2;
triple : multiply 3;
add5 : add 5;
result1 : double 10;
result2 : add5 15;

/* ===== TABLE OPERATIONS ===== */
/* Array-like tables */
numbers : {1, 2, 3, 4, 5};
fruits : {"apple", "banana", "cherry", "date"};

/* Key-value tables */
person : {name: "Alice", age: 30, active: true, skills: {"JavaScript", "Python", "Rust"}};
config : {debug: true, port: 3000, host: "localhost"};

/* Mixed tables */
mixed : {1, name: "Bob", 2, active: false, 3, "value"};

/* Table access */
first_number : numbers[1];
person_name : person.name;
mixed_name : mixed.name;

/* ===== FUNCTIONAL PROGRAMMING ===== */
/* Higher-order functions */
doubled_numbers : map @double numbers;
filtered_numbers : filter @(lessThan 3) numbers;
sum_of_numbers : reduce @add 0 numbers;

/* Function composition */
compose_example : double via add5 via negate;
result3 : compose_example 10;

/* Pipeline operations */
pipeline : numbers via map @double via filter @(greaterThan 5) via reduce @add 0;

/* ===== PATTERN MATCHING ===== */
/* When expressions */
grade : 85;
letter_grade : when grade {
    >= 90: "A";
    >= 80: "B";
    >= 70: "C";
    >= 60: "D";
    default: "F";
};

/* Complex pattern matching */
status : "active";
access_level : when status {
    "admin": "full";
    "moderator": "limited";
    "user": "basic";
    default: "none";
};

/* ===== ADVANCED COMBINATORS ===== */
/* Combinator examples */
numbers2 : {2, 4, 6, 8, 10};
evens : filter @(equals 0 via modulo 2) numbers2;
squares : map @(power 2) numbers2;
sum_squares : reduce @add 0 squares;

/* Function composition with combinators */
complex_pipeline : numbers via 
    map @(multiply 2) via 
    filter @(greaterThan 5) via 
    map @(power 2) via 
    reduce @add 0;

/* ===== TABLE ENHANCEMENTS ===== */
/* Table transformations */
users : {
    user1: {name: "Alice", age: 25, role: "admin"},
    user2: {name: "Bob", age: 30, role: "user"},
    user3: {name: "Charlie", age: 35, role: "moderator"}
};

/* Extract specific fields */
names : map @(constant "name") users;
ages : map @(constant "age") users;

/* Filter by conditions */
admins : filter @(equals "admin" via constant "role") users;
young_users : filter @(lessThan 30 via constant "age") users;

/* ===== REAL-WORLD EXAMPLES ===== */
/* Data processing pipeline */
data : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
processed : data via 
    filter @(greaterThan 5) via 
    map @(multiply 3) via 
    filter @(lessThan 25);

/* Configuration management */
default_config : {port: 3000, host: "localhost", debug: false};
user_config : {port: 8080, debug: true};
merged_config : merge default_config user_config;

/* ===== ERROR HANDLING EXAMPLES ===== */
/* Safe operations */
safe_divide : (x, y) => when y {
    0: "Error: Division by zero";
    default: x / y;
};

safe_result1 : safe_divide 10 2;
safe_result2 : safe_divide 10 0;

/* ===== PERFORMANCE EXAMPLES ===== */
/* Large dataset processing */
large_numbers : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
processed_large : large_numbers via 
    map @(power 2) via 
    filter @(greaterThan 50) via 
    reduce @add 0;

/* ===== DEBUGGING EXAMPLES ===== */
/* State inspection helpers */
debug_state : {
    numbers: numbers,
    person: person,
    processed: processed,
    config: merged_config
};

/* ===== EXPORT EXAMPLES ===== */
/* Exportable configurations */
export_config : {
    version: "1.0.0",
    features: {"tables", "functions", "pattern-matching"},
    examples: {
        basic: "Basic arithmetic and function application",
        advanced: "Complex functional pipelines",
        real_world: "Data processing examples"
    }
};

/* ===== COMPREHENSIVE SHOWCASE ===== */
/* This demonstrates all major language features in one pipeline */
comprehensive_example : {
    input: numbers,
    doubled: map @double numbers,
    filtered: filter @(greaterThan 3) numbers,
    composed: double via add5 via negate,
    pattern_matched: when (length numbers) {
        > 5: "Large dataset";
        > 3: "Medium dataset";
        default: "Small dataset";
    },
    final_result: numbers via 
        map @(multiply 2) via 
        filter @(greaterThan 5) via 
        reduce @add 0
};

/* Output results for verification */
..out "REPL Demo completed successfully!";
..out "All language features demonstrated:";
..out "  ✓ Basic operations and arithmetic";
..out "  ✓ Table literals and access";
..out "  ✓ Function application and composition";
..out "  ✓ Pattern matching with when expressions";
..out "  ✓ Higher-order functions and combinators";
..out "  ✓ Table transformations and pipelines";
..out "  ✓ Real-world data processing examples";
..out "  ✓ Error handling and safe operations";
..out "  ✓ Performance and debugging features";