diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/uniq.fwd | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/uniq.fwd b/examples/uniq.fwd new file mode 100644 index 0000000..490a702 --- /dev/null +++ b/examples/uniq.fwd @@ -0,0 +1,33 @@ +/* not entirely sure about the final syntax just yet but something like this */ + +/* at some point I'll probably add in a type system as well, but for now let's + * pretend we're static-dynamic (or dynamic at compiletime? dunno) */ +readlines(set, next) +{ + /* option![str] */ + fwd_getline() => line; + + /* unwraps option![str] -> str */ + fwd_some(line) => line { + /* we had something in our option */ + fwd_insert(set, line) => set; + + /* at the moment the only supported looping construct is + * recursion */ + readlines(set, next); + } => { + /* option was illegal, we've read all input there is */ + next(set); + } +} + +main() +{ + /* fwdlib.hpp uses namespace std, not good practice but allows us to do + * stuff like this: */ + unordered_set![string]{} => set; + readlines(set) => set; + fwd_foreach(set) => node { + fwd_println(node); + } +} |