Skip to content

Instantly share code, notes, and snippets.

@zah
Last active December 17, 2015 03:49
Show Gist options
  • Save zah/5546279 to your computer and use it in GitHub Desktop.
Save zah/5546279 to your computer and use it in GitHub Desktop.

@fowlmouth

<zahary_> fowl, sorry, turns out I haven't documented it yet

<zahary_> be warned that we have plans to rename it to static[string]

<zahary_> otherwise it's very simple - when the compiler see a parameter like that, it will try to evaluate statically the passed argument

  proc foo(a: expr[string])
  
  foo(callSomeOtherProcReturningString()) # becomes something like:
  
  const arg = static(callSomeOth...)
  foo(arg)

<zahary_> now, after this is done, we enter the second aspect of the feature. internally, the compiler treats procs with static params as generic procs and the compile-time value is the generic param

<zahary_> so just like a generic procs gets instantiated for each unique type they were used with, the expr[T] proc will be instantiated with each unique value

<zahary_> in my example code for the component-entity system, I was using this property to make sure that each message will get it's own ID (assigned at program start-up)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment