Skip to content

Commit

Permalink
Create gh-pages branch via GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
libsteve committed Oct 2, 2013
1 parent db33e4a commit d6aa294
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h1>
<h2>
<a name="abstract-data-types" class="anchor" href="#abstract-data-types"><span class="octicon octicon-link"></span></a>Abstract Data Types</h2>

<p>Uisng the <code>datatype(dataname, ...)</code>, <code>datatypeempty(dataname, option)</code>, and <code>datatypedefine(dataname, option, structure)</code> macros, you can create Haskell style abstract data types.</p>
<p>Uisng the <code>datatype(dataname, ...)</code>, <code>datatypeatom(dataname, option)</code>, and <code>datatypedefine(dataname, option, structure)</code> macros, you can create Haskell style abstract data types.</p>

<p>Haskell Example:</p>

Expand Down Expand Up @@ -86,6 +86,30 @@ <h2>
whereatom(NoneInt) return 0;
where(JustInt, j) return j-&gt;number;
endcaseof;
return 0; // we unfortunately need a dummy return value to avoid a compiler warning
}
</code></pre>

<h2>
<a name="closures" class="anchor" href="#closures"><span class="octicon octicon-link"></span></a>Closures</h2>

<p>Using the <code>closure(type, fn, context, ...)</code> and <code>call(fn, context, ...)</code> macros, you can create a kind of closure over desired values for functions. This can be useful to easily create context for function calls.</p>

<p>Haskell Example:</p>

<pre><code>f :: Int -&gt; Int
f x = fhelper 5
where fhelper y = x + y
</code></pre>

<p>Chunktional Example:</p>

<pre><code>closure(int, fhelper, {int x;}, int y) {
return closure.x + y;
}

int f(int x) {
return call(fhelper, {x}, 5);
}
</code></pre>
</section>
Expand Down
2 changes: 1 addition & 1 deletion params.json
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."}

0 comments on commit d6aa294

Please sign in to comment.