Skip to content

Instantly share code, notes, and snippets.

@crcx
Created April 18, 2018 17:10
Show Gist options
  • Save crcx/2ba73ba23239614f9c1d76a8e5e44511 to your computer and use it in GitHub Desktop.
Save crcx/2ba73ba23239614f9c1d76a8e5e44511 to your computer and use it in GitHub Desktop.
Implement `choose`, a conditional combinator which will execute one of
two functions, depending on the state of a flag. We take advantage of
a little hack here. Store the pointers into a jump table with two
fields, and use the flag as the index. Default to the *false* entry,
since a *true* flag is -1.
~~~
: choice:true
d 0
: choice:false
d 0
: choose
i listlist
r choice:false
r choice:true
i liadfeca
r choice:false
i re......
~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment