Create a list from a list

Discussion in 'Cadence' started by anddrd, Mar 16, 2007.

  1. anddrd

    anddrd Guest


    Started to use sklint on my skill files and it is complaining on my
    use of
    mapcar and lambda function

    I want to create a list of equal length as another list but with the
    same value
    in each element. To do this I use mapcar:

    (mapcar (lambda (x) (sprintf nil inputAlign)) headingListInput).

    Sklint complains that I am not referencing x with in the lambda
    expression, which is true.

    Could I do this in some other way with out creating variabels
    (symbols) and have a happy sklint?

    Best Regards,
    anddrd, Mar 16, 2007
  2. anddrd

    S. Badel Guest

    (mapcar (lambda (x) (sprintf nil inputAlign)) headingListInput).

    (let (result) (for i 1 (length headingListInput) setq(result (cons inputAlign result))) result)

    Note this code juste create a local variable (let) and returns the result you want.

    Note sure how efficient it is, but does the job ;)

    S. Badel, Mar 16, 2007
  3. anddrd

    cadence Guest

    Hi Andreas, i think you'll notice that skill lint has lots of these
    similar limitations. One way to handle this is by using an
    on the variable name. There is a SKILL lint rule you can set that
    it not to complain about unused variables which start with an
    it also serves a sort of a documentation, yes i really did not
    want to use this variable.
    (mapcar (lambda (_x) (sprintf nil inputAlign)) headingListInput).
    (foreach mapcar _x headingListInput (sprintf nil inputAlign))

    Another way is to actually use it but in a way that has no side

    (foreach mapcar x headingListInput
    (or 'sklint x)
    (sprintf nil inputAllign))

    Unfortunately it is sometimes impossible to choose your own variable
    names. for example some interfaces require you to provide a client
    function with certain keyword arguments which you do not want to
    use in all cases.

    (defun foo (arg @key bar)

    If you are not allowed to chose the name of nor omit the keyword
    argument you
    might have to use the (or 'sklint bar) trick. skill lint is not smart
    to know you are still not using the variable.

    (defun foo (arg @key bar)
    (or 'sklint bar)
    cadence, Mar 17, 2007
  4. anddrd

    anddrd Guest


    Thanks for the suggestions.

    I will go with the variable naming option ( _X ) as I think the syntax
    of the mapcar line
    is simpler to read.

    Should have read the sklint documentation before using it.

    Thank you both,
    anddrd, Mar 19, 2007
  5. I'm a bit late responding to this (I'd have suggested prefixing the variable
    name with _ to indicate to SKILL Lint that it's an intentionally unused
    variable), but why do you have the sprintf there at all? Surely this is
    equivalent to:

    (mapcar (lambda (x) inputAlign) headingListInput)

    Minor point, but I'm a bit of a pedant ;-)

    Andrew Beckett, Mar 20, 2007
  6. anddrd

    anddrd Guest

    Yes, that is true. The sprintf does not do anything.

    thanks for seeing this.

    For some reason that I can not understand today I have been using
    sprintf for doing string concatination in a lot of places and
    olny passing strings as in this case.

    The code will be easier to read with strcat instead of sprintf.

    Thank you,

    Best Regards,
    anddrd, Mar 21, 2007
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.