{"id":21326709,"url":"https://github.com/jaypmorgan/slurp","last_synced_at":"2025-06-19T18:34:18.591Z","repository":{"id":74496366,"uuid":"367828525","full_name":"jaypmorgan/slurp","owner":"jaypmorgan","description":"Statistical Lisp in R","archived":false,"fork":false,"pushed_at":"2021-06-19T19:20:05.000Z","size":330,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-22T12:45:24.649Z","etag":null,"topics":["lisp","rprogramming"],"latest_commit_sha":null,"homepage":"https://jaypmorgan.github.io/slurp/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaypmorgan.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":"2021-05-16T08:49:36.000Z","updated_at":"2021-06-19T19:20:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"45e09b18-ec3e-4856-af47-33cc08894991","html_url":"https://github.com/jaypmorgan/slurp","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/jaypmorgan%2Fslurp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaypmorgan%2Fslurp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaypmorgan%2Fslurp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaypmorgan%2Fslurp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaypmorgan","download_url":"https://codeload.github.com/jaypmorgan/slurp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806070,"owners_count":20350775,"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":["lisp","rprogramming"],"created_at":"2024-11-21T21:10:48.959Z","updated_at":"2025-03-16T00:10:54.345Z","avatar_url":"https://github.com/jaypmorgan.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"man/figures/logo.png\"/\u003e\n\n*Statistical Lisp in R*\n\u003c/p\u003e\n\n[![docs](https://img.shields.io/badge/docs-latest-blue)](https://jaypmorgan.github.io/slurp/index.html)\n\nImplemention of Lisp-style sytnax and language design for the `R`\nprogramming language. Code written in SluRp will be translated to `R`\nand then executed in that environment.\n\nThis project isn't intended as a production ready application or\nalternative to `R` but rather a fun project to learn something about\nthe implementation of lisp and the core `R` language.\n\n## Quick-start Guide\n\nStart the REPL:\n\n```bash\n./slurp\nSluRp\u003e\n```\n\nOr you can run a SluRp script:\n\n```bash\n./slurp test.slurp\n```\n\nIn the REPL you can enter the lisp-style commands:\n\n```lisp\nSluRp\u003e (+ 2 (* 2 3))\n\n# [1] 8\n```\n\nUnlike `R`, arithmetic functions are applied over all arguments:\n\n```lisp\nSluRp\u003e (+ 1 2 3 4 5)\n[1] 15\n```\n\nCreate variables using the `defparam` function. This function returns\nthe value associated with the variable name. These variables can then\nbe references in the same scope.\n\n```lisp\nSluRp\u003e (defparam x 5)\n\n# [1] 5\n\nSluRp\u003e (defparam y 10)\n\n# [1] 10\n\nSluRp\u003e (+ x y)\n\n# [1] 15\n```\n\nAs its implemented in the `R` environment, the usual statistical\nfunctions are readily available. Here we are taking 10 samples from a\nnormal distribution with the centre and scale of 10. The return of\nthis function is a vector of 10 elements.\n\n```lisp\nSluRp\u003e (rnorm 10 10 10)\n\n# [1]  14.8692128   3.4932029  18.6337963  15.5319696  -2.9426000 -11.6523209\n# [7]  -0.9475137   6.1512033   4.6517305   8.0993424\n```\n\nFunction arguments can be supplied using the `:keyword` form. For example:\n\n```lisp\nSluRp\u003e (rnorm 10 :mean 10 :sd 1)\n [1] 10.306800 11.189320 10.914911 10.141386 11.459372  9.440626 10.889350\n [8]  9.807462 11.059608 10.595251\n```\n\nIn this example, we are once again calling the `rnorm` function and taking 10 samples from a normal distribution. But instead of supplying the arguments by the position they occur in the function call (number of samples, mean, and then standard deviation of the distribution), we are using keywords. When this form is evaluated in `R` this gets translated to:\n\n```R\nrnorm(10, mean = 10, sd = 1)\n```\n\nAs opposed to `R` base, most functions return a value. Take for\nexample the `print()` function in `R` that prints the passed argument\nto the stream output. In SluRp, the argument that is passed to the\nfunction is printed to the stream and also returned.\n\n```lisp\nSluRp\u003e (print \"testing\")\n[1] \"testing\"\n[1] \"testing\"\n```\n\n### Data types\n\nLisp is a list processor, but we're working with `R`, so we have\naccess to more complex data-types. One of which is the vector or `c()`\ndata-type for simple storage and vector arithmetic. We can create a\nvector with squared-brackets, e.g. `[1 2 3]` is translated to `c(1, 2,\n3)`. This translation is necessary for when we're using functions that\nexpect vector arguments:\n\n```lisp\nSluRp\u003e (mean [1 2 3 4 5])\n[1] 3\n```\n\n### Creating functions\n\nAnonymous functions can be created using a `lambda` expression. Take\nfor example applying a function to a map (from the `purrr` package).\n\n```lisp\nSluRp\u003e (library purrr)\n\nSluRp\u003e (map [1 2 3] (lambda (x) (* x 2)))\n[[1]]\n[1] 2\n\n[[2]]\n[1] 4\n\n[[3]]\n[1] 6\n```\n\nAnonymous functions can also be bound to a name. This is perhaps just\na longer way of creating a function.\n\n```lisp\nSluRp\u003e (defparam print_name (lambda (name) (print (paste \"Hello, \" name))))\nfunction (name)\n{\n    print(paste(\"Hello, \", name))\n}\nSluRp\u003e (print_name \"SluRp\")\n[1] \"Hello,  SluRp\"  # value is printed to stream\n[1] \"Hello,  SluRp\"  # value is also returned\n```\n\nThe shorter way to create a normal function is to use the `defun`\nfunction. The arguments to `defun` are the parameters of the function\n(or an optional empty list) and the body of the function i.e. what\nhappens when the function is called.\n\n```lisp\nSluRp\u003e (defun add (x y) (+ x y))\nfunction (x, y)\n{\n    x + y\n}\nSluRp\u003e (add 1 2)\n[1] 3\n```\n\n## Language Lasagnes\n\nWhat programming stack do you use? Answer: all of them:\n\n```lisp\n;; use slurp to talk to R, to talk to python, to talk to c/c++\n;; use reticulate to talk to python\n(library reticulate)\n\n;; import numpy as torch which should be implemented in C/C++\n(defparam np (import \"numpy\"))\n(defparam torch (import \"torch\"))\n(defparam nn (import \"torch.nn\"))\n\n;; define a simple feedforward network as a test\n(defparam model\n  (nn$Sequential (nn$Linear :in_features 4L :out_features 10L)\n                 (nn$ReLU)\n                 (nn$Linear :in_features 10L :out_features 3L)\n                 (nn$Softmax)))\n\n;; Use the existing iris dataset from R\n;; create a matrix of all the input features\n;; convert to a numpy array and then a torch tensor\n(defun get-data ()\n  (torch$FloatTensor\n    (np$array\n      (as.matrix (select iris [Sepal.Width, Sepal.Length, Petal.Width, Petal.Length])))))\n\n;; create class predictions (as the model isn't trained, these are just random predictions)\n(defparam preds (model get-data))\n\n;; print the predictions to stdout\n(print preds)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaypmorgan%2Fslurp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaypmorgan%2Fslurp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaypmorgan%2Fslurp/lists"}