-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"name":"Chunktional","tagline":"Functional Macros for C","body":"#Chunktional\r\n\r\nChunktional is a collection of macros that can make functional style programming in C convenient.\r\n\r\n##Abstract Data Types\r\n\r\nUisng the `datatype(dataname, ...)`, `datatypeempty(dataname, option)`, and `datatypedefine(dataname, option, structure)` macros, you can create Haskell style abstract data types.\r\n\r\nHaskell Example:\r\n\r\n\tdatatype Maybe = None | Just x\r\n\r\n\tx = None\r\n\ty = Just 10\r\n\r\nChunktional Example:\r\n\r\n\tdatatype(MaybeInt, NoneInt, JustInt);\r\n\tdatatypeempty(MaybeInt, NoneInt);\r\n\tdatatypedefine(MaybeInt, JustInt, {int number;});\r\n\r\n\tint main() {\r\n\t\tMaybeInt *x = mkdatatype(NoneInt);\r\n\t MaybeInt *y = mkdatatype(JustInt, 10);\r\n\r\n\t\tfree(x);\r\n\t\tfree(y);\r\n\r\n\t\treturn 0;\r\n\t}\r\n\r\n##Pattern Matching\r\n\r\nUsing the `caseof(value)`, `endcaseof`, `where(option, result)`, `whereatom(option)`, and `otherwise` macros, you can create a kind of case-of statement for use with the abstract data types.\r\n\r\nHaskell Example:\r\n\r\n\tf :: Maybe Int -> Int\r\n\tf m = case m of\r\n\t\t\tNone -> 0\r\n\t\t\tJust x -> x\r\n\r\nChunktional Example:\r\n\r\n\tint f(MaybeInt *m) {\r\n\t\tcaseof(m)\r\n\t whereatom(NoneInt) return 0;\r\n\t where(JustInt, j) return j->number;\r\n\t endcaseof;\r\n\t}\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} | ||
{"name":"Chunktional","tagline":"Functional Macros for C","body":"#Chunktional\r\n\r\nChunktional is a collection of macros that can make functional style programming in C convenient.\r\n\r\n##Abstract Data Types\r\n\r\nUisng the `datatype(dataname, ...)`, `datatypeatom(dataname, option)`, and `datatypedefine(dataname, option, structure)` macros, you can create Haskell style abstract data types.\r\n\r\nHaskell Example:\r\n\r\n\tdatatype Maybe = None | Just x\r\n\r\n\tx = None\r\n\ty = Just 10\r\n\r\nChunktional Example:\r\n\r\n\tdatatype(MaybeInt, NoneInt, JustInt);\r\n\tdatatypeempty(MaybeInt, NoneInt);\r\n\tdatatypedefine(MaybeInt, JustInt, {int number;});\r\n\r\n\tint main() {\r\n\t\tMaybeInt *x = mkdatatype(NoneInt);\r\n\t MaybeInt *y = mkdatatype(JustInt, 10);\r\n\r\n\t\tfree(x);\r\n\t\tfree(y);\r\n\r\n\t\treturn 0;\r\n\t}\r\n\r\n##Pattern Matching\r\n\r\nUsing the `caseof(value)`, `endcaseof`, `where(option, result)`, `whereatom(option)`, and `otherwise` macros, you can create a kind of case-of statement for use with the abstract data types.\r\n\r\nHaskell Example:\r\n\r\n\tf :: Maybe Int -> Int\r\n\tf m = case m of\r\n\t\t\tNone -> 0\r\n\t\t\tJust x -> x\r\n\r\nChunktional Example:\r\n\r\n\tint f(MaybeInt *m) {\r\n\t\tcaseof(m)\r\n\t whereatom(NoneInt) return 0;\r\n\t where(JustInt, j) return j->number;\r\n\t endcaseof;\r\n\t return 0; // we unfortunately need a dummy return value to avoid a compiler warning\r\n\t}\r\n\r\n##Closures\r\n\r\nUsing the `closure(type, fn, context, ...)` and `call(fn, context, ...)` macros, you can create a kind of closure over desired values for functions. This can be useful to easily create context for function calls.\r\n\r\nHaskell Example:\r\n\r\n\tf :: Int -> Int\r\n\tf x = fhelper 5\r\n\t\twhere fhelper y = x + y\r\n\r\nChunktional Example:\r\n\r\n\tclosure(int, fhelper, {int x;}, int y) {\r\n\t\treturn closure.x + y;\r\n\t}\r\n\r\n\tint f(int x) {\r\n\t\treturn call(fhelper, {x}, 5);\r\n\t}\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} |