Coder Social home page Coder Social logo

r6rs-lazar's Introduction

Lazar

Toy library for R6RS Scheme

Code examples shown here

Overview

Mostly fiddling around trying to learn the ropes, but I have a soft spot for this kind of syntax, so I'll be probably rolling it in any of my real projects, if I ever get to them.

So, purely for fucking around and teaching myself how to handle macros, create libraries (I know the R7RS lib spec is a bit different, but not different enough to undo all I picked up.)

Libraries

  • (lazar)
    • (lazar fn-lambda)
      • SML-reminiscient anonymous (lambda) function.
    • (lazar est)
      • OCaml-like let / let rec-syntax for let* / letrec*
    • (lazar case-with)
      • SML-like syntax sugared cond that should do pattern matching too somewhere in the future.
    • (lazar basic-syntax)
      • math / Coq / Haskell-inspired notation for some miscellaneous functions and macros.
    • (lazar cxr)
      • cadadr-style abbreviations to hd and tl format (ie. h:hd => caar)
    • (lazar contracts)
      • SML-inspired rework of Linus Björnstam's contracts for function definition.

"Features"

  • SML-like syntax
car    := hd
cdr    := tl
cadr   := h:tl
cadar  := h:t:hd

cons   := ::
cons*  := ::*
  • unicode logic symbols, and some of their ascii equivalents to use
#t  := ⊤, true
#f  := ⊥, false
and := /\, ∧, ⋀
or  := \/, ∨, ⋁
not := ¬

( ... )

'()       := Ø
(not '()) := ¯
  • define with contracts (with define/c)
(define/c (<proc-name> ((<param> : <type>) ...) -> <return-type>) body ... )
  • and for single parameter/variable-cases:
(define/c (<proc-name> (<param> : <type>) -> <return-type>) body ... )
  • Types to contract include at the very least:
    • any boolean (easy to construct your own type). Example of this seen below.

    • ListOf x

    • VecOf x

    • Any, a', α

      • etc.
    • Defining new contract/type/predicate:

(define (Natural n)
  (and (exact? n) (ℤ n) (>= n 0)))
  • sugared cond, much like the one found in Standard ML.
    • nb. => is purely sugar and case-with functions just as well without it.
(case-with || <clause> => <expr>
           || <clause> => <expr> ...
           || else     => <expr>)
  • Example of define/c and case-with on a Little Schemer -fame function:
(define/c (rember ((x : α) (ys : List)) -> List)
  (case-with || (Ø? ys)       => Ø
             || (= x (hd ys)) => (tl ys)
             || else          => (:: (hd ys) (rember x (tl ys)))))
  • SML-inspired lambda notation.
    • Without the auxilliary =>, it handles one variable, marked with underscore.
((λ x y z => (+ x y z)) 20 19 3)

;; indices should start at 1 goddamnit
(define/c (ι (n : ℕ) -> List)
  (map (λ (+ _ 1)) (iota n)))
  • est / ε works like a quick let* and letrec*-closure.
    • rec marking the following definition as a recursable from the closure.
(define/c (rev (xs : List) -> List)
  (ε rec aux
     (λ x y =>
        (case-with || (Ø? x) => y
                   || else   => (aux (tl x) (:: (hd x) y))))
     in (aux xs Ø)))

Funnily enough Emacs handles indentation of all this relatively well

Thanks to

r/scheme

Linus Björnstam

#scheme @ freenode

r6rs-lazar's People

Contributors

karahobny avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.