Skip to content

Instantly share code, notes, and snippets.

@svard
Created January 27, 2016 21:49
Show Gist options
  • Save svard/6b9a171acac07aa922c5 to your computer and use it in GitHub Desktop.
Save svard/6b9a171acac07aa922c5 to your computer and use it in GitHub Desktop.
(defmodule universal-server
(export all))
(defun universal-server ()
(receive
((tuple 'become f)
(funcall f))))
(defun factorial-server ()
(receive
((tuple from n)
(! from (factorial n))
(factorial-server))))
(defun factorial
((0) 1)
((n) (* n (factorial (- n 1)))))
(defun run (n)
(let ((pid (spawn #'universal-server/0)))
(! pid (tuple 'become #'factorial-server/0))
(! pid (tuple (self) n)))
(receive
(x x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment