Repeat: Difference between revisions
Content added Content deleted
m (→{{header|ALGOL W}}: Remove unneeded semicolon) |
(Added Quackery.) |
||
Line 1,294: | Line 1,294: | ||
(def h(x): |
(def h(x): |
||
return 1.05 * x)(100) -> 115.7625</pre> |
return 1.05 * x)(100) -> 115.7625</pre> |
||
=={{header|Quackery}}== |
|||
This is a function which is part of the Quackery language. ''times'' performs the word or nest after it the number of times specified on the stack. The definition is reproduced here, along with the additional functionality included in the language; ''i'' counts down to zero, ''i^'' counts up from zero, ''step'' specifies the increment size from an argument on the stack (default is 1), ''conclude'' sets the iteration countdown to the final value (0) and ''refresh'' sets the iteration countdown to the initial value. ''times'' is nestable, and words such as ''witheach'' (which makes use of ''times'' to iterate over a nest) inherit its additional functionality. |
|||
The word ''rosetta-times'' is also defined here, using ''times''. It takes both the repeat number and the function as stack arguments. |
|||
<lang Quackery> [ stack ] is times.start ( --> s ) |
|||
protect times.start |
|||
[ stack ] is times.count ( --> s ) |
|||
protect times.count |
|||
[ stack ] is times.action ( --> s ) |
|||
protect times.action |
|||
[ ]'[ times.action put |
|||
dup times.start put |
|||
[ 1 - dup -1 > while |
|||
times.count put |
|||
times.action share do |
|||
times.count take again ] |
|||
drop |
|||
times.action release |
|||
times.start release ] is times ( n --> ) |
|||
[ times.count share ] is i ( --> n ) |
|||
[ times.start share i 1+ - ] is i^ ( --> n ) |
|||
[ 0 times.count replace ] is conclude ( --> ) |
|||
[ times.start share |
|||
times.count replace ] is refresh ( --> ) |
|||
[ times.count take 1+ |
|||
swap - times.count put ] is step ( --> s ) |
|||
[ nested ' times nested |
|||
swap join do ] is rosetta-times ( n x --> )</lang> |
|||
{{Out}} |
|||
''rosetta-times'' demonstrated in the Quackery shell. (REPL) |
|||
<pre>/O> [ say "hello" cr ] is hi |
|||
... 5 ' hi rosetta-times |
|||
... |
|||
hello |
|||
hello |
|||
hello |
|||
hello |
|||
hello |
|||
Stack empty.</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |