Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Subtracting list from a variable

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
borderliner
453 Views, 2 Replies

Subtracting list from a variable

Hi, I've created a list and want to subtract all the values within it from another variable, and assign it to a new variable.

 

How do I do it?

 

Basically, I ask for ground level (assigned to variable G1), and then any number of depths beneath that (assign to list LVLLIST), and I want to return the value of the bottom point. So it's all the values in LVLLIST added together and subtracted from G1. And assign it to a new variable BASE.

Me thinks anyway.

 

For example,

G1 = 650.00

LVLLIST = (1.23 23.26 0.13 50.23)

 

(setq BASE (- G1 LVLLLIST))

 

Thanks

 

2 REPLIES 2
Message 2 of 3
Kent1Cooper
in reply to: borderliner


@borderliner wrote:

.... I ask for ground level (assigned to variable G1), and then any number of depths beneath that (assign to list LVLLIST), and I want to return the value of the bottom point. So it's all the values in LVLLIST added together and subtracted from G1. And assign it to a new variable BASE.

....

G1 = 650.00

LVLLIST = (1.23 23.26 0.13 50.23)

 

(setq BASE (- G1 LVLLLIST))

....


This is an application for the (apply) function:

 

(setq BASE (- G1 (apply '+ LVLLLIST)))

Kent Cooper, AIA
Message 3 of 3
borderliner
in reply to: Kent1Cooper

Spot on.

 

Thanks.

 

First ever LISP routine - and feelin' quite good about it... Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost