{"id":16739722,"url":"https://github.com/loredanacirstea/taylor","last_synced_at":"2025-03-17T01:32:08.655Z","repository":{"id":39134664,"uuid":"255177899","full_name":"loredanacirstea/taylor","owner":"loredanacirstea","description":"Measure twice, cut once. Lisp-like functional language for computable \u0026 immutable specifications, interpreted by WebAssembly \u0026 the Ethereum Virtual Machine.","archived":false,"fork":false,"pushed_at":"2023-01-06T04:50:18.000Z","size":28968,"stargazers_count":37,"open_issues_count":75,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-02-27T05:05:22.967Z","etag":null,"topics":["blockchain","computable-knowledge","ethereum","functional-programming","lisp","specifications","types"],"latest_commit_sha":null,"homepage":"https://loredanacirstea.github.io/taylor/","language":"JavaScript","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/loredanacirstea.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}},"created_at":"2020-04-12T22:00:08.000Z","updated_at":"2025-01-19T11:29:26.000Z","dependencies_parsed_at":"2023-02-05T08:46:42.399Z","dependency_job_id":null,"html_url":"https://github.com/loredanacirstea/taylor","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loredanacirstea%2Ftaylor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loredanacirstea%2Ftaylor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loredanacirstea%2Ftaylor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loredanacirstea%2Ftaylor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loredanacirstea","download_url":"https://codeload.github.com/loredanacirstea/taylor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243836015,"owners_count":20355615,"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":["blockchain","computable-knowledge","ethereum","functional-programming","lisp","specifications","types"],"created_at":"2024-10-13T00:53:19.813Z","updated_at":"2025-03-17T01:32:08.165Z","avatar_url":"https://github.com/loredanacirstea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# taylor\n\nIn-work.\n\n_Next version (0.0.4): signed integers, matrix construction, n-dimensional array creation, slicing \u0026 casting, matrix multiplication._\n\n**Try it out: https://loredanacirstea.github.io/taylor/**\n\n**Demos: https://www.youtube.com/playlist?list=PL323JufuD9JAgnda2E8mGn_GDcD5ef4mH**\n\nExamples to try out: (!only one line at a time)\n\n```lisp\n(add (add (sub 7 2) 1) 41)\n(list 5 4 (add 6 2) 3 (sub 6 1))\n(if (gt 4 9) ((fn* (a b) (add a b)) 2 3) (add (sub 7 2) 1))\n\n# define and use lambdas in-memory\n( (fn* (a b) (add (mul a b ) b)) 2 3)\n\n# define and store functions on-chain\n(def! myfunction (fn* (a b) (add (add (sub a b) a) b)))\n\n# use a stored function; notice the _\n(_myfunction 5 3)\n\n(concat \"0x11aaaabb\" \"0x221111ccdd\")\n(contig 2 \"0x221111ccdd\")\n\n(def! fib (fn* (n) (if (or (eq n 1) (eq n 2)) 1 (add(_fib (sub n 1)) (_fib (sub n 2)) ) )))\n\n# higher order functions\n(map _fib (list 5 8 2))\n```\n\n## Ballot \n\nImplementing Solidity's Ballot contract from https://solidity.readthedocs.io/en/v0.6.10/solidity-by-example.html#voting. See https://github.com/loredanacirstea/taylor/blob/ff253038d8b83f48b4d897f3b6b455924ef848a2/tests/maltay.test.js#L1159 for ver. 0.0.2.\n\n```lisp\n(list \n    ; weight, voted, delegate, vote (proposal index)\n    (defstruct! Voter (list Uint Bool Address Uint))\n    \n    ; name, voteCount\n    (defstruct! Proposal (list String32 Uint) )\n\n    (defmap! \"voters\" Address \"Voter\")\n    \n    ; (name! chairperson (save! (caller)))\n    (store! 0 (caller))\n\n    (def! giveRightToVote! (fn* (voterAddress)\n        (if (eq (caller) (sload 0 Address))\n            (if (nil? (mapget voters voterAddress))\n                (mapset! voters voterAddress (struct! Voter (list 1 false \"0x0000000000000000000000000000000000000000\" 0)))\n                (revert \"The voter already voted.\")\n            )\n            (revert \"Only chairperson can give right to vote.\")\n        )\n    ))\n\n    (def! recDelegation (fn* (to_address)\n        (let* (\n                delegate_raw (mapget voters to_address)\n                delegate (list-struct delegate_raw)\n            )\n            (if (nil? delegate)\n                ; (revert \"Delegate cannot vote\")\n                (revert to_address)\n                (let* (delegateOfDelegate (nth delegate 2))\n                    (if (or\n                            (nil? delegateOfDelegate)\n                            (eq delegateOfDelegate \"0x0000000000000000000000000000000000000000\")\n                        )\n                        to_address\n                        (if (eq delegateOfDelegate (caller))\n                            (revert \"Found loop in delegation.\")\n                            (recDelegation delegateOfDelegate)\n                        )\n                    )\n                )\n            )\n        )\n    ))\n\n    (def! delegate! (fn* (to_address)\n        (let* (\n                sender_raw (mapget voters (caller))\n                sender (list-struct sender_raw)\n                sender_types (defstruct Voter)\n                sender_indexes (refs-struct sender_raw)\n            )\n            (if (true? (nth sender 1))\n                (revert \"You already voted.\")\n                (if (eq to_address (caller))\n                    (revert \"Self-delegation is disallowed.\")\n                    (let* (\n                            delegateAddress (recDelegation to_address)\n                            delegate_raw (mapget voters delegateAddress)\n                            delegate (list-struct delegate_raw)\n                        )\n                        (list\n                            ; sender.voted = true\n                            (update! (nth sender_types 1) (nth sender_indexes 1) true)\n                            ; sender.delegate = to\n                            (update! (nth sender_types 2) (nth sender_indexes 2) delegateAddress)\n                            (if (true? (nth delegate 1))\n                                ; proposals[delegate_.vote].voteCount += sender.weight\n                                (let* (\n                                        proposal_raw (getfrom Proposal (nth delegate 3))\n                                        proposal (list-struct proposal_raw)\n                                        proposal_types (defstruct Proposal)\n                                        proposal_indexes (refs-struct proposal_raw)\n                                    )\n                                    (update! (nth proposal_types 1) (nth proposal_indexes 1) (add (nth sender 0) (nth proposal 1)))\n                                )\n\n                                ; delegate_.weight += sender.weight\n                                (let* (\n                                        delegate_types (defstruct Voter)\n                                        delegate_indexes (refs-struct delegate_raw)\n                                    )\n                                    (update! (nth delegate_types 0) (nth delegate_indexes 0) (add (nth delegate 0) (nth sender 0)))\n                                )\n                            )\n                        )\n                    )\n                )\n            )\n        )\n    ))\n\n    (def! vote! (fn* (proposalIndex)\n        (let* (\n                sender_raw (mapget voters (caller))\n                ; values for: weight, voted, delegate, vote\n                sender (list-struct sender_raw)\n                \n                ; types for: weight, voted, delegate, vote\n                sender_types (defstruct Voter)\n                \n                ; DB index for each struct component\n                sender_indexes (refs-struct sender_raw)\n                \n                proposal_raw (getfrom Proposal proposalIndex)\n                ; values: name, voteCount\n                proposal (list-struct proposal_raw)\n                proposal_types (defstruct Proposal)\n                proposal_indexes (refs-struct proposal_raw)\n            )\n            (if (or \n                    (or (nil? sender) (true? (nth sender 1)))\n                    (lt (nth sender 0) 1)\n                )\n                (revert \"Has no right to vote\")\n                (list\n                    ; sender.voted = true\n                    (update! (nth sender_types 1) (nth sender_indexes 1) true)\n                    ; sender.vote = proposal\n                    (update! (nth sender_types 3) (nth sender_indexes 3) proposalIndex)\n                    \n                    ; proposals[proposal].voteCount += sender.weight\n                    (update! (nth proposal_types 1) (nth proposal_indexes 1) (add (nth sender 0) (nth proposal 1)))\n                )\n            )\n        )\n    ))\n\n    (list\n        (struct! Proposal (list \"proposal1\" 0))\n        (struct! Proposal (list \"proposal2\" 0))\n        (struct! Proposal (list \"proposal3\" 0))\n    )\n)\n```\n\nThen:\n- `(giveRightToVote! \"0xe8B7665DE12D67bC802aEcb8eef4D8bd34741C51\")`\n- `(vote! 2)`\n- `(delegate! \"0xe8B7665DE12D67bC802aEcb8eef4D8bd34741C51\")`\n\n\n## Moral Support\n\nEthereum: `0xf149c02b892556eC1fCf39bF43A3bF5B4A9F2346`\n\nTo see the current balance: https://etherscan.io/address/0xf149c02b892556eC1fCf39bF43A3bF5B4A9F2346.\n\nAll participations to this project are public and are received into only one account, as required by the Moral Upgrade License (MUL2020): https://medium.com/@loredana.cirstea/mul2020-the-moral-upgrade-license-2020-b19dfbcbe54.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floredanacirstea%2Ftaylor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floredanacirstea%2Ftaylor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floredanacirstea%2Ftaylor/lists"}