Author Topic: explain me how is work (cond, While & its)  (Read 7730 times)

0 Members and 1 Guest are viewing this topic.

Sam

  • Bull Frog
  • Posts: 201
explain me how is work (cond, While & its)
« on: September 16, 2010, 01:03:34 AM »
Dear all

explain me how is work
(cond, While & its)
« Last Edit: September 16, 2010, 01:17:37 AM by Sam »
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

BlackBox

  • King Gator
  • Posts: 3770
Re: explain me how is work (cond, While & its)
« Reply #1 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!
"How we think determines what we do, and what we do determines what we get."

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: explain me how is work (cond, While & its)
« Reply #2 on: September 17, 2010, 02:30:12 PM »
Subtitle: Hard to help a man who won't help himself?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: explain me how is work (cond, While & its)
« Reply #3 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
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: explain me how is work (cond, While & its)
« Reply #4 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:

BlackBox

  • King Gator
  • Posts: 3770
Re: explain me how is work (cond, While & its)
« Reply #5 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]
« Last Edit: September 17, 2010, 04:55:39 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: explain me how is work (cond, While & its)
« Reply #6 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.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

BlackBox

  • King Gator
  • Posts: 3770
Re: explain me how is work (cond, While & its)
« Reply #7 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.
"How we think determines what we do, and what we do determines what we get."

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: explain me how is work (cond, While & its)
« Reply #8 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

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8728
  • AKA Daniel
Re: explain me how is work (cond, While & its)
« Reply #9 on: September 17, 2010, 11:47:56 PM »
cond is similar to the switch statement in C++ except for its spelling and implementation

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: explain me how is work (cond, While & its)
« Reply #10 on: September 17, 2010, 11:51:12 PM »

So,
it's the same but different  :-P
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: explain me how is work (cond, While & its)
« Reply #11 on: September 17, 2010, 11:57:05 PM »
nice explanation Lee  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Sam

  • Bull Frog
  • Posts: 201
Re: explain me how is work (cond, While & its)
« Reply #12 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
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: explain me how is work (cond, While & its)
« Reply #13 on: September 18, 2010, 07:32:27 AM »
nice explanation Lee  :-)

Thanks Ron  :-)

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: explain me how is work (cond, While & its)
« Reply #14 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++ ...  :|