Andrew1979 Posted April 3, 2014 Share Posted April 3, 2014 I am having trouble with the cond function. I am trying to get a number from a text file to evaluate. If the text file says 0, an alert will say evaluation expired. If not, the program will continue. Only problem is, the function doesn't work. Any ideas? The problem is, the way the code currently is, the alert always displays no matter what number is in the text file. (defun checkcount () (setq count (atoi Evaluation)) (cond ((= count 0)(alert "Evaluation Expired" )) ((>= count 1) (getVariables-Elevation-WDE) (getInput-Elevation-WDE) (setVariables-Elevation-WDE) (Offset-Elevation-WDE) (layers) (processInput-Elevation-WDE) (DoorNumber-Elevation-WDE) )) ) Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 3, 2014 Share Posted April 3, 2014 The evaluation is correct; seems that the issue is with the value stored in Evaluation variable - should be a string ("0" or "1"): (and (eq (type Evaluation) 'STR) (member Evaluation '("0" "1"))) Please edit your post and required code tags. Quote Link to comment Share on other sites More sharing options...
hmsilva Posted April 3, 2014 Share Posted April 3, 2014 (edited) I would suggest ;;at you main code (if (and (= (type Evaluation) 'STR) (setq Evaluation (read Evaluation)) (= (type Evaluation) 'INT) );; and (checkcount Evaluation) (prompt "\nWrong Evaluation TYPE!") );; if ;; usage ;; (checkcount Evaluation) ;; Evaluation as an integer (defun checkcount (count) (cond ((= count 0) (alert "Evaluation Expired" )) ((> count 0) (getVariables-Elevation-WDE) (getInput-Elevation-WDE) (setVariables-Elevation-WDE) (Offset-Elevation-WDE) (layers) (processInput-Elevation-WDE) (DoorNumber-Elevation-WDE) ) );; cond );; defun HTH Henrique Edited April 3, 2014 by hmsilva Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 3, 2014 Share Posted April 3, 2014 Henrique, please remember that ATOI will always return an integer (even if a non-numerical string was supplied as argument), so that type validation is superfluous. Would be better to validate for nil, case when ATOI will raise an error. Quote Link to comment Share on other sites More sharing options...
hmsilva Posted April 3, 2014 Share Posted April 3, 2014 Henrique, please remember that ATOI will always return an integer (even if a non-numerical string was supplied as argument), so that type validation is superfluous.Would be better to validate for nil, case when ATOI will raise an error. Mircea, you'r correct, my bad... I did mod my previous code to READ to test for an INT. Thank you Henrique Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 3, 2014 Share Posted April 3, 2014 Please don't forget about this situation: (read nil) Quote Link to comment Share on other sites More sharing options...
hmsilva Posted April 3, 2014 Share Posted April 3, 2014 Please don't forget about this situation: (read nil) Thank you Mircea. (Post #3 corrected) Henrique Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.