Skip to content

Instantly share code, notes, and snippets.

@gatlin
Created August 11, 2012 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatlin/3326248 to your computer and use it in GitHub Desktop.
Save gatlin/3326248 to your computer and use it in GitHub Desktop.
Sample Orc DSL for Common Lisp
; examples from http://orc.csres.utexas.edu/tryorc.shtml#tryorc/tutorial/
; site definition, similar to a function but handles network transparency and will publish multiple values if you call them
; multiple times
; they will necessarily hide much magic
(defsite name (arg)
(body ...))
; I may consider using plain-old functions for this but at the moment I might need to hide some magic
; parallel site calls
; sites are prefixed with `site-`
; site-prompt is analogous to the Prompt site on the Orc demo page that returns user input
(par [(site-prompt "Spoon or fork?")
(site-prompt "Bowl or saucer?")]) ; both responses are theoretically retrieved, though we do nothing with them
; sequential - the result of the first site call could be bound to x and used as an arg for the second
(seq (x)
(site-prompt "What was the last movie that you saw?")
(site-prompt "Was it good?"))
; parallel sequential - write will be called twice as each parallel computation returns
(seq (movie)
(par [(site-prompt "Pick a movie you like: ")
(site-prompt "Pick a movie you like: ")])
(write-line "I heard that %s was a good movie" movie))
; pruning - return the first value produced by a site computation; write will only happen once here
; imagine a write function which takes a value and writes it to the screen
; also note that what par returns behaves like a site so pruning is very useful when combined with par
(write
(prune
(par [(site-prompt "Apples or oranges?")
(site-prompt "Grapes or mangos?")])))
; parallel pruning - "red" and "blue" will be written immediately, and the middle computation will wait
(par [(write "red")
(write
(concat "light"
(prune (site-prompt "Choose a color: "))))
(write "blue")])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment