• Stars
    star
    202
  • Rank 193,691 (Top 4 %)
  • Language
    R
  • License
    Other
  • Created over 7 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lisp-like-R: A clojure inspired lisp that compiles to R in R

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
#>   <int>    <dbl>
#> 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 <backtick> 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.

More Repositories

1

ompr

R package to model Mixed Integer Linear Programs
R
268
star
2

encryptedRmd

πŸ”‘ Password protected markdown html reports in R using libsodium
HTML
168
star
3

r-shiny-electron

WIP: Electron and R shiny
JavaScript
103
star
4

armacmp

πŸš€ Automatically compile linear algebra R code to C++ with Armadillo
R
95
star
5

wasmr

Execute WebAssembly from R using wasmer
C++
75
star
6

thankr

Find out who maintains the R packages you use and say 'thank you'
R
62
star
7

duckduckr

πŸ¦†πŸ¦†πŸšΆ DuckDuckGo's Instant Answer API for R
R
43
star
8

awesome-r-organizations

A community curated list of awesome companies/organizations that contribute open source R software/packages
42
star
9

logician

πŸ–– Prolog-style Logic Programming in pure R
R
36
star
10

defmacro

Load Time R Package Macros
R
35
star
11

r-orms

R for Operations Research
HTML
32
star
12

transduceR

transducers in R
R
31
star
13

TransitmapSolver.jl

Generate transitmaps automatically using mixed integer programming
Julia
25
star
14

rcbc

COIN-OR branch and cut (CBC) bindings for R
R
20
star
15

learnsqlr

Learn SQL using R and duckdb
R
19
star
16

listcomp

List comprehensions in R
R
19
star
17

htmlvault

Encrypt files in self-decrypting html files using libsodium
HTML
19
star
18

r-sudoku

Solve Sudokus with R, GLPK, shiny and ompr
R
19
star
19

rcompilertools

Compiler Tools for R's bytecode compiler
R
16
star
20

PValueAdjust.jl

[deprecated] P-value adjustment methods for multiple testing correction
Julia
16
star
21

armacmp-shiny

A small shiny app to transpile R to C++
R
14
star
22

rhxl

Humanitarian Exchange Language (HXL standard) in R
R
13
star
23

blake3

BLAKE3 Cryptographic Hash Function in R
R
13
star
24

torchoptim

A bit like 'stats::optim', but with torch
R
10
star
25

etherscanr

Etherscan.io api client for R (work in progress)
R
10
star
26

polyglotr

Use C, Rust, Go and Assemblyscript in an R package through WebAssembly
R
10
star
27

RBerlinData

Open data for Berlin in R [project is abandoned]
R
9
star
28

or-companies

List of companies that hire developers particular to work on combinatorial (optimization) problems
9
star
29

genossenschaften

List of German Wohnungsbaugenossenschaften (Housing cooperatives)
8
star
30

repint

ALTREP example of rep.int
C
8
star
31

nodepicosat

SAT solver PicoSAT for javascript
JavaScript
8
star
32

ompr.roi

ROI bindings for OMPR
R
8
star
33

encryptedCredentials

Small, opinionated package to manage encrypted credentials in R
R
8
star
34

armacmp-examples

Examples of algorithms automatically compiled from R to C++
R
8
star
35

shiny-tsp

Traveling salesperson problem with shiny
R
7
star
36

votingpower.r

Measure voting power in R
R
7
star
37

ROI.plugin.cbc

ROI plugin for COIN-OR branch and cut (CBC) solver
R
7
star
38

covid-19-indicators

Epidemiological Indicators (CFR, incubation period, serial interval) for COVID-19
6
star
39

rpicosat

PicoSAT bindings for R
R
6
star
40

blume_messnet_api

Blume Messnet API
Ruby
5
star
41

coreml

WIP and proof of concept: convert R models to coreml and back
R
5
star
42

defmacroex

An Example of defmacro
R
5
star
43

rcppglm

GLM implementation in c++ with rcpp and armadillo
C++
5
star
44

notail

Experimental and simple tail-call optimisation for R functions
R
4
star
45

optplot

An R package for plotting optimization problems/models
R
4
star
46

blume_crawler

A rake task to regularly download and save particulates statistics in Berlin
Ruby
4
star
47

ndarray-linear-regression

Linear regression (with QR decomposition) with ndarrays
JavaScript
4
star
48

dirichlet-rating

Uncertainty intervals around star based ratings in javascript
JavaScript
4
star
49

iUPB

A popular app for the University of Paderborn, Germany [project is dead]
Ruby
4
star
50

lazyseq

Lazy R list that evaluate elements only when needed
R
3
star
51

hellozig

Zig and R
C
3
star
52

geopattern

HTML widget for the geopattern javascript library
R
3
star
53

covid-api

COVID-19 cases in Germany
R
3
star
54

ContentSecurityPolicy

Content Security Policies for Shiny Apps
R
3
star
55

tfjs-glm

Generalized linear models in tensorflow.js (WIP)
JavaScript
3
star
56

cyclehack-crowd-estimation

3
star
57

lyft_incentive_allocation

An implementation of the lyft incentive allocation problem in R
R
3
star
58

r-orms-idealist

A project wishlist for Operations Research in R
2
star
59

recon-sitrep-generator

Just a proof of concept
R
2
star
60

LineFlowSolver.jl

Solve the line flow problem
Julia
2
star
61

ompr.highs

HiGHS solver bindings for {ompr}
R
2
star
62

berlin-air-quality

2
star
63

RcppBrainfuck

Compile Brainfuck to C++ from R
R
2
star
64

advent-of-code-2021

In LLR
2
star
65

rs-leastsquare

least squares in rust
Rust
2
star
66

knapsack-cbc-wasm

C++
2
star
67

losep

An R package to detect seperation in binary classification models using linear programming
R
2
star
68

immerh

Immer C++ Header Files
C++
1
star
69

tfjs-leastsquares

Solve linear least-squares problems in tensorflow.js
JavaScript
1
star
70

rsupport

A machine readable list of R package makers and how to compensate them for their hard work
1
star
71

ftrljs

FTRL-Proximal online learning algorithm for logistic regression in javascript
JavaScript
1
star
72

mlcombinatorics

machine learning and combinatorics ressources
1
star
73

ompr.symphony

R
1
star
74

ompr.glpk

R
1
star
75

elm-ecdf-spa

A toy elm app to showcase the elm-ecdf package
Elm
1
star
76

multi-way-number-partitioning-problem

Integer programming for the multi way number partitioning problem (WIP)
1
star
77

ompr.docs

documentation website for the R ompr package
HTML
1
star
78

ftrl

Dense FTRL-Proximal online learning algorithm for logistic regression in R
R
1
star
79

aoc2020

AoC2020 using llr (lisp like R)
1
star
80

llr-shiny

Just a small test writing a shiny app using llr
Clojure
1
star