{"id":13602486,"url":"https://github.com/moevis/lambda-lite-js","last_synced_at":"2026-01-17T09:50:56.707Z","repository":{"id":82175349,"uuid":"44513134","full_name":"moevis/lambda-lite-js","owner":"moevis","description":"a tiny FUNCITONAL LANGUAGE implemented by javascript. 一个函数式语言，使用 js 实现。","archived":false,"fork":false,"pushed_at":"2018-08-22T12:11:18.000Z","size":98,"stargazers_count":78,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-07T05:39:25.511Z","etag":null,"topics":["functional-language","javascript","lambda"],"latest_commit_sha":null,"homepage":"https://moevis.github.io/lambda-lite-js/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moevis.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":"2015-10-19T05:30:28.000Z","updated_at":"2024-09-12T07:02:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"f2f5509d-bcba-416c-95ec-34a1562ddbfd","html_url":"https://github.com/moevis/lambda-lite-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moevis%2Flambda-lite-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moevis%2Flambda-lite-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moevis%2Flambda-lite-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moevis%2Flambda-lite-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moevis","download_url":"https://codeload.github.com/moevis/lambda-lite-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248361645,"owners_count":21090953,"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":["functional-language","javascript","lambda"],"created_at":"2024-08-01T18:01:25.036Z","updated_at":"2026-01-17T09:50:56.691Z","avatar_url":"https://github.com/moevis.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Lambda-Lite-js\r\na tiny FUNCITONAL LANGUAGE implemented by javascript.\r\n\r\nonline demo: https://moevis.github.io/lambda-lite-js/ （中文版）\r\n\r\n## Support\r\n\r\n* Lambda function (including sugar for declearing multi-parameters function)\r\n* currying, lazy evaluation, recursive in anonymous function (z combinator)\r\n* Basic pattern matching\r\n* Point-free style: compose function together with `.`\r\n* Basic type system: bool, number, list, function and string.\r\n\r\n## Tutorial\r\n\r\n### Lambda function\r\n\r\nUsing backsplash and arrow to declear an anyoumous function. Lambda function only accept one parameter, but you can use some magic method to break this limit.\r\n\r\n```haskell\r\n\\n -\u003e n + 1;\r\n\\n -\u003e n * n;\r\n\\n -\u003e n + n * n;\r\n```\r\n\r\nCreating function which accepts two parameters.\r\n\r\n```haskell\r\n(\\n -\u003e \\m -\u003e m + n) 1 2 --- output: 3\r\n```\r\n\r\nNow, declear a function with single-param or multi-params can be write as below:\r\n\r\n```haskell\r\nlet add x y = x + y\r\nlet result = add 1 2\r\n```\r\n\r\n### Pattern matching\r\n\r\nPattern matching is an useful feature in some functional language. The ll language has a basic pattern matching implements.\r\n\r\n```haskell\r\nlet func a@1 = a + 1;\r\nlet func a@2 = a + 2;\r\nprint (func 2);\r\n\r\nlet echo a@Number = print 'Number';\r\nlet echo a@String = print 'String';\r\nlet echo a@*      = print 'Other';\r\necho 'this is string';\r\necho true;\r\n```\r\n\r\nPattern matching has some limits in ll.js .\r\n\r\n* The all parameters should be in the same order.\r\n* The lengths of the functions which have same name also should be equal.\r\n* Every parameter should have a pattern declearation like `Number`, `String`, `Boolean`, or `*` for other types.\r\n* Matching progress is from top to bottom, from left to right.\r\n\r\n### Various declaration\r\n\r\nThe keyword `let` leads an assignment, in forms of `let ... = ... (-\u003e ...)`. The symbol `-\u003e` is options, only if you want return a value.\r\n\r\n```haskell\r\nlet x = 5;\r\nlet y = \\n -\u003e n + 1;\r\nlet z = let a = 3 -\u003e a * a;\r\n```\r\n\r\n### Binary condition\r\n\r\nThe binary condition is in form of `if ... then ... else ...`.\r\n\r\n```haskell\r\nprint (if true then 1 else 0)\r\n```\r\n\r\n### Native function\r\n\r\nnow some native functions are accessiable. As well as the basic calculation operators: `+-*/`.\r\n\r\n```haskell\r\nprint \"hello\";\r\nprint (length [1,2,3,4]);\r\nprint (reverse [1,2,3,4]);\r\nprint [1,2,3,4] !! 2;\r\nprint (not true);\r\n```\r\n\r\n### Recursive calling\r\n\r\nRecursive programming is an elegant programming style.\r\n\r\n```haskell\r\n\r\nlet fact = \\n -\u003e\r\n    if n == 1 then 1\r\n    else n * (fact n - 1);\r\nprint (fact 5);\r\n```\r\n\r\nLambda function can recursive by using z-combinator instead of calling itself.\r\n\r\n```haskell\r\nlet z = \\f-\u003e(\\x -\u003e f (\\y -\u003e x x y)) (\\x -\u003e f (\\y -\u003e x x y));\r\nlet makeFact = \\g -\u003e \\n -\u003e if n \u003c 2\r\n    then 1\r\n    else n * (g n - 1);\r\nlet fact = z makeFact;\r\nprint (fact 5);\r\n```\r\n\r\n### Point-free programming\r\n\r\nUse `.` and `$` to pretifier your code, less `brackets` now !!!\r\n\r\nBeblow is a sample for calculating (10 + 10) ^ 2\r\n\r\n```haskell\r\nlet double = \\n -\u003e n + n;\r\nlet square = \\n -\u003e n * n;\r\nprint $ double $ square 10;\r\nlet func = double . square;\r\nprint $ func 10;\r\n```\r\n\r\n### Play with Church Number\r\n\r\n```haskell\r\nlet True x y = x;\r\nlet False x y = y;\r\nlet Zero f x = x;\r\nlet One f x = f x;\r\nlet Two f x = f (f x);\r\nlet Three f x = f (f (f x));\r\nlet Add a b f x = a f (b f x);\r\nlet Mul a b f x = a (b f) x;\r\n\r\nprint $ Two (\\n -\u003e n + 1) 0;\r\nprint $ Add One Two (\\n -\u003e n + 1) 0;\r\nprint $ Mul Two Three (\\n -\u003e n + 1) 0;\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoevis%2Flambda-lite-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoevis%2Flambda-lite-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoevis%2Flambda-lite-js/lists"}