Created
August 12, 2011 04:49
-
-
Save jeremytregunna/1141482 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* 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