Re: clip and chop down consecutive "internal" white spaces to one
Thanks Alex, In the context of : (glue " " (filter prog (split (chop " s pac e s") " "))) -> "s pac e s" where : (split (chop " s pac e s") " ") -> (NIL NIL ("s") NIL ("p" "a" "c") ("e") ("s")) it is not immediately obvious to me that the arguments passed to the (filter prog ..) are treated as they are. I'll have to think about it some more... and write more picolisp! but I am confident I will figure it out in time =) /Lindsay
Re: clip and chop down consecutive "internal" white spaces to one
Thanks Alex. I was sure there was something like 'bool' to replace '((E) E)... I just could not find it at the time. =) I am surprised that 'prog works. Why, in this context, does it treat it's argument as 'data'? Given (NIL NIL NIL ("s" "p" "a" "a" "a" "c" "e" "s" ",") : (prog NIL) -> NIL : (prog ("s" "p" "a" "a" "a" "c" "e" "s" ",")) !? ("s" "p" "a" "a" "a" "c" "e" "s" ",") "s" -- Undefined ? (prog '("s" "p" "a" "a" "a" "c" "e" "s" ",")) -> ("s" "p" "a" "a" "a" "c" "e" "s" ",") /Lindsay
Re: clip and chop down consecutive "internal" white spaces to one
Hi Alex Thank you very much for the elaboration. It helps a lot. Best Regards Dean On 18 February 2017 at 08:11, Alexander Burgerwrote: > Hi Lindsay, > > >(glue C (filter '((E) E) (split (chop S) C > > I would do the same. > > Just one minor improvement: > > Because calling an EXPR function like ((E) E) is relatively expensive, I > generally recommend to use 'prog' for the identity function: > >(glue C (filter prog (split (chop S) C > >: ('((E) E) 123) >-> 123 > >: (prog 123) >-> 123 > > > In the above case, where we just filter the list and and thus just need a > boolean result, I'd use 'bool': > >(glue C (filter bool (split (chop S) C > > ♪♫ Alex > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >
Re: clip and chop down consecutive "internal" white spaces to one space??
Joe, LindsayYes! they both do it and are MUCH slicker :) than the improvement I managed overnight i.e. moving the clip down into the for loop :) That's great. Thank you very much. (de shrink (Str) (pack (let (Last_ch "A") (make (for Ch (clip (chop Str)) (if (<> Ch " ") (if (= Last_ch " ") (link (pack " " Ch)) (link Ch))) (setq Last_ch Ch)) Best Regards Dean On 18 February 2017 at 06:39, Lindsay John Lawrence < lawrence.lindsayj...@gmail.com> wrote: > > (de trimmr (S C) >(default C " ") >(glue C (filter '((E) E) (split (chop S) C > > : (setq Str " spaaaces, spaaaces everywhere spaaaces spaaaces r so > squuare ") > -> " spaaaces, spaaaces everywhere spaaaces spaaaces r so squuare " > : (trimmr (trimmr Str) "a") > > -> "spaces, spaces everywhere spaces spaces r so squuare" > > /Lindsay >
Re: clip and chop down consecutive "internal" white spaces to one
Hi Lindsay, >(glue C (filter '((E) E) (split (chop S) C I would do the same. Just one minor improvement: Because calling an EXPR function like ((E) E) is relatively expensive, I generally recommend to use 'prog' for the identity function: (glue C (filter prog (split (chop S) C : ('((E) E) 123) -> 123 : (prog 123) -> 123 In the above case, where we just filter the list and and thus just need a boolean result, I'd use 'bool': (glue C (filter bool (split (chop S) C ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: clip and chop down consecutive "internal" white spaces to one space??
(de trimmr (S C) (default C " ") (glue C (filter '((E) E) (split (chop S) C : (setq Str " spaaaces, spaaaces everywhere spaaaces spaaaces r so squuare ") -> " spaaaces, spaaaces everywhere spaaaces spaaaces r so squuare " : (trimmr (trimmr Str) "a") -> "spaces, spaces everywhere spaces spaces r so squuare" /Lindsay
Re: clip and chop down consecutive "internal" white spaces to one space??
fun does this do it? (pack (mapcon '((X) (ifn (= '(" " " ") (head 2 X)) (cons (car X (chop S))) -> " this contains 2 consecutive spaces " On Feb 17, 2017 5:23 PM, "dean"wrote: > I've done this and it works but...is there a slicker way :) > > (setq S " this contains 2 consecutive spaces ") > > (de shrink (Str) >#can't clip before inner pack so need to pack, chop, clip and re-pack >(pack > (clip > (chop > (pack >(let (Last_ch " ") >(make > (for Ch (chop Str) > (if (<> Ch " ") > (if (= Last_ch " ") >(link (pack " " Ch)) >(link Ch))) > (setq Last_ch Ch) > > > (prinl "'" (shrink S) "'") > > #'this contains 2 consecutive spaces' > > >
clip and chop down consecutive "internal" white spaces to one space??
I've done this and it works but...is there a slicker way :) (setq S " this contains 2 consecutive spaces ") (de shrink (Str) #can't clip before inner pack so need to pack, chop, clip and re-pack (pack (clip (chop (pack (let (Last_ch " ") (make (for Ch (chop Str) (if (<> Ch " ") (if (= Last_ch " ") (link (pack " " Ch)) (link Ch))) (setq Last_ch Ch) (prinl "'" (shrink S) "'") #'this contains 2 consecutive spaces'