From: pietru@caramail.com
To: Jean Louis <bugs@gnu.support>
Cc: Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Re: Passing a list to an interactive function
Date: Sat, 19 Dec 2020 05:29:50 +0100 [thread overview]
Message-ID: <trinity-4394e30c-590a-43cf-8e01-f1cc8032271c-1608352190403@3c-app-mailcom-bs02> (raw)
In-Reply-To: <X914Nb4gHxGnD95c@protected.rcdrun.com>
Am trying to fill variables "ta tb tc" with the numbers from "tlist"
(defun thermoluminesce (tseq)
"Sets thermoluminesce."
(interactive "stseq: ")
(message "stseq: %s " tseq)
(let ((slist (split-string tseq))
tlist ta tb tpab)
(message "slist: %s" slist)
(message "tlist: %s" tlist)
(message "tlen: %d" (length tlist))
(setq tlist (mapcar #'string-to-number slist))
;;(setq ta (nth 1 tlist))
;;(setq tb (nth 2 tlist))
;;(setq tc (nth 3 tlist))
(message "ta tb tc: %d %d %d" ta tb tc) ))
> Sent: Saturday, December 19, 2020 at 4:49 AM
> From: "Jean Louis" <bugs@gnu.support>
> To: pietru@caramail.com
> Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Passing a list to an interactive function
>
> * 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)
>
>
>
next prev parent reply other threads:[~2020-12-19 4:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-18 11:05 Passing a list to an interactive function pietru
2020-12-18 11:30 ` Jean Louis
2020-12-18 11:38 ` pietru
2020-12-18 11:49 ` Joost Kremers
2020-12-18 11:50 ` tomas
2020-12-18 11:56 ` Jean Louis
2020-12-19 2:05 ` pietru
2020-12-19 3:25 ` Jean Louis
2020-12-19 3:34 ` pietru
2020-12-19 3:49 ` Jean Louis
2020-12-19 4:29 ` pietru [this message]
2020-12-19 5:54 ` Jean Louis
2020-12-19 11:03 ` pietru
2020-12-19 6:23 ` Michael Heerdegen
2020-12-19 6:26 ` pietru
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-4394e30c-590a-43cf-8e01-f1cc8032271c-1608352190403@3c-app-mailcom-bs02 \
--to=pietru@caramail.com \
--cc=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).