Author Topic: Evaluate items in a list  (Read 2211 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Evaluate items in a list
« 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
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Evaluate items in a list
« Reply #1 on: September 23, 2016, 04:19:34 PM »
Code: [Select]
(cond
   ((apply 'and lst) "all t")
   ((apply 'or lst) "some t")
   (t "all nil")
)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Evaluate items in a list
« Reply #2 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 :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Evaluate items in a list
« Reply #3 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).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Evaluate items in a list
« Reply #4 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 :)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Evaluate items in a list
« Reply #5 on: September 23, 2016, 05:02:59 PM »
:) :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Evaluate items in a list
« Reply #6 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.

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Evaluate items in a list
« Reply #7 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)
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Evaluate items in a list
« Reply #8 on: September 23, 2016, 06:24:08 PM »
^^ excellent

while we're playing:

**CHALLENGE**

Required function :
Code: [Select]
bool IsExpressionPrecise ( expression )
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Evaluate items in a list
« Reply #9 on: September 23, 2016, 06:32:33 PM »
Required function:
Code: [Select]
bool IsOriginalQuestionStatedClearly ( question )
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

danallen

  • Guest
Re: Evaluate items in a list
« Reply #10 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

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Evaluate items in a list
« Reply #11 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 ...
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Evaluate items in a list
« Reply #12 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:

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Evaluate items in a list
« Reply #13 on: September 24, 2016, 10:35:15 AM »
Thank you, Roy! I'll try them out.
You guys are awesome.  8-)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg