TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Sam on September 16, 2010, 01:03:34 AM
-
Dear all
explain me how is work
(cond, While & its)
-
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!
-
Subtitle: Hard to help a man who won't help himself?
-
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
-
The Its has me intrigued.
I'm guessing a case of IF typed with fat fingers :evil:
-
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:
(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:
(while ([color=red]This_Test_is_True[/color])
([color=blue]Do_This[/color]))
I hope that helps!
[/edit]
-
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.
-
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.
-
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
(if [color=blue](this_is_true)[/color]
[color=red](do_this)[/color]
)
IF/THEN/ELSE
(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
(if [color=blue](this_is_true)[/color]
[color=red] (progn
(do_this)
(and_this)
...
(and_this)
)[/color]
)
IF/THEN/ELSE
(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
(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.
(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:
(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.
(while [color=blue](this_is_true)[/color]
[color=red] (do_this)
(and_this)
...
(and_this)[/color]
)
That's all for now!
Lee
-
cond is similar to the switch statement in C++ except for its spelling and implementation
-
So,
it's the same but different :-P
-
nice explanation Lee :-)
-
dear all
renderman,se7en, kerry & special thx for lee mac
thx for help & u r valuable time
-
nice explanation Lee :-)
Thanks Ron :-)
-
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++ ... :|
-
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
-
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
-
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
-
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: