Created
January 27, 2016 21:49
-
-
Save svard/6b9a171acac07aa922c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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