{"id":15634657,"url":"https://github.com/uraimo/swiftylisp","last_synced_at":"2025-10-19T06:16:02.069Z","repository":{"id":62456926,"uuid":"78416749","full_name":"uraimo/SwiftyLISP","owner":"uraimo","description":"A minimal LISP implemented in Swift","archived":false,"fork":false,"pushed_at":"2019-02-14T09:11:09.000Z","size":105,"stargazers_count":137,"open_issues_count":0,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-15T11:07:59.813Z","etag":null,"topics":["interpreter","language","lisp","programming-language"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/uraimo.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":"2017-01-09T10:04:21.000Z","updated_at":"2025-03-10T09:35:35.000Z","dependencies_parsed_at":"2022-11-02T00:17:00.115Z","dependency_job_id":null,"html_url":"https://github.com/uraimo/SwiftyLISP","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uraimo%2FSwiftyLISP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uraimo%2FSwiftyLISP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uraimo%2FSwiftyLISP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uraimo%2FSwiftyLISP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uraimo","download_url":"https://codeload.github.com/uraimo/SwiftyLISP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249058370,"owners_count":21205910,"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":["interpreter","language","lisp","programming-language"],"created_at":"2024-10-03T10:55:21.569Z","updated_at":"2025-10-19T06:15:57.036Z","avatar_url":"https://github.com/uraimo.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftyLISP\n\n**An embeddable LISP interpreter for Swift**\n\n\u003cp\u003e\n\u003ca href=\"https://developer.apple.com/swift\"\u003e\u003cimg src=\"https://img.shields.io/badge/Swift-4.x-orange.svg?style=flat\" alt=\"Swift 4 compatible\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://raw.githubusercontent.com/uraimo/Bitter/master/LICENSE\"\u003e\u003cimg src=\"http://img.shields.io/badge/license-MIT-blue.svg?style=flat\" alt=\"License: MIT\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/apple/swift-package-manager\"\u003e\u003cimg src=\"https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-brightgreen.svg\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://cocoapods.org/pods/SwiftyLISP\"\u003e\u003cimg src=\"https://img.shields.io/cocoapods/v/SwiftyLisp.svg\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Summary\n\nThis framework contains an interpreter for the LISP defined in [John McCarthy's micro-manual](https://www.uraimo.com/files/MicroManual-LISP.pdf) and described in [this article](https://www.uraimo.com/2017/02/05/building-a-lisp-from-scratch-with-swift/).\n\n## Usage\n\nThe framework converts string literals in nested structures based on the `SExpr` enum that can then be evaluated.\n\nLet's see some usage examples:\n\n```swift\nimport SwiftyLisp\n\nvar expr:SExpr = \"(cond ((atom (quote A)) (quote B)) ((quote true) (quote C)))\"\n\nprint(expr)\ndump(expr)\nprint(expr.eval()!)  //B\n\nexpr = \"(car ( cdr  ( quote (1 2 \\\"aaaa\\\"   4 5 true 6 7 () ))))\"\nprint(expr.eval()!)  //2\n\nexpr = \"( (lambda (x y) (atom x)) a b)\" \nprint(expr.eval()!)  //true\n\nexpr = \"(defun ff (x) (cond ((atom x) x) (true (ff (car x)))))\"\nprint(expr.eval()!)\nexpr = \"(ff (quote ((a b) c)))\"\nprint(expr.eval()!)  //a\n\nexpr = \"(eval (quote (atom (quote A)))\"\nprint(expr.eval()!)  //true\n\nexpr = \"(defun alt (x) (cond ((or (null x) (null (cdr x))) x) (true (cons (car x) (alt (cddr x))))))\"\nprint(expr.eval()!)\nexpr = \"(alt (quote (A B C D E))\"\nprint(expr.eval()!)  //(A C E)\n \n```\n\nHere is a recap of the available operators:\n\n| Atom | Structure | Description |\n|------|-----|---------|\n| Print    | (print e) | Prints its sub-expression |\n| Eval     | (eval e) | Eval evaluates its sub-expression |\n| Quote    | (quote e) | This atom once evaluated returns its sub-expression **as is**, _e.g. (quote A) = A_ |\n| Car | (car l) | Returns the first element of a non-empty sub-list, _e.g. (car (quote (A B C))) = A_ |\n| Cdr | (cdr l) | Returns all the elements of the sub-list after the first in a new list, _e.g. (cdr (quote (A B C))) = (B C)_ |\n| Cons | (cons e l) | Returns a new list with e as first element and then the content of the sublist _e.g. (cons (quote A) (quote (B C))) = (A B C)_ |\n| Equal | (equal e1 e2) | Returns an atom aptly named **true** if the two symbolic expressions are recursively equal and the empty list **()** (that serves as both nil and false value) if they are not, _e.g. (equal (car (quote (A B))) = (quote A))_ |\n| Atom | (atom e) | Returns true if the symbolic expression is an atom or an empty list if it is a lis, _e.g. (atom A) = true_ |\n| Cond | (cond (p1 e1) (p2 e2) ... (pn en)) | Returns the first **e** expression whose **p** predicate expression is not equal to the empty list. This is basically a conditional atom with a slightly more convoluted syntax than a common if construct. _e.g. (cond ((atom (quote A)) (quote B)) ((quote true) (quote C) = B_ |\n| List | (list e1 e2 ... en) | Returns a list of all the given expressions, identical to applying cons recursively to a sequence of expressions. |\n| Lambda | ( (lambda (v1 ... vn) e) p1 ... pn) | Defines a lambda expression with body **e** that describes an anonymous function that uses a series of environment variables **v**. This function will be evaluated using the provided parameters as value for the variables. _e.g. ((lambda (X Y) (cons (car x) y) (quote (A B)) (cdr (quote (C D)))) = (A D)_ |\n| Defun | (defun \u003cname\u003e (v1 ... vn) e) | Define a lambda expression and registers it in the current context to be used when we need it. We'll be able to define a function like _(defun cadr (X) (car (cdr x)))_  and use it in another expression like _(cadr (quote (A B C D)))_. |\n\nAdditional examples, and the additional functions and acronyms defined in the paper, can be found in the test suite of the framework.\n\n## Installation\n\nThe library can be installed with either CocoaPods, Carthage or the SwiftPM.\n\nTo include it in your project using the Swift Package Manager, add a dependency to your `Package.swift`:\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n    ...\n    dependencies: [\n        ...\n        .Package(url: \"https://github.com/uraimo/SwiftyLISP.git\")\n    ]\n)\n```\n\nRegardless of how you added the framework to your project, import it with `import SwiftyLisp`. \n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 [Umberto Raimondi](https://www.uraimo.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furaimo%2Fswiftylisp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Furaimo%2Fswiftylisp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furaimo%2Fswiftylisp/lists"}