{"id":18439065,"url":"https://github.com/demonstrandum/crepl","last_synced_at":"2025-04-07T21:32:11.735Z","repository":{"id":96636215,"uuid":"274903983","full_name":"Demonstrandum/crepl","owner":"Demonstrandum","description":"An intuitive calculator Read-Eval-Print-Loop.","archived":false,"fork":false,"pushed_at":"2025-01-04T00:16:16.000Z","size":203,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T00:51:20.282Z","etag":null,"topics":["c","calculator","compiler","interpreter","math","mathematics","numerical","parser","repl"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Demonstrandum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2020-06-25T11:54:14.000Z","updated_at":"2025-01-04T00:16:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"d2a48c8b-9130-4632-8f1e-0ab446c62943","html_url":"https://github.com/Demonstrandum/crepl","commit_stats":{"total_commits":40,"total_committers":3,"mean_commits":"13.333333333333334","dds":"0.32499999999999996","last_synced_commit":"e3829fe46479a53b8f70dd74a613b67c40d3668b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Demonstrandum%2Fcrepl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Demonstrandum%2Fcrepl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Demonstrandum%2Fcrepl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Demonstrandum%2Fcrepl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Demonstrandum","download_url":"https://codeload.github.com/Demonstrandum/crepl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247732641,"owners_count":20986893,"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","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":["c","calculator","compiler","interpreter","math","mathematics","numerical","parser","repl"],"created_at":"2024-11-06T06:23:14.909Z","updated_at":"2025-04-07T21:32:11.725Z","avatar_url":"https://github.com/Demonstrandum.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CREPL\n\u003e **C**alculator **REPL**\n\nA command line calculator read-eval-print-loop,\nwith intuitive mathematical notation as syntax.\n\n## Install\n\nYou'll need `git` (if cloning), a C compiler (e.g. `gcc`),\nthe GNU readline library, and `make` (`build-essential` / `base-devel`).\n\n### Clone\nClone / Download this repositroy however you like, e.g.\n```sh\ngit clone \"https://github.com/Demonstrandum/crepl.git\"\n```\n\nThen change directory into it:\n```sh\ncd crepl\n```\n\n### Build \u0026 Install\n```sh\nmake  # Builds and compiles the project.\nsudo make install  # Installs the program system wide.\n```\n\nYou may also compile with debug-printing by `DEFINES=-DDEBUG make` instead.\n\n## Example\n\nAn example of a session:\n\n```console\n::\u003e k = 9\n#=\u003e 9\n::\u003e f x = 2x - k\n::\u003e f 10\n#=\u003e 11\n::\u003e addTo x = y -\u003e x + y\n::\u003e add3 = addTo 3\n::\u003e add3 10\n#=\u003e 13\n::\u003e sum = x -\u003e y -\u003e x + y\n::\u003e (sum 2) 3\n#=\u003e 5\n::\u003e sin 2pi - 1\n#=\u003e -1\n::\u003e (k-2)!\n#=\u003e 5040\n```\n\n### Symbolic Manipulation\n\nQuotes are expressions enclosed in `[`, `]`.\nQuotes recursively evaluate its containing expression until it reaches\na leaf (a literal value) or it reaches an unresolvable symbol (an unknown).\n\nSo, if `f (x, a) = x^3 + 2x + a` is defined, but no variable `x` is defined,\nwriting `[f(x, 1)]` evaluates to `[x^3 + 2x + 1]`.\n\nQuoting is idempotent `[[f(x)]]` is the same as `[f(x)]`.\nAnd, `[x + [y] + 3]` is the same as `[x + y + 3]`.\nQuoting literals leaves them unchanged `[5]` is the same as `5`.\n\nTo evaluate quotes, simply trigger evaluating the quote again in an environment\nwhere its unknowns are defined. You can make a function:\n```\nexpr = [x^2]\nf x = [expr]\nf 4 #=\u003e 16\n```\n\nTo keep quotes from evaluating known variables, specify the unknowns\nexplicitly: `[f(x); x]` reads \"quote `f(x)` where `x` is the unknown.\nWhen unknowns are listed explicitly, they must be exhaustive,\ni.e. the rest can be generic stand-ins by must be eventually determined,\nthey are not implicitly understood as unknowns if they are not defined.\nThat is, `[x + y; x]` is an error if `y` is not defined.\n\nFunctions can take quotes, match against them, and construct new ones.\n```\nD [x^n; x] = n x^(n - 1)\nD [sin(x); x] = cos(x)\nD [cos(x); x] = -sin(x)\nD [f (g x); x] = D[f(y)] D[g(x)] where y = g(x)\nD [(f x) * (g x); x] = D[f(x)] g(x) + f(x) D[g(x)]\nD [_] = error \"Unknown derivative\"\nD _ = 0\nf x0 = x0^3\nf' x0 = D[f(x)] where x = x0\nf' 1 #=\u003e 2\n```\n\nIn the above, `x` is automatically quoted as `[x]` in the RHS since its an unknown in the LHS.\nOperations on a quoted expression results in another quote,\ne.g. `[x + 2] + 3` evaluates to `[x + 2 + 3]` which continues to be evaluated to\n`[x + 5]`.\n\nThus, the expression defining `f` earlier can be retrieved by passing\nquoted variables `f ([x], [a])` becomes `[x^3 + 2x + a].\n\n## TODO\n\n - [x] Temporary variables with `let ... in ...` and `... where ...` expressions.\n - [ ] Computed physical units with through postfix operators.\n   - [ ] User defined units.\n - [ ] A `ref(.)` function, for referencing/aliasing other variables.\n - [ ] Throw errors on overflows until we implement bignums.\n - [ ] Imaginary numbers (using `complex.h`).\n - [x] User defined functions.\n   - [x] Single argument.\n   - [x] Tuple argument.\n   - [x] Anonymous functions.\n   - [x] Currying.\n - [ ] Tuple slicing with `a:b` range syntax.\n - [x] Tuple splat operator `(a, ...tup)`.\n - [ ] Overloading operators. Operations on tuples.\n - [ ] Pool constant and literal values in a preallocated structure, to save on reallocating constants by preventing them from being garbage collected.\n - [x] Garbage collection.\n   - [x] Reference count function scopes.\n   - [x] Reference count data values.\n - [ ] Numerical equation solver (polynomial, simultaneous, \u0026c.).\n - [ ] Extend numbers to include “Big Numbers” (“Big Integers” and “Big Decimals”/Rationals), numbers a currently limited to ~80bit floats and pointer-sized (likely 64bit) integeres.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemonstrandum%2Fcrepl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdemonstrandum%2Fcrepl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemonstrandum%2Fcrepl/lists"}