Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -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 ;

View file

@ -0,0 +1 @@
reverse("foo");

View file

@ -0,0 +1,6 @@
#charset utf8
void main()
{
string s = "ßÜÖÄüöää ἀρχῇ";
write("%s\n", string_to_utf8( reverse(s) ));
}

View file

@ -1,2 +1 @@
with strings'
"asdf" reverse puts
'asdf s:reverse s:put