Author Topic: Whats difference between ...?  (Read 5774 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10414
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Whats difference between ...?
« Reply #16 on: July 08, 2010, 10:29:31 AM »
How is "a" getting it data. 

Code: [Select]
  (setq ANG1 (angle UP1 UP2))
  (setq ANG2 (angle UP2 UP3))

 I use sub functions but more to grope my code in chunks.  Really not needed but it makes sense to me.


"a" is gotten from you or the program itself.  Take your example

Code: [Select]
(setq a (angle UP1 UP2));; This sets "a"
 (setq d (RTD a));; This calls RTD and sends "a" as an argument. It converts "a" and sets "d" to the conversion.


Code: [Select]
(defun RTD (Rads /)
 (* 180.0 (/ Rads pi))
)

ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016

hermanm

  • Bull Frog
  • Posts: 282
Re: Whats difference between ...?
« Reply #17 on: July 08, 2010, 10:41:48 AM »
1 and 2 are the same

3 you are localizing 2 variables  var1 and var2

4 you are passing and argument  var1  (it really should read arg1)  and localizing a variable var2
-essentially you are giving the routine some information to work with

HTH

Tim, you probably already know this , but for anyone who does not,

The arguments (sometimes called parameters in the function definition) also become local variables (local symbols) to the function.

So, you can do this:
(contrived ridiculous example)

Code: [Select]
Command: (defun foo ( a / ) (setq a (+ 5 a)) (princ (itoa a)))
FOO

Command: (foo 12)
17"17"

Meaning, if you need to process an argument in some way, then do multiple things with the modified value, you need not define a local symbol to hold the modified value, because the argument is itself a local symbol.
If you don't know where you are going, you might not get there.
  - L.P. Berra

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Whats difference between ...?
« Reply #18 on: July 08, 2010, 11:03:56 AM »
I think the example was a good one.  :-)

I would have gone with a bit less: 

Code: [Select]
Command: (defun foo ( a / ) (setq a (+ 5 a)))
FOO

Command: (foo 12)
17

I didn't see the need to convert the value.   :-P (just having a slow day, don't mind me)
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Whats difference between ...?
« Reply #19 on: July 08, 2010, 11:38:14 AM »
A more concrete example would be taking a folder path as a string.  If the function is expecting a trailing "\\" at the end, the argument can be checked and modified if necessary without having to track a separate variable.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}