diff options
Diffstat (limited to 'js/scripting-lang/tests/repl_demo.txt')
-rw-r--r-- | js/scripting-lang/tests/repl_demo.txt | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/js/scripting-lang/tests/repl_demo.txt b/js/scripting-lang/tests/repl_demo.txt new file mode 100644 index 0000000..c96f911 --- /dev/null +++ b/js/scripting-lang/tests/repl_demo.txt @@ -0,0 +1,180 @@ +/* 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"; \ No newline at end of file |