Last active
November 13, 2018 16:03
-
-
Save porky11/125a3419fd99cb632b7bcf0573ec2194 to your computer and use it in GitHub Desktop.
Dynamic bindings in scope
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
let model model-normal = | |
static mat4 | |
static mat3 | |
typefn& Node 'render (self) | |
dynamic-let model model-normal = | |
'transform model self.transform | |
'transform model-normal self.transform-normal | |
if ('is-leaf self) | |
render-mesh self.mesh model model-normal | |
else | |
for child in self.children | |
'render child |
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
let model model-normal = | |
static mat4 | |
static mat3 | |
typefn& Node 'render (self) | |
let old-model old-model-normal = | |
deref model | |
deref model-normal | |
model = | |
'transform model self.transform | |
model-normal = | |
'transform model-normal self.transform-normal | |
if ('is-leaf self) | |
render-mesh self.mesh model model-normal | |
else | |
for child in self.children | |
'render child | |
model = old-model | |
model-normal = old-model-normal |
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
typefn& Node 'render (self model model-normal) | |
let model model-normal = | |
'transform model self.transform | |
'transform model-normal self.transform-normal | |
if ('is-leaf self) | |
render-mesh self.mesh model model-normal | |
else | |
for child in self.children | |
'render child model model-normal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dynamic:
this version uses the new scope-macro
dynamic-let
, which temporary changes the globals for the current scopeexplicit:
this version does exactly the same, but without the use of the new scope macro, but instead typing everything explicitly
pass-around:
this version does the same, but passes everything around instead of using global variables
this doesn't need global variables, but you have to pass everything around
it may get inconvenient when having too many global variables
you may pack these variables into a struct or pass them around as variadic arguments, which will make it more convenient to pass around, but it's still necessary to pass it around at all
the problem when using a struct is, that you either have to revert the state anyway or you have a copy, where most of the variables are just the same
it's also more difficult to write generic code, when the API is not intended to use some global state, but you need global state in your use case