"and", no not the function. Help with evaluating 2 expressions

"and", no not the function. Help with evaluating 2 expressions

Anonymous
Not applicable
1,410 Views
10 Replies
Message 1 of 11

"and", no not the function. Help with evaluating 2 expressions

Anonymous
Not applicable

Hi all.

 

Need to call on your expertise again. 

 

I find many times where I want to say "and" in my routines, For example in "plain" English:

 

"If Angle1 is less than 0 and  Angle2 is greater than 0, then SETQ....blah blah blah

 

Is there a function or expression that lets you do this?

Ultimately find a work around with multiple if statements or cond. It always seems to get messy and convoluted.

 

 

Is there a simpler way to evaluate/compare to arguments like that?

Any help is appreciated.

 

Thank you

0 Likes
Accepted solutions (1)
1,411 Views
10 Replies
Replies (10)
Message 2 of 11

Shneuph
Collaborator
Collaborator

You're saying you're looking for an alternative to the AND function?

 

(If (and

      (< Angle1 0)

      (> Angle2 0)

      );and

  (setq .....)

  );if

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 3 of 11

ВeekeeCZ
Consultant
Consultant
Accepted solution

And actually IS the function.

 

Your example.

 

(if (and (< angle1 0)
	 (> angle2 0)
	 )
  (setq blah "blah"))

It could even be used in following syntax. The result is the same.

 

(and (< angle1 0)
     (> angle2 0)
     (setq blah "blah")
     )

 

 

Message 4 of 11

Anonymous
Not applicable

Thank You! Your examples were quite helpful

 

I was confused by the cryptic definition of AND I was looking at.

 

"...Arguments
expr Any expression.
Return Values
Nil, if any of the expressions evaluate to nil; otherwise T. If and is issued
without arguments, it returns T.
Examples
Command: (setq a 103 b nil c "string")
"string"
Command: (and 1.4 a c)
T
Command: (and 1.4 a b c)
nil"

 

your examples make perfect sense.

Thanks Again.

 

0 Likes
Message 5 of 11

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

Thank You! Your examples were quite helpful

 

I was confused by the cryptic definition of AND I was looking at.

 

"...Arguments
expr Any expression.
Return Values
Nil, if any of the expressions evaluate to nil; otherwise T. If and is issued
without arguments, it returns T.
Examples
Command: (setq a 103 b nil c "string")
"string"
Command: (and 1.4 a c)
T
Command: (and 1.4 a b c)
nil"

 

your examples make perfect sense.

Thanks Again.

 


The number 1.4 inside of and does not make much sence. It's always T. But testing variables (and a b c) for not nil, that makes the sence.

BTW an empty string variable (setq a "") is True.

Message 6 of 11

steve_carson
Enthusiast
Enthusiast

Thanks for the info regarding an empty string, BeekeeCZ.

 

I think it's weird that an empty string is T, but an empty list is nil...

 

Command: (and "")
T

Command: (and '())
nil

Command: (= '() nil)
T

 

 

Steve

0 Likes
Message 7 of 11

Kent1Cooper
Consultant
Consultant

@steve_carson wrote:

.... 

I think it's weird that an empty string is T, but an empty list is nil...

....


Just to add another to that list of empty things that may or may not be nil:

 

The result of (ssget), if nothing is selected or found, is nil, not an empty selection set.  But empty selection sets can "exist" -- if you remove everything from a selection set with (ssdel) functions, or start an empty one via (ssadd) with no items-do-add argument, it may be empty and have an (sslength) of 0, but it still "exists" and is not nil.

Kent Cooper, AIA
0 Likes
Message 8 of 11

john.uhden
Mentor
Mentor
Kudos to you!
Do you remember Stephan Koster too?
He's the one that got me hooked on anding.
Technically, it stops further evaluations if any returns nil.

John F. Uhden

0 Likes
Message 9 of 11

ВeekeeCZ
Consultant
Consultant

@john.uhden wrote:
Kudos to you!
Do you remember Stephan Koster too?
He's the one that got me hooked on anding.
Technically, it stops further evaluations if any returns nil.

Thanks! Unfortunately I have no idea how this guy is, although I know you've noticed him before. But I remember were I saw this 'odd' usage of and function for the first time - it made me a little thinking about it. It was @Kent1Cooper 's ReportAngle routine HERE.

 

Another interesting constructions using similar principle are...

 

(or dst
    (initget 5)
    (setq dst (getdist "\nSet distance: "))
    )

;;;;;

(setq dst (cond ((getdist "\nSet distance <10>: "))
		(10)))
0 Likes
Message 10 of 11

martti.halminen
Collaborator
Collaborator

 

The rules about truth values in the Lisp language family (except Scheme) can be expressed quite simply:

 

1. The symbol NIL and the empty list are the same object, there is no way to distinguish between them.

 

2. NIL is the only thing that is considered false in a boolean context (IF, COND, AND, OR etc.)

 

3. Anything else whatsoever is considered as true.

 

-- 

 

0 Likes
Message 11 of 11

martti.halminen
Collaborator
Collaborator

 

I'd write the last one slightly differently:

(setq dst (cond ((getdist "\nSet distance <10>: "))
		(T 10)))

but that is just a style preference.

 

This is a little contrived construction, usually only seen in AutoLISP.

That would be legal also in other Lisps, but there this can be done in a simpler way, because in other Lisps OR returns the value of the last thing it evaluated, instead of T:

(setq dst (or (getdist "\nSet distance <10>: ")
              10))

0 Likes