Create a list from a list

A

anddrd

Guest
Hi,

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,
Andreas
 
(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 ;)

Stéphane
 
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
underscore
on the variable name. There is a SKILL lint rule you can set that
tells
it not to complain about unused variables which start with an
underscore.
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).
or
(foreach mapcar _x headingListInput (sprintf nil inputAlign))

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

(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
enought
to know you are still not using the variable.

(defun foo (arg @key bar)
(or 'sklint bar)
....)

On Mar 16, 11:15 am, "anddrd" <and...@gmail.com> wrote:
Hi,

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,
Andreas
 
Hi,

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,
Andreas

On Mar 18, 12:46 am, "cadence" <j...@rdrop.com> wrote:
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
underscore
on the variable name. There is a SKILL lint rule you can set that
tells
it not to complain about unused variables which start with an
underscore.
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).
or
(foreach mapcar _x headingListInput (sprintf nil inputAlign))

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

(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
enought
to know you are still not using the variable.

(defun foo (arg @key bar)
(or 'sklint bar)
....)

On Mar 16, 11:15 am, "anddrd" <and...@gmail.com> wrote:

Hi,

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,
Andreas
 
On 16 Mar 2007 03:15:40 -0700, "anddrd" <anddrd@gmail.com> wrote:

Hi,

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,
Andreas
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.
--
Andrew Beckett
Principal European Technology Leader
Cadence Design Systems, UK.
 
On Mar 20, 7:21 pm, Andrew Beckett <andr...@DcEaLdEeTnEcTe.HcIoSm>
wrote:
On 16 Mar 2007 03:15:40 -0700, "anddrd" <and...@gmail.com> wrote:





Hi,

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,
Andreas

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.
--
Andrew Beckett
Principal European Technology Leader
Cadence Design Systems, UK.- Hide quoted text -

- Show quoted text -
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
sometimes
olny passing strings as in this case.

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

Thank you,
Andreas




Best Regards,
Andreas
 

Welcome to EDABoard.com

Sponsor

Back
Top