TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Sam on September 16, 2010, 01:03:34 AM

Title: explain me how is work (cond, While & its)
Post by: Sam on September 16, 2010, 01:03:34 AM
Dear all

explain me how is work
(cond, While & its)
Title: Re: explain me how is work (cond, While & its)
Post by: BlackBox on September 17, 2010, 01:56:16 PM
explain me how is work
(cond, While & its)

Please read the Developer Documentation for information on the cond and while functions.

To view this documentation, open the VLIDE (by typing VLIDE at the command line + Enter), and hit F1.

Hope this helps!
Title: Re: explain me how is work (cond, While & its)
Post by: MP on September 17, 2010, 02:30:12 PM
Subtitle: Hard to help a man who won't help himself?
Title: Re: explain me how is work (cond, While & its)
Post by: Kerry on September 17, 2010, 02:40:34 PM

The Its has me intrigued.

The rest I found here on my system ... ( yours may differ)
C:\Program Files\Autodesk\ACADM 2011\Help\acad_dev181.chm
Title: Re: explain me how is work (cond, While & its)
Post by: Lee Mac on September 17, 2010, 03:01:48 PM
The Its has me intrigued.

I'm guessing a case of IF typed with fat fingers  :evil:
Title: Re: explain me how is work (cond, While & its)
Post by: BlackBox on September 17, 2010, 04:38:33 PM
Subtitle: Hard to help a man who won't help himself?

I hope I wasn't 'mean'...? :-o  If so, that was not my intention.

I simply felt it prudent that the OP read for themselves, before broaching a conversation on the matter(s).

[edit]
To offer a couple of carrots...

The cond function is a conditional function (hence the name), which permits the testing for one of several list cases. When the test expression of a list is true, a subsequent expression is evaluated for that condition only. Out of many possible list cases, only one condition is evaluated.

If that jibberish didn't make any sense, maybe this will:

Code: [Select]
(cond
  (([color=red]If_Test_1_is_True[/color]) ([color=blue]Do_This_1[/color]))
  ((If_Test_2_is_True) (Do_This_2))
  ((If_Test_3_is_True) (Do_This_3))
  ((If_Test_4_is_True) (Do_This_4)))

The while function provides a potential loop, given a test expression. 'While' the test expression is true, a subsequent expression is evaluated.

For example:
Code: [Select]
(while ([color=red]This_Test_is_True[/color])
 ([color=blue]Do_This[/color]))

I hope that helps!
[/edit]
Title: Re: explain me how is work (cond, While & its)
Post by: JohnK on September 17, 2010, 04:46:53 PM
Subtitle: Hard to help a man who won't help himself?
<snip>

I simply felt it prudent that the OP read for themselves, before broaching a conversation on the matter(s).

MP felt the same way as you RenderMan.
Title: Re: explain me how is work (cond, While & its)
Post by: BlackBox on September 17, 2010, 05:01:28 PM
MP felt the same way as you RenderMan.

Thanks for the clarification, Se7en... I'm new to TheSwamp, and I'm not trying to 'make waves' (pun intended).

You know, a man wiser than I once shared with me the secrets for 'How To Ask Questions The Smart Way'... I felt that my initial reply was a fitting response, given the question.
Title: Re: explain me how is work (cond, While & its)
Post by: Lee Mac on September 17, 2010, 08:04:16 PM
Had a spare minute, so here is a quick outline:

IF

IF evaluates a test expression (shown in blue), and, if it returns anything non-nil, will proceed to evaluate a 'then' expression (shown in red). Should the test expression return nil, IF will evaluate the 'else' expression (shown in green) should this be supplied.

IF/THEN
Code: [Select]
(if [color=blue](this_is_true)[/color]
  [color=red](do_this)[/color]
)

IF/THEN/ELSE
Code: [Select]
(if [color=blue](this_is_true)[/color]
  [color=red](do_this)[/color]
  [color=green](else_do_this)[/color]
)

The IF function can only take three arguments: the test expression, an expression to evaluate if the test expression returns non-nil, and an optional expression to evaluate if the test expression returns nil.

Hence, if we wish to evaluate mutiple expressions within the IF function, we can wrap these functions within a function such as progn which can be then supplied to IF as a single expression:

IF/THEN
Code: [Select]
(if [color=blue](this_is_true)[/color]
[color=red]  (progn
    (do_this)
    (and_this)
    ...
    (and_this)
  )[/color]
)

IF/THEN/ELSE
Code: [Select]
(if [color=blue](this_is_true)[/color]
[color=red]  (progn
    (do_this)
    (and_this)
    ...
    (and_this)
  )[/color]
[color=green]  (else_do_this)[/color]
)

IF/THEN/ELSE
Code: [Select]
(if [color=blue](this_is_true)[/color]
[color=red]  (progn
    (do_this)
    (and_this)
    ...
    (and_this)
  )[/color]
[color=green]  (progn
    (else_do_this)
    (and_this)
    ...
    (and_this)
  )[/color]
)

COND

COND will evaluate a test expression (first item in a list of expressions) for each condition (list of expressions) supplied and evaluate the expressions following the test expression should it return non-nil. COND will stop evaluating test expressions when a condition is met.

Code: [Select]
(cond
  (
    [color=blue](if_this_is_true)[/color]
    
[color=red]    (do_this)
    (and_this)
    ...
    (and_this)[/color]
  )
  (
    [color=blue](else_if_this_is_true)[/color]

[color=red]    (do_this)
    (and_this)
    ...
    (and_this)[/color]
  )
  (
    [color=blue](else_if_this_is_true)[/color]

[color=red]    (do_this)
    (and_this)
    ...
    (and_this)[/color]
  )
  ...
)

This functionality could also be achieved using a tree of nested IF statements, however this is much less elegant and harder to follow:

Code: [Select]
(if [color=blue](this_is_true)[/color]
[color=red]  (progn[/color]
[color=red]    (do_this)
    (and_this)
    ...
    (and_this)[/color]
  )
  (if [color=blue](else_if_this_is_true)[/color]
[color=red]    (progn[/color]
[color=red]      (do_this)
      (and_this)
      ...
      (and_this)[/color]
    )
    (if [color=blue](else_if_this_is_true)[/color]
[color=red]      (progn[/color]
  [color=red]      (do_this)
        (and_this)
        ...
        (and_this)[/color]
      )
      ...
    )
  )
)

WHILE

WHILE will evaluate a test expression, and, if it returns a non-nil value, will evaluate a set of expressions; this is repeated until the test expression returns nil.

Code: [Select]
(while [color=blue](this_is_true)[/color]
[color=red]  (do_this)
  (and_this)
  ...
  (and_this)[/color]
)

That's all for now!

Lee
Title: Re: explain me how is work (cond, While & its)
Post by: It's Alive! on September 17, 2010, 11:47:56 PM
cond is similar to the switch statement in C++ except for its spelling and implementation
Title: Re: explain me how is work (cond, While & its)
Post by: Kerry on September 17, 2010, 11:51:12 PM

So,
it's the same but different  :-P
Title: Re: explain me how is work (cond, While & its)
Post by: ronjonp on September 17, 2010, 11:57:05 PM
nice explanation Lee  :-)
Title: Re: explain me how is work (cond, While & its)
Post by: Sam on September 18, 2010, 01:41:44 AM
dear all
renderman,se7en, kerry & special thx for lee mac
thx for help & u r valuable time
Title: Re: explain me how is work (cond, While & its)
Post by: Lee Mac on September 18, 2010, 07:32:27 AM
nice explanation Lee  :-)

Thanks Ron  :-)
Title: Re: explain me how is work (cond, While & its)
Post by: Lee Mac on September 18, 2010, 01:41:58 PM
cond is similar to the switch statement in C++ except for its spelling and implementation

Is it right that the switch statement can only handle integers as the test expressions though? I found that really annoying when learning C++ ...  :|
Title: Re: explain me how is work (cond, While & its)
Post by: pkohut on September 18, 2010, 02:51:25 PM
cond is similar to the switch statement in C++ except for its spelling and implementation

Is it right that the switch statement can only handle integers as the test expressions though? I found that really annoying when learning C++ ...  :|

Being a low level language it doesn't give you the kitchen sink. It doesn't even give you a kitchen.  :-D
Title: Re: explain me how is work (cond, While & its)
Post by: Lee Mac on September 18, 2010, 06:25:22 PM
cond is similar to the switch statement in C++ except for its spelling and implementation

Is it right that the switch statement can only handle integers as the test expressions though? I found that really annoying when learning C++ ...  :|

Being a low level language it doesn't give you the kitchen sink. It doesn't even give you a kitchen.  :-D

 :-D
Title: Re: explain me how is work (cond, While & its)
Post by: stevej on September 18, 2010, 10:30:38 PM
Here's an excellent post from another forum I happened upon some time ago that explains it well.
It's a coupla years ago, but well worth the read.
http://www.cadtutor.net/forum/showthread.php?27101&p=173196&viewfull=1#post173196

SteveJ
Title: Re: explain me how is work (cond, While & its)
Post by: Lee Mac on September 19, 2010, 08:49:39 AM
Here's an excellent post from another forum I happened upon some time ago that explains it well.
It's a coupla years ago, but well worth the read.
http://www.cadtutor.net/forum/showthread.php?27101&p=173196&viewfull=1#post173196

SteveJ

Wow - thats from back when I started LISP  :lol: