https://github.com/dirkschumacher/llr Skip to content Sign up * Why GitHub? + Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Issues - + Integrations - + GitHub Sponsors - + Customer stories - * Team * Enterprise * Explore + Explore GitHub - + Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - + Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing + Plans - + Compare plans - + Contact Sales - + Education - [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} dirkschumacher / llr Public * Notifications * Star 151 * Fork 12 * Lisp-like-R: A clojure inspired lisp that compiles to R in R View license 151 stars 12 forks Star Notifications * Code * Issues 16 * Pull requests 0 * Actions * Security * Insights More * Code * Issues * Pull requests * Actions * Security * Insights master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show Loading {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default Loading View all tags 1 branch 0 tags Code Loading Latest commit @dirkschumacher dirkschumacher fix repl bug ... 0aa72c3 Feb 5, 2021 fix repl bug 0aa72c3 Git stats * 65 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time R fix repl bug Feb 5, 2021 inst More functions in llr Jan 22, 2021 tests Start counting at 0 Jan 22, 2021 .Rbuildignore Towards a V3 Jan 13, 2021 .gitignore Towards a V3 Jan 13, 2021 CODE_OF_CONDUCT.md Towards a V3 Jan 13, 2021 DESCRIPTION Various improvements Jan 22, 2021 LICENSE Towards a V3 Jan 13, 2021 LICENSE.md Towards a V3 Jan 13, 2021 NAMESPACE Even more improvements Jan 22, 2021 README.Rmd Fix readme Jan 22, 2021 README.md Fix readme Jan 22, 2021 llr.Rproj Towards a V3 Jan 13, 2021 View code [ ] llr Installation Intro REPL Special forms Data Types Lists Vectors Maps Symbols Functions def Meta-data Macros Recursion Namespaces Reader Dispatch #_ ignores the next form R interop Design Goals Contributing Code of Conduct README.md llr llr is a small, work in progress and just for fun clojure-like lisp on top of R's abstract syntax trees. Expressions are not interpreted, but are translated to R's AST and then interpreted by the R interpreter. Most implementation details are sub-optimal, but the focus is on having fun and producing results instead writing perfect code. There are also many bugs and inconsistencies! Installation remotes::install_github("dirkschumacher/llr") Intro (-> r/datasets::mtcars (r/dplyr::filter (r/base::`>` hp 100)) (r/dplyr::summarise :count (r/dplyr::n) :mean_mpg (r/mean mpg)) (r/tibble::as_tibble)) #> # A tibble: 1 x 2 #> count mean_mpg #> #> 1 23 17.5 Or run it from R library(llr) interp <- llr_env$new() interp$eval("(+ 1 1)") #> 2 Also see some Advent Of Code solutions in llr. REPL It also has a (limited) REPL interp <- llr_env$new() interp$repl() Special forms Data Types Lists ; this is a list '(1 2 3 4 5 6) ; an unquoted list is a function call (+ 1 2 3 4 5 6) #> 21 Vectors [1 2 3 4] #> [1 2 3 4] Maps {:a 1 :b 2} #> {:a 1 :b 2} Symbols x namespaced.variable/x :keyword "character" 10 ; integer 10.42 ; double Functions (fn [a b] (+ a b)) (fn this ([] 0) ([a] a) ([a b] (+ a b)) ([a b & more] (reduce + (concat [a b] more)))) def def defines a symbol in a namespace and assignes it a name. (def x 1) (def plus (fn [a b] (+ a b))) (plus x x) #> 2 Meta-data Symbols and values can hold meta-data. That meta-data needs to be a map at the moment. (def ^{:const true} x ^{:meta "hello"} [ 1 2 3]) (meta x) #> {:meta "hello"} Meta-data on symbols is currently only available to the reader. Macros Macros are also supported. Macros are functions bound to a name with meta data {:macro true}. In a macro you can use syntax-quote together with the unquote ~ and unquote-splice ~@ operators. (defmacro infix [operand1 operator operand2] `(~operator ~operand1 ~operand2)) (infix 1 + 1) #> 2 Recursion Similar to Clojure llr uses recur to jump to a recursion point currently only defined by loop. (def is-even (fn [number] (loop [cnt number] (if (zero? cnt) true (if (< cnt 0) false (recur (- cnt 2))))))) #> `is-even` (is-even 5001) #> false (is-even 5000) #> true Namespaces Every top level definition is part of a namespace (ns product.lib) (defn compute [a b] (+ a b)) (ns user) (product.lib/compute 10 32) #> 42 Reader Dispatch The reader switches to a different set of interpretations of the next symbol when reading the character #. #_ ignores the next form #_ (r/stop "error") "Yay" #> "Yay" R interop All symbols starting with the namespace r/ are treated slightly differently. You can use that to refer to external R functions and symbols. In addition keywords are interpreted as named arguments. (r/set.seed 1) (def rand-numbers (r/stats::rnorm :n 10)) (r/mean rand-numbers) #> [1] 0.1322028 Design Goals * Have fun, experiment and learn :) * Build a clojure-like language that supports R-interop using the r / namespace. * Thus the core language should feel like clojure and support some of clojures's core functions, but still make it easy to work with R's internal data structures. Contributing * Please read the code-of-conduct and also be aware that this a fun project, so things will break and progress is valued prefect code (at the moment). * However everyone is invited to play around with the language, learn together, extend it, document things, fix bugs and propose features. Code of Conduct Please note that the llr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms. About Lisp-like-R: A clojure inspired lisp that compiles to R in R Topics language r lisp lisp-dialect Resources Readme License View license Code of conduct Code of conduct Releases No releases published Packages 0 No packages published Contributors 2 * @dirkschumacher dirkschumacher Dirk Schumacher * @funnell funnell Tyler Funnell Languages * R 93.9% * Clojure 6.1% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.