Skip to content

Instantly share code, notes, and snippets.

@draegtun
Last active December 16, 2015 07:59
Show Gist options
  • Save draegtun/5402764 to your computer and use it in GitHub Desktop.
Save draegtun/5402764 to your computer and use it in GitHub Desktop.
Simple Rebol dialect example.
REBOL [
Purpose: "Providing Rebol example of a Lisp macro given in HN comment"
HNcomment: https://news.ycombinator.com/item?id=5482124
usage: "select [word-value from collection-list]"
]
select: func [block /local totals] [
parse block [
set this word!
'from
set coll word!
(totals: map-each n (get coll) [n/:this])
]
totals
]
;;
;; Lets do some quick testing!
; global orders
orders: compose [(context [total: 10]) (context [total: 20])]
; in scope (context)
context [
orders: compose [(context [total: 100]) (context [total: 200])]
probe select [total from orders] ; => [100 200]
; check context within context!
context [
orders: compose [(context [total: 1000]) (context [total: 2000])]
probe select [total from orders] ; => [1000 2000]
]
; still back with this context?
probe select [total from orders] ; => [100 200]
]
probe select [total from orders] ; => [10 20]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment