Better way to define constant symbol?

Better way to define constant symbol?

mmitchellH6TRW
Enthusiast Enthusiast
1,215 Views
7 Replies
Message 1 of 8

Better way to define constant symbol?

mmitchellH6TRW
Enthusiast
Enthusiast

I looking for a better way to define a constant symbol, so that it evaluates when used.

Currently:

(setq rot pi)
.... (setq BKROT (quote (and (> rot (* pi 0.5)) (<= rot (* pi 1.5))))) ; define constant for Back Rotation .... (cond ((eval BKROT) (something happens)) ..... (cond ((not (eval BKROT)) (something happens)) ......

;; what I would like

(setmagic BKROT (quote (and (> rot (* pi 0.5)) (<= rot (* pi 1.5))))) ; define self evaluating constant
.....
 (cond ( BKROT (something happens)) .....
0 Likes
Accepted solutions (2)
1,216 Views
7 Replies
Replies (7)
Message 2 of 8

CodeDing
Advisor
Advisor

@mmitchellH6TRW ,

 

Then just perform the evaluation..?

(setq BKROT (and (> rot (* pi 0.5)) (<= rot (* pi 1.5))))
.....
(cond (BKROT (something happens)) .....

Best,

~DD

0 Likes
Message 3 of 8

ronjonp
Mentor
Mentor

Are you talking about defining a function to pass a rotation argument to?

(defun _mycheck (rot) (<= (/ pi 2) rot (* pi 1.5)))
(if (_mycheck (getangle)) (alert "YES :)")(alert "NO :("))
0 Likes
Message 4 of 8

Kent1Cooper
Consultant
Consultant

I'm trying to picture what the (quote) function is doing for you.  The (and) function that it is applied to will return either T [with the value of pi at the beginning] or nil, so BKROT is going to be set to either (quote T) or (quote nil).  I'm not at an AutoCAD to try, but I'm wondering what those do -- whether they even have any meaning....

Kent Cooper, AIA
0 Likes
Message 5 of 8

CodeDing
Advisor
Advisor
Accepted solution

@mmitchellH6TRW ,

 

I think I know what you're going for, and this is as close as I can get. You have to call it as a function though [with brackets (...) ]. I'm not sure how to run the expression if you were to just call the symbol without brackets.

Is this more-so what you're looking for?

.....
(setq rot pi)
(setq BKROT (lambda () (and (> rot (* pi 0.5)) (<= rot (* pi 1.5))))) ; define constant for Back Rotation
(cond ((BKROT) (something happens)) .....
(setq rot 0.0)
(cond ((not (BKROT)) (something ELSE happens)) .....
.....

Best,

~DD

0 Likes
Message 6 of 8

mmitchellH6TRW
Enthusiast
Enthusiast
Accepted solution
  (setq TAU (* pi 2))
  (setq BKROT (lambda () (and (> rot (* TAU 0.25)) (<= rot (* TAU 0.75))))) ; define constant for Back Rotation

is a condition to test of rot is on the back side of a circle.  So later in the code I can call the condition....

	     (cond
	       ((BKROT) (cons 50 (+ rot pi (cdr (assoc 50 x))))) ; insertion angle on back side
	       (T (cons 50 (+ rot (cdr (assoc 50 x)))))	    ; insertion angle on front side
	     )						    ; (cond

as part of my entmake . The (assoc 50 x) pulls the insert angle from the original block. i.e.  https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/trying-to-entmake-a-block-insert-wit... 

	     (cond
	       ((BKROT) (cons 72 2))		    	    ; Horz 0 = Left; 1= Center; 2 = Right
	       (T (cons 72 0))				    ; Horz 0 = Left; 1= Center; 2 = Right
	     )						    ; (cond

Eight different calls to place blocks.

Array.png

Message 7 of 8

CodeDing
Advisor
Advisor

@mmitchellH6TRW ,

 

Not to interrupt your flow or anything, but perhaps some simple 'improvements'?

(cond
  ((BKROT) (cons 50 (+ rot pi (cdr (assoc 50 x))))) ; insertion angle on back side
  (T (cons 50 (+ rot (cdr (assoc 50 x)))))	    ; insertion angle on front side
)
...to...
(cons 50 (+ rot (if (BKROT) pi 0.0) (cdr (assoc 50 x))))
(cond
  ((BKROT) (cons 72 2))	; Horz 0 = Left; 1= Center; 2 = Right
  (T (cons 72 0))	; Horz 0 = Left; 1= Center; 2 = Right
)
...to...
(cons 72 (if (BKROT) 2 0))

Best,

~DD

Message 8 of 8

mmitchellH6TRW
Enthusiast
Enthusiast

Thank you DD.

I see how you did that. 

Thank you,

Mark

0 Likes