After trying to figure it out myself for a few minutes, I remembered to check rosettacode (wonderful resource). This is probably close to what you need: http://rosettacode.org/wiki/Globally_replace_text_in_several_files#PicoLisp
On Tue, Feb 21, 2017 at 8:08 AM, Joe Bogner <joebog...@gmail.com> wrote: > Hi dean, > > I experimented with this problem for a few minutes and didn't come up with > anything worth posting. A few comments though: > > 1. Your picolisp code is becoming easier to read. Nice work! > 2. My initial thought was to split the input into words and replace > sublists, however it looks like you don't have a word delimiter (typically > a space)...Since you need to be able to substitute "fl ow" with "flow". As > a result, the best I came up with is something similar (looping through > characters and testing the replacement) > 3. Why do you need to work with bytes vs chars? (mapcar char (chop > Sfrom)) ? > > > > On Tue, Feb 21, 2017 at 3:37 AM, dean <deangwillia...@gmail.com> wrote: > >> I need to globally replace certain words in a text file and because >> I need to process it a byte at a time initially...I'm inputting >> processed list of bytes into the global replace function "lchg" >> (and others) like this. >> >> (lbytes_to_fl Cleaned_txt_pth >> (lchg "fl ow" "flow" >> (fltr2 >> (fltr1 >> (fl_to_lbytes Txt_pth))))) >> >> The other filters seem ok but this one is slow (most likely my >> algorithm/general approach :)) and any help to >> speed things up would be much appreciated. >> >> (de lchg (Sfrom Sto Lbytes) >> (make >> (let >> (X 0 >> B NIL >> Lfrom (mapcar char (chop Sfrom)) >> Lto (mapcar char (chop Sto)) >> First_from_ch (car Lfrom) >> Len_from-1 (- (length Lfrom) 1) >> Len_lbytes (length Lbytes) ) >> (until (<= (length Lbytes) X) >> (inc 'X) >> (setq B (get Lbytes X)) >> (if (= B First_from_ch) >> (prog >> (if (= (slice Lbytes X (+ X Len_from-1)) Lfrom) >> (prog >> (for MatchB Lto >> (link MatchB) ) >> (inc 'X Len_from-1) ) >> (link B) ) ) >> (link B) ) ) ) ) ) >> >> (de slice (Lst I K) (head (inc (- K I)) (nth Lst I)) ) #99 >> >> Here's "lchg" in action... >> >> : (setq L (chop "ab fl ow flow fl ow yz")) >> -> ("a" "b" " " "f" "l" " " "o" "w" " " "f" "l" "o" "w" " " "f" "l" " " >> "o" "w" " " "y" "z") >> : (pack (mapcar char (lchg "fl ow" "flow" (mapcar char L)))) >> -> "ab flow flow flow yz" >> >> >