Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: REBOL Cookbook in Beta

From: nitsch-lists:netcologne at: 29-Aug-2003 6:57

Am Donnerstag, 28. August 2003 23:25 schrieb [carl--rebol--com]: [snip] More seasoning ideas: Could "find in file" and "read directory" be crosslinked? IIRC peoples expected find/any read %./ %*.r to work. instead we need a loop. modifying your example: files: read %docs/ remove-each file files [ not find/any/match file %*.r ;attention: do NOT remove ] probe files -- the article "Convert Text File Formats" shows another use of find, find [%.txt %.text] suffix? file also the example is nice for an article about "how to copy a directory"? !>> This code will copy all the text files found in your current directory: foreach file read %./ [ if find [%.txt %.text] suffix? file [ write/binary file read/binary file ] ] You can add additional file suffixes if necessary. (/me added /binary) <<! -- Get a Directory File List : it may be surprising that read %other-dir/ returns only the files, without directories. so foreach file read %other-dir/[ process-file file ] fails. must be dir: read %other-dir foreach file dir[ process-file dir/:file ;or join dir file ] -- How to process a directory recursive is also a frequent question. The masters example would be nice (will be used a lot as snippet i guess). -- Replace Text in a File In some places "reduction of variable use" is used, here explicitly mentioned: !>> Shortcut It is common practice in REBOL to remove extra code. The above example could also be written: foreach file read %./ [ if find [%.txt %.text] suffix? file [ write file replace/all read file "web" "rebol" ] ] <<! could be another article, "shortening code" i would give an example with explicit variables, then optimizing, but variables stay there as markers, then dropping the variables. !>> foreach file read %./ [ if find [%.txt %.text] suffix? file [ text: read file replace/all text "web" "rebol" write file text ] ] could also be written: foreach file read %./ [ if find [%.txt %.text] suffix? file [ write file replace/all TEXT: read file "web" "rebol" ] ] and since we don't need the variable now foreach file read %./ [ if find [%.txt %.text] suffix? file [ write file replace/all read file "web" "rebol" ] ] -- the above mentioned {how functions allocate "new" series} ( f: func[a][append [] a ] ;ouch ) out of the masters hand would be nice. needs explanation of design-decisions. demo using [source f], eventually mentioning obvious alternatives (me, early)? copy-on-write -> same? fails write-protection -> performance? what to protect (inner blocks too)? -- When using special technics in examples, they could have a line with links? ut of the head i would mention the needed {how rebol allocates "new" series} ( f: func[a][append [] a ] ;ouch ) and this expression chaining. -- the above mentioned {how functions allocate "new" series} ( f: func[a][append [] a ] ;ouch ) out of the masters hand would be nice. (explanation of design-decisions) a demo using [source f]. eventually mentioning obvious alternatives (me, early)? copy-on-write -> 'same? fails write-protection -> performance? what to protect (inner blocks too)? -- an article about clever probing, ?ing etc? its not we lack a debugger, we don't need one ;)
> -Carl
-Volker