I’ve done a fizzbuzz without macro thanks to the new function pragmas!
\function .fizz(n) [<n>remainder[3]match[0]then[fizz]else<n>]
\function .buzz(n) [<n>remainder[5]match[0]then[buzz]else<n>]
\function .fizzbuzz(n) [.fizz<n>] [.buzz<n>] +[!match<n>join[]else<n>]
* fizz {{{ [range[17]] :map[.fizz<currentTiddler>] +[dump[fizz]join[ ]] }}}
* buzz {{{ [range[17]] :map[.buzz<currentTiddler>] +[dump[buzz]join[ ]] }}}
* fizzbuzz {{{ [range[17]] :map[.fizzbuzz<currentTiddler>] +[dump[fizzbuzz]join[ ]] }}}
if I only wanted fizzbuzz and not use neither fizz nor buzz out of fizzbuzz, I could have it in less code:
\function .fizz(n) [<n>remainder[3]match[0]then[fizz]]
\function .buzz(n) [<n>remainder[5]match[0]then[buzz]]
\function .fizzbuzz(n) [.fizz<n>] [.buzz<n>] +[join[]else<n>]
* fizzbuzz {{{ [range[17]] :map[.fizzbuzz<currentTiddler>] +[dump[fizzbuzz]join[ ]] }}}
But then fizz and buzz still exists in the wild. It would be nice if we could restrict them to fizzbuzz. For instance, if the code below was OK.
\function .fizzbuzz(n)
\function .fizz(n) [<n>remainder[5]match[0]then[fizz]]
\function .buzz(n) [<n>remainder[5]match[0]then[buzz]]
[.fizz<n>] [.buzz<n>] +[join[]else<n>]
\end
We could do it with an import pragma like we can have for macro definition. Currently, \import do not cater for function definition. IMHO, it should.
in “fizzbuzz.private” tiddler:
\function .fizz(n) [<n>remainder[3]match[0]then[fizz]]
\function .buzz(n) [<n>remainder[5]match[0]then[buzz]]
and in “fizzbuzz.public” tiddler:
\import [[fizzbuzz.private]]
\function .fizzbuzz(n) [.fizz<n>] [.buzz<n>] +[join[]else<n>]