TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Grrr1337 on September 23, 2016, 04:00:22 PM

Title: Evaluate items in a list
Post by: Grrr1337 on September 23, 2016, 04:00:22 PM
Hi guys,
Today I was kinda stuck with my ideas and attempts about this.
I was trying to write the following sub-functions:

Function #1 that determines if all of the items are equal to 'nil' or 'T'. (maybe use vl-every?)
Lets name it: (defun IsEveryItem)
Function #2 that determines if there are items equal to 'nil' or 'T'. (use vl-some!)
Lets name it: (defun IsSomeItem)

Check the examples to understand what I mean:
Code: [Select]
(setq LstOne (list nil nil nil nil nil nil))
(setq LstTwo (list T T T T T T T T))
(setq LstThree (list nil T T nil T nil nil))

(IsEveryItem 'T LstOne) -> nil
(IsEveryItem 'T LstTwo) -> T

(IsSomeItem 'nil LstOne) -> T
(IsSomeItem 'T LstOne) -> nil
(IsSomeItem 'T LstThree) -> T
(IsSomeItem 'T LstThree) -> T

I remember that once I was successful about writing func #1, by just doing something like:
Code: [Select]
(defun IsEverythingNil ( Lst / ) (if (= 0 (length (vl-remove 'nil Lst))) 'T nil))But honestly, my approach seems kinda lame... so I've created this thread to see your professional suggestions about this task. :D
Title: Re: Evaluate items in a list
Post by: VovKa on September 23, 2016, 04:19:34 PM
Code: [Select]
(cond
   ((apply 'and lst) "all t")
   ((apply 'or lst) "some t")
   (t "all nil")
)
Title: Re: Evaluate items in a list
Post by: MP on September 23, 2016, 04:31:06 PM
Code: [Select]
(cond
   ((apply 'and lst) "all non nil")
   ((apply 'or lst) "some non nil")
   (t "all nil")
)

Nice ... fify ... retentively yours ... MP :)
Title: Re: Evaluate items in a list
Post by: Grrr1337 on September 23, 2016, 04:44:37 PM
Thanks Vovka,  :yay!:
 That might probably be the most simple and effective suggestion (I don't know when I would thought about it).
 Still looking for more suggestions (just to stretch some flexible minds).
Title: Re: Evaluate items in a list
Post by: VovKa on September 23, 2016, 04:52:27 PM
Code: [Select]
(cond
   ((apply 'and lst) "all non nil")
   ((apply 'or lst) "some non nil")
   (t "all nil")
)

Nice ... fify ... retentively yours ... MP :)
perfect quoting :)
Title: Re: Evaluate items in a list
Post by: MP on September 23, 2016, 05:02:59 PM
:) :)
Title: Re: Evaluate items in a list
Post by: kdub_nz on September 23, 2016, 05:33:23 PM

< .. >

Nice ... fify ... retentively yours ... MP :)

I've never been able to understand how the words punctilious and pedantic have garnered a negative connotation.

Title: Re: Evaluate items in a list
Post by: MP on September 23, 2016, 06:15:17 PM
I've never been able to understand how the words punctilious and pedantic have garnered a negative connotation.

Code: [Select]
(if
    (and
        embellishment_floated_cordially
        embellishment_of_perceived_value
        recipient_is_gracious
    )
    (its_all_good)
    (all_hell_breaks_loose)
)
Title: Re: Evaluate items in a list
Post by: kdub_nz on September 23, 2016, 06:24:08 PM
^^ excellent

while we're playing:

**CHALLENGE**

Required function :
Code: [Select]
bool IsExpressionPrecise ( expression )
Title: Re: Evaluate items in a list
Post by: MP on September 23, 2016, 06:32:33 PM
Required function:
Code: [Select]
bool IsOriginalQuestionStatedClearly ( question )
Title: Re: Evaluate items in a list
Post by: danallen on September 23, 2016, 06:44:47 PM
I've never been able to understand how the words punctilious and pedantic have garnered a negative connotation.

because they rhyme with supercilious & hierophantic
Title: Re: Evaluate items in a list
Post by: kdub_nz on September 23, 2016, 07:07:15 PM
I've never been able to understand how the words punctilious and pedantic have garnered a negative connotation.

because they rhyme with supercilious & hierophantic

and so are bilious and sycophantic


:) wish I had time to play ...
Title: Re: Evaluate items in a list
Post by: roy_043 on September 24, 2016, 04:02:28 AM
Code - Auto/Visual Lisp: [Select]
  1. ; Everything nil check:
  2. (vl-every 'null lst)
  3. ; Some nil check:
  4. (vl-some 'null lst)
  5.  
  6. ; Everything non-nil check:
  7. (not (vl-some 'null lst))
  8. ; Some non-nil check:
  9. (not (vl-every 'null lst))
  10.  
  11. ; 'Is true' predicate function:
  12. (defun True_P (x) (= x T))
  13. ; Everything T check:
  14. (vl-every 'True_P lst)
  15. ; Some T check:
  16. (vl-some 'True_P lst)
  17.  
  18. ; Everything is number check:
  19. ; Some is number check:
Title: Re: Evaluate items in a list
Post by: Grrr1337 on September 24, 2016, 10:35:15 AM
Thank you, Roy! I'll try them out.
You guys are awesome.  8-)