Repeat a string: Difference between revisions
Content added Content deleted
(Add Racket examples) |
(→{{header|Forth}}: fix bizarre formatting... oh wait, this code is obviously wrong. Funny how that works.) |
||
Line 334: | Line 334: | ||
n 0 ?do src len dest +place loop ; |
n 0 ?do src len dest +place loop ; |
||
⚫ | |||
create test 256 allot |
|||
⚫ | |||
⚫ | |||
⚫ | |||
The same code without the use of locals: |
The same code without the use of locals: |
||
<lang forth> |
<lang forth> |
||
: place-n |
: place-n ( src len dest n -- ) |
||
swap >r 0 r@ c! |
|||
begin dup while -rot 2dup r@ +place rot 1- repeat |
|||
r> 2drop 2drop ; |
|||
⚫ | |||
create test 256 allot |
|||
⚫ | |||
⚫ | |||
⚫ | |||
Filling a string with a single character is supported by ANS-Forth: |
Filling a string with a single character is supported by ANS-Forth: |
||
<lang forth> |
<lang forth>pad 10 char * fill \ repeat a single character |
||
⚫ | |||
test 10 char * fill \ repeat a single character |
|||
⚫ | |||
=={{header|Fortran}}== |
=={{header|Fortran}}== |