emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rationale for split-string?


From: Stefan Reichör
Subject: Re: Rationale for split-string?
Date: Thu, 17 Apr 2003 13:30:01 +0200
User-agent: Gnus/5.090018 (Oort Gnus v0.18) Emacs/21.3.50 (windows-nt)

On Thu, 17 Apr 2003, Stephen J. Turnbull said:

>  What is the rationale for the specification of `split-string'?
>  
>  That is, in GNU Emacs
>  
>    ;; an often convenient abbreviation
>    (split-string "  data  ")
>  => ("data")
>  
>    ;; weird
>    (split-string "  data  " " ")
>  => ("" "data" "")
>  
>    ;; urk (think "gnumeric just-say-no.xls" "save as" "csv")
>    (split-string ",,data,," ",")
>  => ("" "data" "")
>  
>  emacs-version
>  "21.2.2"
>  
>  In XEmacs currently we get
>  
>    ;; usually (delete "" (split-string "  data  ")) should do the
>    ;; trick if you don't like this
>    (split-string "  data  ")
>  => ("" "data" "")
>  
>    ;; no less useful than what GNU Emacs returns
>    (split-string "  data  " " ")
>  => ("" "" "data" "" "")
>  
>    ;; I can't imagine wanting anything else
>    (split-string ",,data,," ",")
>  => ("" "" "data" "" "")
>  
>  For comparison, Python's `split' function behaves like XEmacs's
>  `split-string'. Perl's `split' function by default removes all
>  trailing null fields while preserving all leading null fields, but
>  when invoked "split (/pattern/, string, -1)" behaves like XEmacs's
>  `split-string'.
>  
>  I think it makes sense for GNU Emacs to adopt (return to?) the
>  simpler, more consistent behavior, rather than have XEmacs sync to
>  GNU Emacs. In particular, I think it's really unfortunate to force
>  people who want to parse csv data and the like to write their own
>  functions, while the `(delete "" (split-string ...))' idiom not
>  only seems very natural to me, but it handles the second example
>  better than GNU Emacs currently does. And while I'm sure there
>  exist applications where trimming null fields at the ends but
>  leaving them when surrounded by non-null ones make sense, I can't
>  come up with one offhand. I suspect they're less common than either
>  "remove all nulls" or "keep all nulls".
>  
>  I believe that (at least for third-party maintainers) this change
>  should cause no problems, because we have had no complaints about
>  the behavior from anyone. (We discovered the difference only when
>  Ben started a sync, and the regression test sent up flares and
>  alarums.)

I noticed the different behavior of the split-string function,
because I need to parse csv output from subversion. Now I need
different code for the two platforms.

I would welcome, if the GNU Emacs and XEmacs would have the same
split-string implementation.

Stefan.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]