# Arguments

## Recommended Posts

Hello to all,

Attached below are three formulas to solve for distance for ellipsodial heads of different types.

My question is can each formula be written in one argument or does it need to be written in several?

I am not completely sure how to break this down. Any help on this would be greatly appreciated.

The Buzzard

##### Share on other sites

Sorry,

I think I explained myself incorrectly.

What I meant was can each formula be written in one statement with the given arguments.

##### Share on other sites
Sorry,

I think I explained myself incorrectly.

What I meant was can each formula be written in one statement with the given arguments.

Not sure about but have you tried use the COND statement?

~'J'~

##### Share on other sites

I probably overlooked something, but this should be a good example (your first function)...

```(defun foo (L r O D tt / _sq)
(setq _sq (lambda (#) (* # #)))

(- L (sqrt (- (_sq (- L r)) (_sq (/ (* O D) (apply '- (list 2 tt r)))))))
) ;_ defun
```

##### Share on other sites

Sorry again,

Fixo,

I do not mean to combine all three or a way to pick a formula.

For each formula above can the supplied arguments be put into one continuous statement for each formula.

##### Share on other sites

Thanks Alan,

I think I can figure the rest from here.

But what is apply in the statement for.

##### Share on other sites
Thanks Alan,

I think I can figure the rest from here.

But what is apply in the statement for.

It was to subtract the 3 numbers, but I completely forgot you can add more than 2 numbers to the (- function.

```(defun foo (L r O D tt / _sq)
(setq _sq (lambda (#) (* # #)))

(- L (sqrt (- (_sq (- L r)) (_sq (/ (* O D) (- 2 tt r))))))
) ;_ defun```

##### Share on other sites

You don't have to use the _sq sub function. However, it saves you a lot of typing and condenses your routine quite a bit.

`(setq _sq (lambda (#) (* # #)))`

##### Share on other sites

Alan,

I looked up apply Function,

Passes a list of arguments to, and executes, a specified function.

Thanks

##### Share on other sites
Alan,

I looked up apply Function,

Passes a list of arguments to, and executes, a specified function.

Thanks

Hope it helps.

And good luck keeping your head on straight while typing everything out.

##### Share on other sites

Nice one Alan

This is the only improvement I can see:

```(defun foo (L r O D tt / _sq n)
(setq _sq (lambda (#) (* # #)))

(cond (  (minusp (setq n (- (_sq (- L r)) (_sq (/ (* O D) (- 2 tt r)))))) nil)

(  (- L (sqrt n)))))
```

##### Share on other sites

I know,

Its like putting 30lbs of s%#t in a 5lb bag.

##### Share on other sites

Now you tripped me up Lee,

Whats with the condition?

##### Share on other sites
Now you tripped me up Lee,

Whats with the condition?

Square roots of negative numbers don't exist in the Reals

##### Share on other sites
Square roots of negative numbers don't exist in the Reals

But in that case, could'nt you just use abs in there someplace.

##### Share on other sites
Nice one Alan

This is the only improvement I can see:

```(defun foo (L r O D tt / _sq n)
(setq _sq (lambda (#) (* # #)))

(cond (  (minusp (setq n (- (_sq (- L r)) (_sq (/ (* O D) (- 2 tt r)))))) nil)

(  (- L (sqrt n)))))
```

HaHa

I guess we can't have i. Good catch.

##### Share on other sites
But in that case, could'nt you just use abs in there someplace.

But then you are changing the formula... :wink:

##### Share on other sites
But then you are changing the formula... :wink:

Ahh good point.

##### Share on other sites

One minor change to #2:

```(defun foo (L r O D tt / _sq n)
(setq _sq (lambda (#) (* # #)))

(cond (  (minusp (setq n (- (_sq (- L r)) (_sq (/ (* O D) (- 2. tt r)))))) nil)

(  (- L (sqrt n)))))```

##### Share on other sites
One minor change to #2:

Excellent spot - that would have you looking for days for that bug...