{"id":30876210,"url":"https://github.com/client9/cardinal","last_synced_at":"2025-10-30T19:04:11.040Z","repository":{"id":305197770,"uuid":"1021875880","full_name":"client9/cardinal","owner":"client9","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-05T06:44:34.000Z","size":1477,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-05T07:07:45.378Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/client9.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-18T05:02:47.000Z","updated_at":"2025-09-05T06:44:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"c5bb009d-14e7-481d-9554-6f6b5a9b3670","html_url":"https://github.com/client9/cardinal","commit_stats":null,"previous_names":["client9/sexpr","client9/cardinal"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/client9/cardinal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/client9%2Fcardinal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/client9%2Fcardinal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/client9%2Fcardinal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/client9%2Fcardinal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/client9","download_url":"https://codeload.github.com/client9/cardinal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/client9%2Fcardinal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274121957,"owners_count":25225801,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-08T02:07:59.665Z","updated_at":"2025-10-30T19:04:10.986Z","avatar_url":"https://github.com/client9.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cardinal - symbolic programming language, in Go\n\n## Features\n\n- **Complete S-Expression Parser** - Supports atoms (numbers, strings, booleans, symbols) and nested lists\n- **Context-Based Architecture** - Isolated evaluator instances with no global state interference\n- **Attribute System** - Full support for symbol attributes (HoldAll, Flat, Orderless, OneIdentity, etc.)\n- **Thread-Safe Design** - Multiple evaluators can run concurrently without interference\n- **Expression Evaluator** - Evaluates expressions with support for:\n  - Arithmetic operations (Plus, Times, Subtract, Divide, Power)\n  - Comparison operations (Equal, Less, Greater, etc.)\n  - Logical operations (And, Or, Not)\n  - Control structures (If, Hold, Evaluate)\n  - Variable assignment (Set, SetDelayed, Unset)\n  - Built-in constants (Pi, E, True, False)\n- **Interactive REPL** - Read-Eval-Print Loop for interactive computation\n- **Infix Notation Support** - Standard mathematical operators (+, -, *, /, ==, \u003c, \u003e, etc.)\n\n## Installation\n\n```bash\ngo get github.com/client9/cardinal\n```\n\n## Usage\n\n### As a Library\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/client9/cardinal\"\n)\n\nfunc main() {\n    // Create a REPL instance\n    repl := sexpr.NewREPL()\n    \n    // Evaluate expressions\n    result, _ := repl.EvaluateString(\"1 + 2 * 3\")\n    fmt.Println(\"1 + 2 * 3 =\", result) // Output: 7\n    \n    result, _ = repl.EvaluateString(\"x = 5\")\n    fmt.Println(\"x =\", result) // Output: 5\n    \n    result, _ = repl.EvaluateString(\"If(x \u003e 3, \\\"big\\\", \\\"small\\\")\")\n    fmt.Println(\"Result:\", result) // Output: \"big\"\n}\n```\n\n### Interactive REPL\n\nBuild and run the interactive REPL:\n\n```bash\ngo build -o cardinal ./cmd/cardinal\n./cardinal\n```\n\nExample session:\n```\nS-Expression REPL v1.0\nType 'quit' or 'exit' to exit, 'help' for help\n\nsexpr\u003e 1 + 2 * 3\n7\nsexpr\u003e x = 10\n10\nsexpr\u003e y = 20\n20\nsexpr\u003e And(x \u003e 5, y \u003c 25)\nTrue\nsexpr\u003e If(x \u003e y, \"x wins\", \"y wins\")\n\"y wins\"\nsexpr\u003e Plus(1, 2, 3, 4, 5)\n15\nsexpr\u003e Hold(1 + 2)\nHold(Plus(1, 2))\nsexpr\u003e Pi\n3.141592653589793\nsexpr\u003e quit\nGoodbye!\n```\n\n### File Execution\n\nExecute expressions from a file:\n\n```bash\n./repl -file examples.sexpr\n```\n\n### REPL Commands\n\n- `help` - Show help information\n- `quit` or `exit` - Exit the REPL\n- `clear` - Clear all variable assignments\n- `attributes` - Show all symbols with their attributes\n\n## Expression Syntax\n\n### Function Calls\n```\nPlus(1, 2, 3)\nTimes(2, x, 4)\nGreater(5, 3)\n```\n\n### Infix Notation\n```\n1 + 2 * 3        # Arithmetic\nx == 5           # Equality\nx \u003e y \u0026\u0026 y \u003c 10  # Logical operations\n```\n\n### Variable Assignment\n```\nx = 5            # Immediate assignment\ny := 2 * x       # Delayed assignment\n```\n\n### Control Structures\n```\nIf(condition, then, else)\nHold(expression)\nEvaluate(expression)\n```\n\n### Built-in Functions\n\n#### Arithmetic\n- `Plus(...)` - Addition\n- `Times(...)` - Multiplication  \n- `Subtract(a, b)` - Subtraction\n- `Divide(a, b)` - Division\n- `Power(base, exp)` - Exponentiation\n\n#### Comparison\n- `Equal(a, b)` - Equality test\n- `Less(a, b)` - Less than\n- `Greater(a, b)` - Greater than\n- `LessEqual(a, b)` - Less than or equal\n- `GreaterEqual(a, b)` - Greater than or equal\n- `SameQ(a, b)` - Identity test\n\n#### Logical\n- `And(...)` - Logical AND\n- `Or(...)` - Logical OR\n- `Not(x)` - Logical NOT\n\n#### Control\n- `If(cond, then, else)` - Conditional expression\n- `Hold(expr)` - Prevent evaluation\n- `Evaluate(expr)` - Force evaluation\n\n#### Assignment\n- `Set(var, value)` - Immediate assignment\n- `SetDelayed(var, value)` - Delayed assignment\n- `Unset(var)` - Remove variable\n\n### Attributes\n\nThe system supports Mathematica-style attributes that control evaluation:\n\n- **HoldAll** - Prevent evaluation of all arguments\n- **HoldFirst** - Prevent evaluation of first argument\n- **HoldRest** - Prevent evaluation of all but first argument\n- **Flat** - Flatten nested applications (associativity)\n- **Orderless** - Sort arguments (commutativity)\n- **OneIdentity** - f[x) → x for single arguments\n\nExample:\n```\nsexpr\u003e attributes\nSymbols with attributes:\n===============================\nAnd            : {Flat, HoldAll, Orderless}\nBlock          : {HoldAll}\nCompoundExpression: {HoldAll}\nE              : {Constant, Protected}\nFalse          : {Constant, Protected}\nHold           : {HoldAll}\nIf             : {HoldRest}\nModule         : {HoldAll}\nOr             : {Flat, HoldAll, Orderless}\nPi             : {Constant, Protected}\nPlus           : {Flat, OneIdentity, Orderless}\nPower          : {OneIdentity}\nSet            : {HoldFirst}\nSetDelayed     : {HoldAll}\nTimes          : {Flat, OneIdentity, Orderless}\nTrue           : {Constant, Protected}\nUnset          : {HoldFirst}\nWhile          : {HoldAll}\n```\n\n## Examples\n\nSee `examples.sexpr` for more examples:\n\n```bash\n# Arithmetic with precedence\n1 + 2 * 3                    # → 7\n\n# Function calls\nPlus(1, 2, 3, 4, 5)          # → 15\n\n# Variables and assignments\nx = 10                       # → 10\ny = 20                       # → 20\nz = x + y                    # → 30\n\n# Comparisons\nx \u003e y                        # → False\nEqual(x, 10)                 # → True\n\n# Logical operations\nAnd(True, False)             # → False\nOr(False, True)              # → True\nAnd(x \u003e 5, y \u003c 25)          # → True\n\n# Conditionals\nIf(x \u003e y, \"x is greater\", \"y is greater\")  # → \"y is greater\"\n\n# Mathematical constants\nPi                           # → 3.141592653589793\nE                            # → 2.718281828459045\n\n# Attribute demonstrations\nPlus(1, Plus(2, 3))          # → 6 (Flat attribute)\nPlus(3, 1, 2)                # → 6 (Orderless attribute)\nPlus(42)                     # → 42 (OneIdentity attribute)\n\n# Hold expressions\nHold(1 + 2)                  # → Hold(Plus(1, 2))\n```\n\n## Testing\n\nRun the test suite:\n\n```bash\ngo test -v\n```\n\n## License\n\nThis project is open source. See the source code for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclient9%2Fcardinal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclient9%2Fcardinal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclient9%2Fcardinal/lists"}