Hi,

discovered a strange behaviour of the split function for Strings:

A very natural application is to read in a CSV file and get as many
Strings - possibly empty ones - as the number of occurencies of the
splitting character indicates (+1):

However:

(1) -> line := "A;B;;C;;"

   (1)  "A;B;;C;;"
                                                                 Type:
String
(2) -> c := char ";"

   (2)  ;
                                                              Type:
Character
(3) -> split(line, c)

   (3)  ["A","B","C"]
                                                           Type:
List(String)

This is not what I expect. Here is a fix in IndexedString:

    split(s, c) ==
        n := maxIndex s
        --for i in mn..n while s.i = c repeat 0
        i := mn
        l := empty()$List(%)
        j : Integer -- j is conditionally intialized
        while i <= n and (j := position(c, s, i)) >= mn repeat
            l := concat(s(i..j-1), l)
            --for i in j..n while s.i = c repeat 0
            i := j+1
        --if i <= n then l := concat(s(i..n), l)
        l := concat(s(i..n), l)
        reverse! l
    split(s, cc) ==
        n := maxIndex s
        --for i in mn..n while member?(s.i, cc) repeat 0
        l := empty()$List(%)
        i := mn
        j : Integer -- j is conditionally intialized
        while i <= n and (j := position(cc, s, i)) >= mn repeat
            l := concat(s(i..j-1), l)
            --for i in j..n while member?(s.i, cc) repeat 0
            i := j+1
        --if i <= n then l := concat(s(i..n), l)
        l := concat(s(i..n), l)
        reverse! l

and now:

(28) -> split(line, c)

   (28)  ["A","B","","C","",""]

as desired and expected 

If there are good reasons - would like to know - for the current
implementation, then I would suggest to add a second a pair of split
functions of this behaviour, otherwise I would suggest to switch to this
interpretation.


-- 
Mit freundlichen Grüßen

Johannes Grabmeier

Prof. Dr. Johannes Grabmeier
Köckstraße 1, D-94469 Deggendorf
Tel. +49-(0)-991-2979584, Tel. +49-(0)-151-681-70756
Tel. +49-(0)-991-3615-141 (d),  Fax: +49-(0)-3224-192688

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to