View Full Version : Please explain how LISP function "cond" works
ccowgill
2006-11-16, 01:44 PM
in the cond function, If something meets condition 1 and condition 2, does it fall under condition 1 then skip to the end of the cond function?
Avatart
2006-11-16, 02:37 PM
in the cond function, If something meets condition 1 and condition 2, does it fall under condition 1 then skip to the end of the cond function?As far as I know, it will return on the first instance of the condition being true and not read any further possibilities.
rkmcswain
2006-11-16, 03:29 PM
in the cond function, If something meets condition 1 and condition 2, does it fall under condition 1 then skip to the end of the cond function?
Have you checked out the (cond) function in HELP (acad_dev.chm)?
The first "test" in the list that is non-nil will cause it's expressions to be evaluated, and the results are returned. No further evaluation of any more "test" will be done.
Example:
(cond
( (not (setq fn (findfile "sample.txt")))
(princ "\nCannot find sample.txt"))
( (not (setq fh (open fn "r")))
(princ "\nCannot open sample.txt."))
(T (do_your_function_here))
)
If sample.txt cannot be found, the (cond) returns the first (princ) statement and then ends.
If sample.txt is found, but cannot be opened, then the second (princ) statement is returned and the (cond) ends.
If both of the first two tests are nil (meaning that the file exists and it is opened successfully), then the last test (T) will always evaluate as "true" and the following expression will be executed.
Carl_hd_Collins (http://forums.augi.com/member.php?u=70923) was close, except that a statement doesn't have to be TRUE to execute, only non-nil.
ccowgill
2006-11-16, 03:31 PM
That's all I needed to know, thanks.
Avatart
2006-11-16, 03:51 PM
Carl_hd_Collins (http://forums.augi.com/member.php?u=70923) was close, except that a statement doesn't have to be TRUE to execute, only non-nil.Sorry, that was what I meant, my Lispese failed me!
rkmcswain
2006-11-16, 08:49 PM
Sorry, that was what I meant
I figured so, but just wanted to clear it up :beer:
CAB2k
2006-11-17, 11:53 PM
[ Moderator Action = ON ] Cab, I have merged your informative post into the Anatomy of an AUTOLISP file thread. You can find the location of your post here.
Thank you for your contribution.
Richard
Forum Moderator[ Moderator Action = OFF ]
rkmcswain
2006-11-18, 01:58 AM
This is sure to be More than you ask for. :)
Excellent information. Thanks.
kennet.sjoberg
2006-11-18, 05:28 PM
This is sure to be More than you ask for. :) . . .
No it can’t be too much
Hey CAB2k why not bring this great story and a :beer: to the bar desk in "Anatomy of an AUTOLISP file"
Welcome in . . .
: ) Happy Computing !
kennet
No it can’t be too much
Hey CAB2k why not bring this great story and a :beer: to the bar desk in "Anatomy of an AUTOLISP file"
Welcome in . . .
: ) Happy Computing !
kennet
kennet, I'll see what I can do to get it moved. No need to double post.
kennet, I'll see what I can do to get it moved. No need to double post.
Done. See Cab's edited post.
CAB2k
2006-11-18, 09:31 PM
Thanks fellas.
I also added to it.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.