Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
|
|
@ -1,18 +1,7 @@
|
|||
\ reverse a counted string using the stack
|
||||
\ Method: Read the input string character by character onto the parameter stack
|
||||
\ Then write the character back into the same string from the stack
|
||||
\ reverse a string using the data stack for temporary storage
|
||||
|
||||
create mystring ," ABCDEFGHIJKLMNOPQRSTUVWXYZ987654321" \ this is a counted string
|
||||
: mystring ( -- caddr len) S" ABCDEFGHIJKLMNOPQRSTUVWXYZ987654321" ;
|
||||
|
||||
: pushstr ( str -- char[1].. char[n]) \ read the contents of STR onto the stack
|
||||
count bounds do I c@ loop ;
|
||||
|
||||
: popstr ( char[1].. char[n] str -- ) \ read chars off stack into str
|
||||
count bounds do I c! loop ;
|
||||
|
||||
: reverse ( str -- ) \ create the reverse function with the factored words
|
||||
dup >r \ put a copy of the string addr on return stack
|
||||
pushstr \ push the characters onto the parameter stack
|
||||
r> popstr ; \ get back our copy of the string addr and pop the characters into it
|
||||
|
||||
\ test in the Forth console
|
||||
: pushstr ( caddr len -- c..c[n]) bounds do I c@ loop ;
|
||||
: popstr ( c.. c[n] caddr len -- ) bounds do I c! loop ;
|
||||
: reverse ( caddr len -- ) 2dup 2>r pushstr 2r> popstr ;
|
||||
|
|
|
|||
1
Task/Reverse-a-string/Pike/reverse-a-string-1.pike
Normal file
1
Task/Reverse-a-string/Pike/reverse-a-string-1.pike
Normal file
|
|
@ -0,0 +1 @@
|
|||
reverse("foo");
|
||||
6
Task/Reverse-a-string/Pike/reverse-a-string-2.pike
Normal file
6
Task/Reverse-a-string/Pike/reverse-a-string-2.pike
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#charset utf8
|
||||
void main()
|
||||
{
|
||||
string s = "ßÜÖÄüöää ἀρχῇ";
|
||||
write("%s\n", string_to_utf8( reverse(s) ));
|
||||
}
|
||||
|
|
@ -1,2 +1 @@
|
|||
with strings'
|
||||
"asdf" reverse puts
|
||||
'asdf s:reverse s:put
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue