How to write a list literal with conditional items? [duplicate]












2
















This question already has an answer here:




  • How to evaluate the variables before adding them to a list?

    2 answers




Given a list literal '(1 2 3)



is it possible to conditionally include parts of the list?



eg:



'(1 2 3
(when thing-is-true '(10 11 12)))
4 5 6)


Which would result in



'(1 2 3 4 5 6) or '(1 2 3 10 11 12 4 5 6) dependent on thing-is-true.





Python for example supports:



[1, 2, 3, *([10, 11, 12] if thing_is_true else ), 4, 5, 6]




What is the most straightforward way to achieve this using a single expression, without defining a list variable and manipulating it?










share|improve this question















marked as duplicate by npostavs, DoMiNeLa10 11 hours ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Don't think this is a duplicate because I'm not asking about adding items to a list. Rather, how to declare a list. Also notice the answer to this question is quite different.

    – ideasman42
    16 hours ago











  • Hmm, I guess there is minor difference in that the dup's answer doesn't mention ,@, only ,; but to my mind the answer in both cases is essentially: "you're looking for backquote".

    – npostavs
    10 hours ago











  • I was aware of the feature (that it could be useful in this case), I just didn't know how to use it because I'm not that experienced in elisp.

    – ideasman42
    9 hours ago






  • 1





    I'm not aware of what you're aware of, I just talk about what's written in the question and vote accordingly.

    – npostavs
    9 hours ago











  • Seems like a dup to me, regardless of a minor difference in what you're trying to do. The question is really about a misunderstanding, and the referenced duplicate Q&A covers that. (And the tags should include quote and not include elisp, IMO.)

    – Drew
    6 hours ago
















2
















This question already has an answer here:




  • How to evaluate the variables before adding them to a list?

    2 answers




Given a list literal '(1 2 3)



is it possible to conditionally include parts of the list?



eg:



'(1 2 3
(when thing-is-true '(10 11 12)))
4 5 6)


Which would result in



'(1 2 3 4 5 6) or '(1 2 3 10 11 12 4 5 6) dependent on thing-is-true.





Python for example supports:



[1, 2, 3, *([10, 11, 12] if thing_is_true else ), 4, 5, 6]




What is the most straightforward way to achieve this using a single expression, without defining a list variable and manipulating it?










share|improve this question















marked as duplicate by npostavs, DoMiNeLa10 11 hours ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Don't think this is a duplicate because I'm not asking about adding items to a list. Rather, how to declare a list. Also notice the answer to this question is quite different.

    – ideasman42
    16 hours ago











  • Hmm, I guess there is minor difference in that the dup's answer doesn't mention ,@, only ,; but to my mind the answer in both cases is essentially: "you're looking for backquote".

    – npostavs
    10 hours ago











  • I was aware of the feature (that it could be useful in this case), I just didn't know how to use it because I'm not that experienced in elisp.

    – ideasman42
    9 hours ago






  • 1





    I'm not aware of what you're aware of, I just talk about what's written in the question and vote accordingly.

    – npostavs
    9 hours ago











  • Seems like a dup to me, regardless of a minor difference in what you're trying to do. The question is really about a misunderstanding, and the referenced duplicate Q&A covers that. (And the tags should include quote and not include elisp, IMO.)

    – Drew
    6 hours ago














2












2








2









This question already has an answer here:




  • How to evaluate the variables before adding them to a list?

    2 answers




Given a list literal '(1 2 3)



is it possible to conditionally include parts of the list?



eg:



'(1 2 3
(when thing-is-true '(10 11 12)))
4 5 6)


Which would result in



'(1 2 3 4 5 6) or '(1 2 3 10 11 12 4 5 6) dependent on thing-is-true.





Python for example supports:



[1, 2, 3, *([10, 11, 12] if thing_is_true else ), 4, 5, 6]




What is the most straightforward way to achieve this using a single expression, without defining a list variable and manipulating it?










share|improve this question

















This question already has an answer here:




  • How to evaluate the variables before adding them to a list?

    2 answers




Given a list literal '(1 2 3)



is it possible to conditionally include parts of the list?



eg:



'(1 2 3
(when thing-is-true '(10 11 12)))
4 5 6)


Which would result in



'(1 2 3 4 5 6) or '(1 2 3 10 11 12 4 5 6) dependent on thing-is-true.





Python for example supports:



[1, 2, 3, *([10, 11, 12] if thing_is_true else ), 4, 5, 6]




What is the most straightforward way to achieve this using a single expression, without defining a list variable and manipulating it?





This question already has an answer here:




  • How to evaluate the variables before adding them to a list?

    2 answers








elisp list






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 16 hours ago







ideasman42

















asked 19 hours ago









ideasman42ideasman42

1,555625




1,555625




marked as duplicate by npostavs, DoMiNeLa10 11 hours ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by npostavs, DoMiNeLa10 11 hours ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Don't think this is a duplicate because I'm not asking about adding items to a list. Rather, how to declare a list. Also notice the answer to this question is quite different.

    – ideasman42
    16 hours ago











  • Hmm, I guess there is minor difference in that the dup's answer doesn't mention ,@, only ,; but to my mind the answer in both cases is essentially: "you're looking for backquote".

    – npostavs
    10 hours ago











  • I was aware of the feature (that it could be useful in this case), I just didn't know how to use it because I'm not that experienced in elisp.

    – ideasman42
    9 hours ago






  • 1





    I'm not aware of what you're aware of, I just talk about what's written in the question and vote accordingly.

    – npostavs
    9 hours ago











  • Seems like a dup to me, regardless of a minor difference in what you're trying to do. The question is really about a misunderstanding, and the referenced duplicate Q&A covers that. (And the tags should include quote and not include elisp, IMO.)

    – Drew
    6 hours ago



















  • Don't think this is a duplicate because I'm not asking about adding items to a list. Rather, how to declare a list. Also notice the answer to this question is quite different.

    – ideasman42
    16 hours ago











  • Hmm, I guess there is minor difference in that the dup's answer doesn't mention ,@, only ,; but to my mind the answer in both cases is essentially: "you're looking for backquote".

    – npostavs
    10 hours ago











  • I was aware of the feature (that it could be useful in this case), I just didn't know how to use it because I'm not that experienced in elisp.

    – ideasman42
    9 hours ago






  • 1





    I'm not aware of what you're aware of, I just talk about what's written in the question and vote accordingly.

    – npostavs
    9 hours ago











  • Seems like a dup to me, regardless of a minor difference in what you're trying to do. The question is really about a misunderstanding, and the referenced duplicate Q&A covers that. (And the tags should include quote and not include elisp, IMO.)

    – Drew
    6 hours ago

















Don't think this is a duplicate because I'm not asking about adding items to a list. Rather, how to declare a list. Also notice the answer to this question is quite different.

– ideasman42
16 hours ago





Don't think this is a duplicate because I'm not asking about adding items to a list. Rather, how to declare a list. Also notice the answer to this question is quite different.

– ideasman42
16 hours ago













Hmm, I guess there is minor difference in that the dup's answer doesn't mention ,@, only ,; but to my mind the answer in both cases is essentially: "you're looking for backquote".

– npostavs
10 hours ago





Hmm, I guess there is minor difference in that the dup's answer doesn't mention ,@, only ,; but to my mind the answer in both cases is essentially: "you're looking for backquote".

– npostavs
10 hours ago













I was aware of the feature (that it could be useful in this case), I just didn't know how to use it because I'm not that experienced in elisp.

– ideasman42
9 hours ago





I was aware of the feature (that it could be useful in this case), I just didn't know how to use it because I'm not that experienced in elisp.

– ideasman42
9 hours ago




1




1





I'm not aware of what you're aware of, I just talk about what's written in the question and vote accordingly.

– npostavs
9 hours ago





I'm not aware of what you're aware of, I just talk about what's written in the question and vote accordingly.

– npostavs
9 hours ago













Seems like a dup to me, regardless of a minor difference in what you're trying to do. The question is really about a misunderstanding, and the referenced duplicate Q&A covers that. (And the tags should include quote and not include elisp, IMO.)

– Drew
6 hours ago





Seems like a dup to me, regardless of a minor difference in what you're trying to do. The question is really about a misunderstanding, and the referenced duplicate Q&A covers that. (And the tags should include quote and not include elisp, IMO.)

– Drew
6 hours ago










1 Answer
1






active

oldest

votes


















2














You can use the macro (elisp) Backquote, e.g.,



`(1 2 3 ,@(when nil '(10 11 12)) 4 5 6)
;; => (1 2 3 4 5 6)

`(1 2 3 ,@(when t '(10 11 12)) 4 5 6)
;; => (1 2 3 10 11 12 4 5 6)


if you expand the above macros, they are simply using append



(append '(1 2 3) (when nil '(10 11 12)) '(4 5 6))
;; => (1 2 3 4 5 6)

(append '(1 2 3) (when t '(10 11 12)) '(4 5 6))
;; => (1 2 3 10 11 12 4 5 6)





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You can use the macro (elisp) Backquote, e.g.,



    `(1 2 3 ,@(when nil '(10 11 12)) 4 5 6)
    ;; => (1 2 3 4 5 6)

    `(1 2 3 ,@(when t '(10 11 12)) 4 5 6)
    ;; => (1 2 3 10 11 12 4 5 6)


    if you expand the above macros, they are simply using append



    (append '(1 2 3) (when nil '(10 11 12)) '(4 5 6))
    ;; => (1 2 3 4 5 6)

    (append '(1 2 3) (when t '(10 11 12)) '(4 5 6))
    ;; => (1 2 3 10 11 12 4 5 6)





    share|improve this answer




























      2














      You can use the macro (elisp) Backquote, e.g.,



      `(1 2 3 ,@(when nil '(10 11 12)) 4 5 6)
      ;; => (1 2 3 4 5 6)

      `(1 2 3 ,@(when t '(10 11 12)) 4 5 6)
      ;; => (1 2 3 10 11 12 4 5 6)


      if you expand the above macros, they are simply using append



      (append '(1 2 3) (when nil '(10 11 12)) '(4 5 6))
      ;; => (1 2 3 4 5 6)

      (append '(1 2 3) (when t '(10 11 12)) '(4 5 6))
      ;; => (1 2 3 10 11 12 4 5 6)





      share|improve this answer


























        2












        2








        2







        You can use the macro (elisp) Backquote, e.g.,



        `(1 2 3 ,@(when nil '(10 11 12)) 4 5 6)
        ;; => (1 2 3 4 5 6)

        `(1 2 3 ,@(when t '(10 11 12)) 4 5 6)
        ;; => (1 2 3 10 11 12 4 5 6)


        if you expand the above macros, they are simply using append



        (append '(1 2 3) (when nil '(10 11 12)) '(4 5 6))
        ;; => (1 2 3 4 5 6)

        (append '(1 2 3) (when t '(10 11 12)) '(4 5 6))
        ;; => (1 2 3 10 11 12 4 5 6)





        share|improve this answer













        You can use the macro (elisp) Backquote, e.g.,



        `(1 2 3 ,@(when nil '(10 11 12)) 4 5 6)
        ;; => (1 2 3 4 5 6)

        `(1 2 3 ,@(when t '(10 11 12)) 4 5 6)
        ;; => (1 2 3 10 11 12 4 5 6)


        if you expand the above macros, they are simply using append



        (append '(1 2 3) (when nil '(10 11 12)) '(4 5 6))
        ;; => (1 2 3 4 5 6)

        (append '(1 2 3) (when t '(10 11 12)) '(4 5 6))
        ;; => (1 2 3 10 11 12 4 5 6)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 17 hours ago









        xuchunyangxuchunyang

        8,8791926




        8,8791926















            Popular posts from this blog

            數位音樂下載

            When can things happen in Etherscan, such as the picture below?

            格利澤436b