Skip to content

Instantly share code, notes, and snippets.

@manuel
manuel / tx.adoc
Last active February 19, 2024 17:47
Transactional RPC across heterogenous data stores and facades

An idea for how to do transactions across heterogenous data stores (e.g. key-value (KV) stores and Git repositories) in an RPC system. Probably not novel.

Overview

There are primitive data stores, like KV stores and Git repositories.

There are facades, processes, that enforce some invariant on top of another, underlying data store. Example: a facade that only allows storing numbers as values in a KV store.

Let’s use the term storage process to refer to both primitive stores and facades.

### Keybase proof
I hereby claim:
* I am manuel on github.
* I am msimoni (https://keybase.io/msimoni) on keybase.
* I have a public key ASC3_N8cmaCDXyRmFG6rWilVZcJlAYJC1-aVvAjfMsvL4Qo
To claim this, I am signing this object:
;; Define a simple structure
(defstruct point
x
y)
(defun make-point (x y)
(make-instance 'point :x x :y y))
;; Normal Lisp style function
(defun add-points (p1 p2)
fun send(rcv, msg, args) {
  cls = rcv.isa
  if (cls.isa == STD_CLS)
    method = builtin_lookup(rcv, msg)
  else
    method = send(cls, "lookup", msg)
  method(rcv, args)
}
@manuel
manuel / representing-monads.scm
Created August 28, 2012 00:08
Error monad from Filinski's "Representing Monads"
;; Error monad from Filinski's "Representing Monads"
(define *default-prompt* (make-prompt))
(define (reflect m) (shift *default-prompt* k (ext k m)))
(define (reify t) (push-prompt *default-prompt* (unit (t))))
(define-record-type Success
(make-success a)
success?
@manuel
manuel / dyn-wind-commentary.scm
Created August 11, 2012 12:45
Commenting on Oleg's dyn-wind.scm
;; See http://okmij.org/ftp/continuations/implementations.html#dynamic-wind
;; and http://axisofeval.blogspot.com/2012/08/delimited-continuations-do-dynamic-wind.html
;; Slight trick here: use identity of yield-record-tag function as the actual tag
(define (yield-record-tag) yield-record-tag)
(define (make-yield-record v k)
(list yield-record-tag v k))
;; Yield simply aborts up to the generator's caller, delivering to it
;; the yielded value and the continuation for resuming after the call
<html>
<head>
<title>Wat Sleeping Demo</title>
<script type="text/javascript" src="../../wat.js"></script>
</head>
<body>
<h1><a href="https://github.com/manuel/wat-js">Wat</a></h1>
<script type="text/javascript">
var code =
["begin",
(*
(define-class foo (make-foo))
(define-class bar (make-bar))
(define-generic (m obj))
(define-method (m (f foo)) 1)
(define-method (m (b bar)) 2)
(print (m (make-foo))) ; => 1
(print (m (make-bar))) ; => 2
(define-method (m (f foo)) 3)
(print (m (make-foo))) ; => 3
@manuel
manuel / define-constructor.scm
Created February 22, 2012 15:40
Adventures in Hygienic Fexprs
;; As part of the implementation of Virtua's [1] object system I need
;; a facility called DEFINE-CONSTRUCTOR that defines a convenient
;; function for creating an instance of a class and setting its slots.
(define-constructor make-person Person (firstname lastname))
;; should be operationally equivalent to
(define make-person
(lambda (firstname lastname)
@manuel
manuel / callcc.scm
Created August 1, 2012 15:21
Call/CC in terms of Feeley's "Better API for First-Class Continuations"
(define (call/cc f)
(continuation-capture
(lambda (k)
(f (lambda (val)
(continuation-graft k (lambda () val)))))))