help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Passing a list to an interactive function


From: Jean Louis
Subject: Re: Passing a list to an interactive function
Date: Sat, 19 Dec 2020 06:49:09 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

* pietru@caramail.com <pietru@caramail.com> [2020-12-19 06:34]:
> I decided towards a simpler strategy by passing a string with numbers
> separated by spaces.  But inside the function, I got to convert from
> string to a list containing numbers.
> 
> How  could I convert to a list containing numbers.
> 
> Example of string: "3 5 13"

Function `read-number' ensured you get the number. If function is for
you it is fine, if it is for others you risk not getting a number. If
data goes to database which also accepts string you risk losing
data as you maybe did not get a number.

If user writes spaces before numbers or after numbers or multiple
spaces between you need to remove such.

(setq my-worse-string "  1 2  3 4  5 6    ")

(setq my-string (split-string my-worse-string) ;; it will convert to numbers

my-string becomes => ("1" "2" "3" "4" "5" "6")

      Inspect `split-string' as it can omit nulls and trim
      strings automatically. But I did not here include those
      switches, as it does so by default.

Then you need to convert list of strings to list of numbers:
      
(mapcar #'string-to-number my-string)




reply via email to

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