Skip to content

Instantly share code, notes, and snippets.

@sundbp
Created October 3, 2012 17:05
Show Gist options
  • Select an option

  • Save sundbp/3828347 to your computer and use it in GitHub Desktop.

Select an option

Save sundbp/3828347 to your computer and use it in GitHub Desktop.
draft DSL
; indicate that there will be someting called a future
;
; can use to prepare space in some global structure for all known
; entity tupes and things like that.
;
; also use it to create default constructor and convenience
; type methods
;
; also makes it possible to stick in a documentation string as well
(def-entity future
"a documentation string for the future")
(def-property contract-month
"optional description"
[fut]
tk/time ;optional explicit time dependency
(time/local-now)) ;after which follows an optional initializer body
(def-property expiration-date [fut] ; no docstring
tk/time
(time/local-now))
(def-has-one contract-spec [fut]) ;no docstring, default time dep and no initializer
(def-has-one futures-mark ;doc, marks time initializer
"the mark for this future"
[fut]
tk/marks-time
(get-futures-mark (cps (contract-spec fut)) (contract-month fut)))
(def-has-one price-ccy
"the ccy of the price for this future"
[fut]) ;only doctstring, default time and no initializer
(def-calc price
"optional description.."
[fut]
;bindings to be used for dependencies
;operations involving getting other node values outside these bindings will fail
;at runtime
[[mark (futures-mark fut)]
[v (value mark)]]
v)
(def-calc dollar-cross [fut]
[[usd (get-ccy "USD")]
[ccy (price-ccy fut)]]
(get-fx-cross ccy usd))
(def-calc dollar-price [fut]
[[price (price fut)]
[fx-rate (price (dollar-cross fut))]]
(* price fx-rate))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment