* The different results obtained by apply function. @ 2021-10-07 2:46 Hongyi Zhao 2021-10-07 5:41 ` Michael Heerdegen 0 siblings, 1 reply; 5+ messages in thread From: Hongyi Zhao @ 2021-10-07 2:46 UTC (permalink / raw) To: help-gnu-emacs I try to reproduce the results given here [1], as follows: (mapcar 'list '((1 2)(3 4))) ;; (((1 2)) ((3 4))) (funcall 'mapcar 'list '((1 2)(3 4))) ;; (((1 2)) ((3 4))) (apply 'mapcar 'list '((1 2)(3 4)) ()) ;; (((1 2)) ((3 4))) The last one is different from the one given on the URL above: (apply 'mapcar 'list '((1 2)(3 4))) ;; ((1 3) (2 4)) [1] https://stackoverflow.com/a/68876647 Any hints for this? -- Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com> Theory and Simulation of Materials Hebei Vocational University of Technology and Engineering No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: The different results obtained by apply function. 2021-10-07 2:46 The different results obtained by apply function Hongyi Zhao @ 2021-10-07 5:41 ` Michael Heerdegen 2021-10-07 7:57 ` Hongyi Zhao 0 siblings, 1 reply; 5+ messages in thread From: Michael Heerdegen @ 2021-10-07 5:41 UTC (permalink / raw) To: help-gnu-emacs Hongyi Zhao <hongyi.zhao@gmail.com> writes: > The last one is different from the one given on the URL above: > > (apply 'mapcar 'list '((1 2)(3 4))) ;; ((1 3) (2 4)) That gives an error with Emacs Lisp - but please try with `cl-mapcar'. Is that enough as hint? Michael. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: The different results obtained by apply function. 2021-10-07 5:41 ` Michael Heerdegen @ 2021-10-07 7:57 ` Hongyi Zhao 2021-10-07 8:11 ` Emanuel Berg via Users list for the GNU Emacs text editor 0 siblings, 1 reply; 5+ messages in thread From: Hongyi Zhao @ 2021-10-07 7:57 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs On Thu, Oct 7, 2021 at 1:42 PM Michael Heerdegen <michael_heerdegen@web.de> wrote: > > Hongyi Zhao <hongyi.zhao@gmail.com> writes: > > > The last one is different from the one given on the URL above: > > > > (apply 'mapcar 'list '((1 2)(3 4))) ;; ((1 3) (2 4)) > > That gives an error with Emacs Lisp - but please try with `cl-mapcar'. > Is that enough as hint? Yep. (apply 'cl-mapcar 'list '((1 2)(3 4))) ;; ((1 3) (2 4)) HZ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: The different results obtained by apply function. 2021-10-07 7:57 ` Hongyi Zhao @ 2021-10-07 8:11 ` Emanuel Berg via Users list for the GNU Emacs text editor 2021-10-07 8:25 ` Emanuel Berg via Users list for the GNU Emacs text editor 0 siblings, 1 reply; 5+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-07 8:11 UTC (permalink / raw) To: help-gnu-emacs Hongyi Zhao wrote: > Yep. > > (apply 'cl-mapcar 'list '((1 2)(3 4))) ;; ((1 3) (2 4)) You can get this effect without `apply' with `cl-mapcar', and the usual `mapcar' behavior without cl-mapcar: (cl-mapcar #'list '(1 2) '(3 4)) ; ( (1 3) (2 4)) (cl-mapcar #'list (list '(1 2) '(3 4))) ; (((1 2)) ((3 4))) (mapcar #'list (list '(1 2) '(3 4))) ; (((1 2)) ((3 4))) -- underground experts united https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: The different results obtained by apply function. 2021-10-07 8:11 ` Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-07 8:25 ` Emanuel Berg via Users list for the GNU Emacs text editor 0 siblings, 0 replies; 5+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-07 8:25 UTC (permalink / raw) To: help-gnu-emacs > You can get this effect without `apply' with `cl-mapcar', > and the usual `mapcar' behavior without cl-mapcar: > > (cl-mapcar #'list '(1 2) '(3 4)) ; ( (1 3) (2 4)) > (cl-mapcar #'list (list '(1 2) '(3 4))) ; (((1 2)) ((3 4))) > (mapcar #'list (list '(1 2) '(3 4))) ; (((1 2)) ((3 4))) While it is easy to say `cl-mapcar' is much cooler with the aggregate function over multiple sets ... but observe (cl-mapcar #'list '(1 2) '(3 4)) ; ((1 3) (2 4)) (cl-mapcar #'list '(1 2) '(3 4 5)) ; ((1 3) (2 4)) so same outdata for different indata - non-injective! -- underground experts united https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-10-07 8:25 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-10-07 2:46 The different results obtained by apply function Hongyi Zhao 2021-10-07 5:41 ` Michael Heerdegen 2021-10-07 7:57 ` Hongyi Zhao 2021-10-07 8:11 ` Emanuel Berg via Users list for the GNU Emacs text editor 2021-10-07 8:25 ` Emanuel Berg via Users list for the GNU Emacs text editor
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).