• Re: separating words

    From B. Pym@21:1/5 to Edward Fagan on Sat Sep 7 05:25:48 2024
    XPost: comp.lang.scheme

    Edward Fagan wrote:

    Something like this function will tell you the position of
    the last comma in a string.

    (defun find-last-comma (s)
    (loop for n from 0 below (length s)
    if (char= (aref s n) #\,)
    do
    (if (and (loop for n downfrom (1- (length s)) to 0
    if (char= (aref n s) #\,)
    return n
    finally (return nil))
    (= n (loop for n downfrom (1- (length s)) to 0
    if (char= (aref s n) #\,)
    return n
    finally (return nil))))
    (return-from find-last-coma n))
    finally (return nil)))

    Testing in SBCL:

    * (FIND-LAST-COMMA "hi, hi, ho")

    debugger invoked on a SIMPLE-TYPE-ERROR in thread
    #<THREAD "main thread" RUNNING {23EAC201}>:
    Value of N in (AREF N S) is 9, not a ARRAY.


    Gauche Scheme

    (string-scan-right "hi, hi, ho" #\,)
    ===>
    6

    (string-scan-right "hi, hi, ho" #\, 'before)
    ===>
    "hi, hi"

    (string-scan-right "hi, hi, ho" #\, 'after)
    ===>
    " ho"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)