Author Topic: null string in list  (Read 10340 times)

0 Members and 1 Guest are viewing this topic.

csgoh

  • Newt
  • Posts: 176
Re: null string in list
« Reply #15 on: August 03, 2015, 11:08:25 PM »
Thank you all for the contribution.
cheers

77077

  • Guest
Re: null string in list
« Reply #16 on: August 04, 2015, 12:01:21 AM »
Lee ,can make it like this ?
'("" "" "") returns nil
'("1" "" "") returns nil
'("1" "10" "") returns nil
……
……
Only '("1" "s1"  "a") returns T

Code - Auto/Visual Lisp: [Select]
  1. _$ (defun f ( x ) (equal x '("1" "s1" "a")))
  2. _$ (f '("1" "s1" "a"))
  3. T

Thanks Lee,

77077

  • Guest
Re: null string in list
« Reply #17 on: August 04, 2015, 12:03:53 AM »
Another:
Code - Auto/Visual Lisp: [Select]
  1. (vl-every '= (cons "" lst) lst)

Very good roy.
Thanks.

@ ANJALI: If you want to check for the absence of empty strings you should try Keith's contribution. His code checks for the opposite, but that can easily be fixed...

Roy, Thank you. useful

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: null string in list
« Reply #18 on: August 04, 2015, 12:33:51 AM »
another:
Code: [Select]
(setq l '("" "" "" ""))
(eq (strlen (vl-princ-to-string l)) (1+ (length l)))
or
(and (eq "" (car l)) (equal l (acad_strlsort l)))

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: null string in list
« Reply #19 on: August 04, 2015, 05:21:33 AM »
My variant
Code: [Select]
(apply '= (cons "" lst))
Nice! Very succinct and using 'Classic' Lisp only.

bruno_vdh

  • Guest
Re: null string in list
« Reply #20 on: August 04, 2015, 05:41:27 AM »
Nice! Very succinct and using 'Classic' Lisp only.
Yes, thank you
I'm surprised it is not written on TheSwamp

 = function alone is sufficient,
Code: [Select]
_$ (= "" "" "" "")
T
_$ (= "" 2 ABC T)
nil

Regards,
(Ps: roy_043, congratulation your solution with vl-every is very efficient)
« Last Edit: August 04, 2015, 05:48:03 AM by bruno_vdh »

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: null string in list
« Reply #21 on: August 04, 2015, 08:35:39 AM »
Nice! Very succinct and using 'Classic' Lisp only.
Yes, thank you
I'm surprised it is not written on TheSwamp

 = function alone is sufficient,
Code: [Select]
_$ (= "" "" "" "")
T
_$ (= "" 2 ABC T)
nil

Regards,
(Ps: roy_043, congratulation your solution with vl-every is very efficient)


But it is written on TheSwamp :-) You just added it ...

Incidentally,

Code: [Select]
_$ (= "a" "a" "a" "a")
T
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

bruno_vdh

  • Guest
Re: null string in list
« Reply #22 on: August 04, 2015, 09:36:09 AM »
Incidentally,

Code: [Select]
_$ (= "a" "a" "a" "a")
T

Sorry Keith, translator problem
I thought I explained why (apply '= (cons "" lst)), work in all cases
Code: [Select]
_$ (cons "" '("a" "a" "a" "a"))
("" "a" "a" "a" "a")
_$ (= "" "a" "a" "a" "a")
nil

Regards,
« Last Edit: August 04, 2015, 09:48:37 AM by bruno_vdh »

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: null string in list
« Reply #23 on: August 04, 2015, 09:55:06 AM »
My first lisp in many years. Kinda fun (the code is kludgy but it was fun).

Code - Auto/Visual Lisp: [Select]
  1. (apply 'and (mapcar '(lambda (x) (eq (ascii x) 0)) '("" "" "")))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: null string in list
« Reply #24 on: August 04, 2015, 10:17:31 AM »
Oh, I made it smaller!? This one only checks to see if all entries are the same though.

Code - Auto/Visual Lisp: [Select]
  1. (apply '= (mapcar 'ascii '("" "" "")))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: null string in list
« Reply #25 on: August 04, 2015, 10:27:39 AM »
Hello,
Quote
I have say a list ("" "" "" "" "").
My variant
Code: [Select]
(apply '= (cons "" lst))

Regards,

That's nice.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: null string in list
« Reply #26 on: August 04, 2015, 10:41:29 AM »
for maniacs...

Code: [Select]
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 262144 iteration(s):
    (VL-REMOVE1 ALIST).....2000 / 3.6 <fastest>
    (VL-REMOVE1 ALIST).....2000 / 3.6
    (VL-EVERY12 ALIST).....2282 / 3.16
    (VL-EVERY12 ALIST).....2297 / 3.14
    (F ALIST)..............2375 / 3.03
    (F ALIST)..............2391 / 3.01
    (APPLY1 ALIST).........2547 / 2.83
    (APPLY1 ALIST).........2563 / 2.81
    (APPLY3 ALIST).........2672 / 2.7
    (APPLY3 ALIST).........2672 / 2.7
    (APPLY2 ALIST).........2719 / 2.65
    (APPLY2 ALIST).........2734 / 2.63
    (F2 ALIST).............2922 / 2.47
    (F2 ALIST).............2938 / 2.45
    (APPLY6 ALIST).........3156 / 2.28
    (APPLY6 ALIST).........3172 / 2.27
    (APPLY4 ALIST).........3375 / 2.13
    (APPLY4 ALIST).........3375 / 2.13
    (VL-SOME1 ALIST).......5516 / 1.31
    (VL-SOME1 ALIST).......5546 / 1.3
    (APPLY5 ALIST).........5656 / 1.27
    (APPLY5 ALIST).........5672 / 1.27
    (F3 ALIST).............6407 / 1.12
    (F3 ALIST).............6421 / 1.12
    (VL-EVERY1 ALIST)......7187 / 1
    (VL-EVERY1 ALIST)......7203 / 1 <slowest>

Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 262144 iteration(s):
    (VL-REMOVE1 ALIST).....1860 / 3.72 <fastest>
    (VL-REMOVE1 ALIST).....1875 / 3.69
    (VL-EVERY12 ALIST).....2140 / 3.23
    (VL-EVERY12 ALIST).....2141 / 3.23
    (F ALIST)..............2250 / 3.08
    (F ALIST)..............2250 / 3.08
    (APPLY1 ALIST).........2297 / 3.01
    (APPLY1 ALIST).........2313 / 2.99
    (APPLY3 ALIST).........2406 / 2.88
    (APPLY3 ALIST).........2422 / 2.86
    (APPLY2 ALIST).........2438 / 2.84
    (APPLY2 ALIST).........2469 / 2.8
    (F2 ALIST).............2750 / 2.52
    (F2 ALIST).............2765 / 2.5
    (APPLY6 ALIST).........2797 / 2.47
    (APPLY6 ALIST).........2797 / 2.47
    (APPLY4 ALIST).........3000 / 2.31
    (APPLY4 ALIST).........3016 / 2.3
    (APPLY5 ALIST).........5218 / 1.33
    (APPLY5 ALIST).........5250 / 1.32
    (VL-SOME1 ALIST).......5265 / 1.31
    (VL-SOME1 ALIST).......5266 / 1.31
    (F3 ALIST).............6016 / 1.15
    (F3 ALIST).............6032 / 1.15
    (VL-EVERY1 ALIST)......6875 / 1.01
    (VL-EVERY1 ALIST)......6922 / 1 <slowest>
Code: [Select]
(defun apply1 (lst) (apply '= (cons "" lst)))
(defun vl-remove1 (lst) (not (vl-remove "" lst)))
(defun vl-every1 (l) (vl-every '(lambda (x) (and (= (type x) 'str) (= x ""))) l))
(defun apply2 (l) (zerop (strlen (apply 'strcat l))))
(defun apply3 (l) (= "" (apply 'strcat l)))
(defun apply4 (l) (zerop (apply '+ (mapcar 'strlen l))))
(defun vl-every12 (lst) (vl-every '= (cons "" lst) lst))
(defun vl-some1 (l) (not (vl-some '(lambda (u) (/= u "")) l)))
(defun f ( l ) (or (not l) (and (= "" (car l)) (f (cdr l)))))
(defun f2 (l) (eq (strlen (vl-princ-to-string l)) (1+ (length l))))
(defun f3 (l) (and (eq "" (car l)) (equal l (acad_strlsort l))))
(defun apply5 (l) (apply 'and (mapcar '(lambda (x) (eq (ascii x) 0)) l)))
(defun apply6 (l) (apply '= (mapcar 'ascii l)))
  :crazy2:

bruno_vdh

  • Guest
Re: null string in list
« Reply #27 on: August 04, 2015, 11:20:21 AM »

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: null string in list
« Reply #28 on: August 04, 2015, 11:39:57 AM »
additional variant:
Code - Auto/Visual Lisp: [Select]
  1. (defun eea (l) (vl-every (function =) (cons "" l) l))
« Last Edit: August 04, 2015, 11:48:33 AM by ElpanovEvgeniy »

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: null string in list
« Reply #29 on: August 04, 2015, 11:46:50 AM »
sorry this option is already there.  :-)

Code - Auto/Visual Lisp: [Select]
  1. (defun vl-every12 (lst) (vl-every '= (cons "" lst) lst))