YAPC::EU 2018 Glasgow Update!

This commit is contained in:
Ingy döt Net 2018-08-17 15:15:24 +01:00
parent 22f33d4004
commit 4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions

View file

@ -9,8 +9,8 @@
: STRLEN ( addr -- length) c@ ; \ alias the "character fetch" operator
: COUNT ( addr -- addr+1 length) \ returns the address+1 and the length byte on the stack
dup strlen swap 1+ swap ;
: COUNT ( addr -- addr+1 length) \ Standard word. Shown for explanation
dup strlen swap 1+ swap ; \ returns the address+1 and the length byte on the stack
: ENDSTR ( str -- addr) \ calculate the address at the end of a string
COUNT + ;
@ -25,10 +25,10 @@
>r COUNT R> APPEND ;
: PLACE ( addr1 len addr2 -- ) \ addr1 and length, placed at addr2 as counted string
2dup 2>r 1+ swap move 2r> c! ;
2dup 2>r char+ swap move 2r> c! ;
: STRING, ( addr len -- ) \ compile a string at the next available memory (called 'HERE')
here over 1+ allot place ;
here over char+ allot place ;
: APPEND-CHAR ( char string -- ) \ append char to string
dup >r count dup 1+ r> c! + c! ;
@ -72,12 +72,12 @@
string: strpad \ general purpose storage buffer
: substr ( string1 start length -- strpad) \ Extract a substring of string and return an output string
strpad ="" \ clear strpad
>r \ push the length
+ \ calc the new start addr
r> strpad append \ pop the length and append to strpad
strpad ; \ return the address of strpad.
>r >r \ push start,length
count \ compute addr,len
r> 1- /string \ pop start, subtract 1, cut string
drop r> \ drop existing length, pop new length
strpad place \ place new stack string in strpad
strpad ; \ return address of strpad
\ COMPARE takes the 4 inputs from the stack (addr1 len1 addr2 len2 )
\ and returns a flag for equal (0) , less-than (1) or greater-than (-1) on the stack

View file

@ -14,7 +14,7 @@ if x.len == 0: echo "empty" # check if empty
x.add('!') # append a byte
echo x[5..8] # substring
echo x[8 .. -1] # substring
echo x[8 .. ^1] # substring
z = x & y # join strings

View file

@ -3,16 +3,17 @@ dingsta= '11110101'b /*four versions, bit string ass
dingsta= "11110101"b /*this is the same assignment as above.*/
dingsta= '11110101'B /* " " " " " " " */
dingsta= '1111 0101'B /* " " " " " " */
dingsta2=dingsta /*clone one string to another (a copy).*/
dingsta2= dingsta /*clone one string to another (a copy).*/
other= '1001 0101 1111 0111'b /*another binary (or bit) string. */
if dingsta=other then say 'they are equal' /*compare the two (binary) strings. */
if other=='' then say 'OTHER is empty.' /*see if the OTHER string is empty.*/
otherA=other || '$' /*append a dollar sign ($) to OTHER. */
otherB=other'$' /*same as above, but with less fuss. */
guts=substr(c2b(other), 10, 3) /*obtain the 10th through 12th bits.*/
new=changeStr('A', other, "Z") /*change the upper letter A ──► Z. */
tt=changeStr('~~', other, ";") /*change two tildes ──► one semicolon.*/
joined=dignsta || dingsta2 /*join two strings together (concat). */
if dingsta= other then say 'they are equal' /*compare the two (binary) strings. */
if other== '' then say "OTHER is empty." /*see if the OTHER string is empty.*/
otherA= other || '$' /*append a dollar sign ($) to OTHER. */
otherB= other'$' /*same as above, but with less fuss. */
guts= substr(c2b(other), 10, 3) /*obtain the 10th through 12th bits.*/
new= changeStr('A' , other, "Z") /*change the upper letter A ──► Z. */
tt= changeStr('~~', other, ";") /*change two tildes ──► one semicolon.*/
joined= dingsta || dingsta2 /*join two strings together (concat). */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
c2b: return x2b( c2x( arg(1) ) ) /*return the string as a binary string.*/