mapcar only?

Discussion in 'AutoCAD' started by BillZ, May 18, 2004.

  1. BillZ

    BillZ Guest

    R2005 Vlisp:

    I have a list of strings:
    !dir_year
    ("2005" "2004" "2003" "2002" "2001" "2000" "1999" "1998" "1997" "1996" "1995"
    "1994" "1993" "1992")

    I also have a list of string lists:
    !tmplst
    (("7218_WC-12" "7219_WC-14" "7221_SSV-14" "7235_SSV-16")("7218_WC-12" "7219_WC-14" "7221_SSV-14" "7235_SSV-16")("7218_WC-12" "7219_WC-14" "7221_SSV-14" "7235_SSV-16"))

    I want to concatenate the first item of the first list to all the strings in the first item of the second list, and so on...

    The lists are the same length although my example is truncated..

    Can I do this exclusively with mapcar or must I use a foreach to do this?

    I've searched and tried but am striking out.

    (mapcar '(lambda (x)(apply 'strcat (mapcar '(lambda (y)(strcat "G:\\"
    y "\\")) dir_year) x)) tmplst)

    TIA

    Bill
     
    BillZ, May 18, 2004
    #1
  2. If I understood you correctly ...

    Code:
    
    (setq ListOfStrings
    '(   "2005" "2004" "2003" "2002" "2001" "2000" "1999"
    "1998" "1997" "1996" "1995" "1994" "1993" "1992"
    )
    )
    
    (setq ListOfStringLists
    '(   ("7218_WC-12" "7219_WC-14" "7221_SSV-14" "7235_SSV-16")
    ("7218_WC-12" "7219_WC-14" "7221_SSV-14" "7235_SSV-16")
    ("7218_WC-12" "7219_WC-14" "7221_SSV-14" "7235_SSV-16")
    )
    )
    
    ;; I want to concatenate the first item of the first list
    ;; to all the strings in the first item of the second list,
    ;; and so on...
    
    (mapcar
    ;; underscore added merely for clarity; you may wish to remove
    '(lambda (a b) (mapcar '(lambda (x) (strcat a "_" x)) b ))
    ListOfStrings
    ListOfStringLists
    )
    
    ;; returns ...
    
    (
    (
    "2005_7218_WC-12"
    "2005_7219_WC-14"
    "2005_7221_SSV-14"
    "2005_7235_SSV-16"
    )
    (
    "2004_7218_WC-12"
    "2004_7219_WC-14"
    "2004_7221_SSV-14"
    "2004_7235_SSV-16"
    )
    (   "2003_7218_WC-12"
    "2003_7219_WC-14"
    "2003_7221_SSV-14"
    "2003_7235_SSV-16"
    )
    )
    
    
    R2005 Vlisp:

    I have a list of strings:
    !dir_year
    ("2005" "2004" "2003" "2002" "2001" "2000" "1999" "1998" "1997" "1996" "1995"
    "1994" "1993" "1992")

    I also have a list of string lists:
    !tmplst
    (("7218_WC-12" "7219_WC-14" "7221_SSV-14" "7235_SSV-16")("7218_WC-12" "7219_WC-14" "7221_SSV-14" "7235_SSV-16")("7218_WC-12"
    "7219_WC-14" "7221_SSV-14" "7235_SSV-16"))

    I want to concatenate the first item of the first list to all the strings in the first item of the second list, and so on...

    The lists are the same length although my example is truncated..

    Can I do this exclusively with mapcar or must I use a foreach to do this?

    I've searched and tried but am striking out.

    (mapcar '(lambda (x)(apply 'strcat (mapcar '(lambda (y)(strcat "G:\\"
    y "\\")) dir_year) x)) tmplst)

    TIA

    Bill
     
    michael puckett, May 18, 2004
    #2
  3. You're welcome Bill. If you learned anything from all
    your variants it is not wasted time in my opinion.

    PS: Thank you for the challenge - I've been coding a
    VB project for weeks and need to keep the lisp muscles
    toned!

    Cheers.

    Perfect!
    Thanks for the fast reply.
    I will need to add some path info but the underbar shows me how to do that.

    Spent all morning trying variations. :(

    Thanks

    Bill
     
    michael puckett, May 18, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.