unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Elisp - quoting or not?
@ 2020-12-05  5:15 David Masterson
  2020-12-05  6:12 ` An Liu
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: David Masterson @ 2020-12-05  5:15 UTC (permalink / raw)
  To: help-gnu-emacs

I give up -- what's the proper way of doing this?

(setq ab '("a" . "b")
      cd '("c" . "d")
      abcd '(ab cd))

What I want is a result for abcd to be '(("a" . "b") ("c" . "d")). I
imagine I need to use cons/car/cdr, but I'm not sure how.

-- 
David Masterson



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Elisp - quoting or not?
  2020-12-05  5:15 Elisp - quoting or not? David Masterson
@ 2020-12-05  6:12 ` An Liu
  2020-12-05  6:12   ` An Liu
  2020-12-05  6:14 ` Alexis Roda
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: An Liu @ 2020-12-05  6:12 UTC (permalink / raw)
  To: David Masterson; +Cc: help-gnu-emacs

Hi,
is it what you want?

(setq ab '("a". "b")
         cd '("c". "d")
          abcd `(ab cd))


On Sat, Dec 5, 2020 at 6:16 AM David Masterson <dsmasterson92630@outlook.com>
wrote:

> I give up -- what's the proper way of doing this?
>
> (setq ab '("a" . "b")
>       cd '("c" . "d")
>       abcd '(ab cd))
>
> What I want is a result for abcd to be '(("a" . "b") ("c" . "d")). I
> imagine I need to use cons/car/cdr, but I'm not sure how.
>
> --
> David Masterson
>
>

-- 
Liu An


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Elisp - quoting or not?
  2020-12-05  6:12 ` An Liu
@ 2020-12-05  6:12   ` An Liu
  2020-12-05  8:57     ` tomas
  0 siblings, 1 reply; 9+ messages in thread
From: An Liu @ 2020-12-05  6:12 UTC (permalink / raw)
  To: David Masterson; +Cc: help-gnu-emacs

sorry, typo

abcd `(ab cd)  should be

abcd `(,ab ,cd)


On Sat, Dec 5, 2020 at 7:12 AM An Liu <sourceonly@gmail.com> wrote:

> Hi,
> is it what you want?
>
> (setq ab '("a". "b")
>          cd '("c". "d")
>           abcd `(ab cd))
>
>
> On Sat, Dec 5, 2020 at 6:16 AM David Masterson <
> dsmasterson92630@outlook.com> wrote:
>
>> I give up -- what's the proper way of doing this?
>>
>> (setq ab '("a" . "b")
>>       cd '("c" . "d")
>>       abcd '(ab cd))
>>
>> What I want is a result for abcd to be '(("a" . "b") ("c" . "d")). I
>> imagine I need to use cons/car/cdr, but I'm not sure how.
>>
>> --
>> David Masterson
>>
>>
>
> --
> Liu An
>


-- 
Liu An


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Elisp - quoting or not?
  2020-12-05  5:15 Elisp - quoting or not? David Masterson
  2020-12-05  6:12 ` An Liu
@ 2020-12-05  6:14 ` Alexis Roda
  2020-12-06  2:11   ` David Masterson
  2020-12-05  6:21 ` Teemu Likonen
  2020-12-05  6:42 ` Arthur Miller
  3 siblings, 1 reply; 9+ messages in thread
From: Alexis Roda @ 2020-12-05  6:14 UTC (permalink / raw)
  To: David Masterson; +Cc: help-gnu-emacs

(setq ab '("a" . "b")
      cd '("c" . "d")
      abcd (list ab cd))


Missatge de David Masterson <dsmasterson92630@outlook.com> del dia ds., 5
de des. 2020 a les 6:15:

> I give up -- what's the proper way of doing this?
>
> (setq ab '("a" . "b")
>       cd '("c" . "d")
>       abcd '(ab cd))
>
> What I want is a result for abcd to be '(("a" . "b") ("c" . "d")). I
> imagine I need to use cons/car/cdr, but I'm not sure how.
>
> --
> David Masterson
>
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Elisp - quoting or not?
  2020-12-05  5:15 Elisp - quoting or not? David Masterson
  2020-12-05  6:12 ` An Liu
  2020-12-05  6:14 ` Alexis Roda
@ 2020-12-05  6:21 ` Teemu Likonen
  2020-12-05  6:42 ` Arthur Miller
  3 siblings, 0 replies; 9+ messages in thread
From: Teemu Likonen @ 2020-12-05  6:21 UTC (permalink / raw)
  To: David Masterson, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 702 bytes --]

* 2020-12-04 21:15:00-08, David Masterson wrote:

> I give up -- what's the proper way of doing this?
>
> (setq ab '("a" . "b")
>       cd '("c" . "d")
>       abcd '(ab cd))
>
> What I want is a result for abcd to be '(("a" . "b") ("c" . "d")). I
> imagine I need to use cons/car/cdr, but I'm not sure how.

I would not use quotes there:

    (setq ab (cons "a" "b")
          cd (cons "c" "d")
          abcd (list ab cd))

You can use "'", "`" and "," reader "macros" if you want:

    (setq ab '("a" . "b")
          cd '("c" . "d")
          abcd `(,ab ,cd))

-- 
/// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
// OpenPGP: 4E1055DC84E9DFF613D78557719D69D324539450

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Elisp - quoting or not?
  2020-12-05  5:15 Elisp - quoting or not? David Masterson
                   ` (2 preceding siblings ...)
  2020-12-05  6:21 ` Teemu Likonen
@ 2020-12-05  6:42 ` Arthur Miller
  3 siblings, 0 replies; 9+ messages in thread
From: Arthur Miller @ 2020-12-05  6:42 UTC (permalink / raw)
  To: David Masterson; +Cc: help-gnu-emacs

David Masterson <dsmasterson92630@outlook.com> writes:

> I give up -- what's the proper way of doing this?
>
> (setq ab '("a" . "b")
>       cd '("c" . "d")
>       abcd '(ab cd))
>
> What I want is a result for abcd to be '(("a" . "b") ("c" . "d")). I
> imagine I need to use cons/car/cdr, but I'm not sure how.

I am not sure if you really wish that quite before the conses or not;

If you really wish to have quote try this:


(setq ab '("a" . "b")
      cd '("c" . "d")
      abcd  `'(,ab ,cd))

If not, try this:

(setq ab '("a" . "b")
      cd '("c" . "d")
      abcd `(,ab ,cd))

Helps?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Elisp - quoting or not?
  2020-12-05  6:12   ` An Liu
@ 2020-12-05  8:57     ` tomas
  2020-12-05 12:31       ` Pankaj Jangid
  0 siblings, 1 reply; 9+ messages in thread
From: tomas @ 2020-12-05  8:57 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 380 bytes --]

On Sat, Dec 05, 2020 at 07:12:59AM +0100, An Liu wrote:
> sorry, typo
> 
> abcd `(ab cd)  should be
> 
> abcd `(,ab ,cd)

Or just

  abcd (list ab cd)

(I'd slightly prefer this one, since your -- totally correct --
`(,ab ,cd) variant suggests that there's some quoting going on,
which could be a bit misleading. But that's just a matter of
taste).

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Elisp - quoting or not?
  2020-12-05  8:57     ` tomas
@ 2020-12-05 12:31       ` Pankaj Jangid
  0 siblings, 0 replies; 9+ messages in thread
From: Pankaj Jangid @ 2020-12-05 12:31 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs

<tomas@tuxteam.de> writes:

> On Sat, Dec 05, 2020 at 07:12:59AM +0100, An Liu wrote:
>> sorry, typo
>> 
>> abcd `(ab cd)  should be
>> 
>> abcd `(,ab ,cd)
>
> Or just
>
>   abcd (list ab cd)
>
> (I'd slightly prefer this one, since your -- totally correct --
> `(,ab ,cd) variant suggests that there's some quoting going on,
> which could be a bit misleading. But that's just a matter of
> taste).

I too prefer the (list ab cd) approach. backquote and comma means there
is quoting but with exceptions. In this case first two are cons cells
and last one is a list. But true, it /is/ a matter of taste.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Elisp - quoting or not?
  2020-12-05  6:14 ` Alexis Roda
@ 2020-12-06  2:11   ` David Masterson
  0 siblings, 0 replies; 9+ messages in thread
From: David Masterson @ 2020-12-06  2:11 UTC (permalink / raw)
  To: Alexis Roda; +Cc: help-gnu-emacs

Alexis Roda <alexis.roda.villalonga@gmail.com> writes:

> (setq ab '("a" . "b")
>       cd '("c" . "d")
>       abcd (list ab cd))

To all who suggest this, I like it -- much simpler than I thought!

Thanks
-- 
David Masterson



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-06  2:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-05  5:15 Elisp - quoting or not? David Masterson
2020-12-05  6:12 ` An Liu
2020-12-05  6:12   ` An Liu
2020-12-05  8:57     ` tomas
2020-12-05 12:31       ` Pankaj Jangid
2020-12-05  6:14 ` Alexis Roda
2020-12-06  2:11   ` David Masterson
2020-12-05  6:21 ` Teemu Likonen
2020-12-05  6:42 ` Arthur Miller

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).