{"id":18165593,"url":"https://github.com/thedevtop/libsexp","last_synced_at":"2025-04-07T06:19:28.222Z","repository":{"id":258840905,"uuid":"875306617","full_name":"TheDevtop/libsexp-swift","owner":"TheDevtop","description":"S-Expression parser library","archived":false,"fork":false,"pushed_at":"2024-10-22T07:35:12.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T06:19:25.347Z","etag":null,"topics":["parser","s-expressions","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":false,"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/TheDevtop.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":"2024-10-19T16:23:25.000Z","updated_at":"2025-01-15T20:38:20.000Z","dependencies_parsed_at":"2024-12-20T18:29:58.865Z","dependency_job_id":"70ac781b-abf0-43d0-81d0-7e886275fabf","html_url":"https://github.com/TheDevtop/libsexp-swift","commit_stats":null,"previous_names":["thedevtop/libsexp"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheDevtop%2Flibsexp-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheDevtop%2Flibsexp-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheDevtop%2Flibsexp-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheDevtop%2Flibsexp-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheDevtop","download_url":"https://codeload.github.com/TheDevtop/libsexp-swift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601446,"owners_count":20964866,"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":["parser","s-expressions","swift"],"created_at":"2024-11-02T12:07:56.821Z","updated_at":"2025-04-07T06:19:28.179Z","avatar_url":"https://github.com/TheDevtop.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Libsexp \u0026 Libcadr\n\nAn S-Expression parser library, written in Swift.\n\nLisp and its innovative constructs, continue to inspire me.\nThe philosophy of combination and abstraction, as formulated in [SICP](https://web.mit.edu/6.001/6.037/sicp.pdf) left me wanting to write my own Lisp environment.\nThis repository is the first step in that direction.\n\nI hope you may find use in this. \n\n### On usage\n\nThere are two important functions, **decode** and **encode**.\n\n```swift\npublic func Decode(_ input: String) -\u003e Sexp\n```\nDecode takes in a string and outputs an S-Expression object.\nIf any error occurs, it returns an S-Expression containing the `:error` atom.\n\n```swift\npublic func Encode(_ exp: Sexp) -\u003e String\n```\nEncode takes an S-Expression object and returns a string that contains the S-Expression representation of the object.\n\n### On type hierarchy\n\nAn S-Expression can be one of several types.\n\nList types:\n- List `()`, `(+ 1 2 3)`\n\nValue types:\n- Quote `\"Cited string\"`, `'Quoted string'`\n- Number `42`, `-69`\n- Float `4.20`\n- Atom (based on Elixir atoms) `:err`, `:foobar`\n- Boolean `:true` or `:false`\n- Symbol `+`, `foobar`, `write-file`\n\nThe order in which there are listed, is the order in which they are parsed.\nThus there is a hierarchy of types, which determines the output of the decode function.\n\n### On atoms\n\nAtoms are different from symbols, in that atoms won't evaluate to anything.\nThe symbol `foo` may evaluate to a procedure, a number, or even an atom.\nThe atom `:foo` will always resolve to `:foo`.\n\nThere are also two special atoms: `:ok` and `:err`.\nThese atoms perform the same function as the [result](https://doc.rust-lang.org/std/result/) type in Rust.\n\n### On cons, car, and cadr\n\nBesided the S-Expression code found in libsexp, there is also **libcadr**.\nThis library contains the `Cons` type, and the `Car()`, and `Cdr()` functions.\n\n```swift\n/// Get the first element of a list\npublic func Car(_ lexp: libsexp.List) -\u003e libsexp.Sexp\n\n/// Get the other elements of a list\npublic func Cdr(_ lexp: libsexp.List) -\u003e libsexp.List\n\n/// Construct cell\npublic typealias Cons = (car: libsexp.Sexp, cdr: libsexp.List)\n\n/// Construct a cell\npublic func Construct(_ exp: libsexp.Sexp) -\u003e libcadr.Cons\n```\nWith `Construct()` you can create an Cons cell from any S-Expression.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthedevtop%2Flibsexp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthedevtop%2Flibsexp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthedevtop%2Flibsexp/lists"}