Skip to content

Instantly share code, notes, and snippets.

@jeremytregunna
Created August 12, 2011 04:49
Show Gist options
  • Select an option

  • Save jeremytregunna/1141482 to your computer and use it in GitHub Desktop.

Select an option

Save jeremytregunna/1141482 to your computer and use it in GitHub Desktop.
/* Converts any Io method (You'll have to wrap CFunctions in an Io method for those to work) to continuation passing style */
/* This is working code, not code someone posted asking for help. Feel free to use how you want, public domain. */
Object convertToCPS := method(str,
m := self getSlot(str)
blk := Block clone
blk setArgumentNames(getSlot("m") argumentNames append("__k"))
blk setMessage(Message clone fromString("__k call(self performWithArgList(\"#{str}\", call evalArgs append(__k)))" interpolate))
self setSlot("#{str}CPS" interpolate, blk setIsActivatable(true))
)
Number sub := method(x, self - x)
Number convertToCPS("sub")
8 subCPS(5, block(n, n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment