diff --git a/index.html b/index.html index 353824b..29c686b 100644 --- a/index.html +++ b/index.html @@ -39,7 +39,7 @@
Uisng the datatype(dataname, ...)
, datatypeempty(dataname, option)
, and datatypedefine(dataname, option, structure)
macros, you can create Haskell style abstract data types.
Uisng the datatype(dataname, ...)
, datatypeatom(dataname, option)
, and datatypedefine(dataname, option, structure)
macros, you can create Haskell style abstract data types.
Haskell Example:
@@ -86,6 +86,30 @@Using 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.
Haskell Example:
+ +f :: Int -> Int
+f x = fhelper 5
+ where fhelper y = x + y
+
+
+Chunktional Example:
+ +closure(int, fhelper, {int x;}, int y) {
+ return closure.x + y;
+}
+
+int f(int x) {
+ return call(fhelper, {x}, 5);
}
diff --git a/params.json b/params.json
index f214827..8f909c5 100644
--- a/params.json
+++ b/params.json
@@ -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."}
\ No newline at end of file
+{"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."}
\ No newline at end of file