Author Topic: help list  (Read 4139 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: help list
« Reply #15 on: January 21, 2013, 01:28:24 PM »
My 2 cents with vl-princ-to-string use:


Code: [Select]
(vl-princ-to-string '("99.001101" 77.1111111))
=> "(99.001101 77.1111)"

(vl-princ-to-string '("99.001101" "77.1111111"))
=> "(99.001101 77.1111111)"

(vl-princ-to-string '(99.001101 77.0011111))
=> "(99.0011 77.0011)"

(vl-princ-to-string "(99.001101 77.1111111)")
=> "(99.001101 77.1111111)"

ribarm

  • Gator
  • Posts: 3312
  • Marko Ribar, architect
Re: help list
« Reply #16 on: January 21, 2013, 11:34:03 PM »
Code - Auto/Visual Lisp: [Select]
  1. (setq lst '(("nr" "X" "Y" "Z")
  2.             (1.0 -55687.7 35585.1 0.0)
  3.             (2.0 -54769.5 35230.2 0.0)
  4.             (3.0 -54532.6 35023.2 0.0)
  5.             (4.0 -55184.2 34283.8 0.0)
  6.             (5.0 -55983.9 35230.2 0.0)
  7.             (6.0 (1 "test" 7))
  8.             (7.0 (2 (8 "abc") "abcdef ghijkl")))
  9. )
  10.  
  11. (defun foo ( l / a b c )
  12.   (while (setq a (car l))
  13.     (setq l (cdr l))
  14.     (if (eq (type a) 'str)
  15.         (setq b (cons a b))
  16.         (cond ((eq (type a) 'int)
  17.                (setq b (cons (itoa a) b))
  18.               )
  19.               ((eq (type a) 'real)
  20.                (setq b (cons (rtos a 2 1) b))
  21.               )
  22.               ((eq (type a) 'list)
  23.                (setq b (foo a))
  24.               )
  25.         )
  26.     )
  27.     (if (eq (length b) 1) (setq c (cons (car b) c)) (setq c (cons b c)))
  28.     (setq b nil)
  29.   )
  30.   (reverse c)
  31. )
  32.  
  33. (defun f ( l / ff b )
  34.  (defun ff ( l / a )
  35.    (while (setq a (car l))
  36.      (setq l (cdr l))
  37.      (cond ((and (eq (type a) 'str))
  38.             (setq b (append (list (strlen a)) b))
  39.            )
  40.            ((eq (type a) 'list)
  41.             (ff a)
  42.            )
  43.      )
  44.      (if (not l)
  45.        (setq b (list (apply 'max b)))
  46.      )
  47.    )
  48.    (car b)
  49.  )
  50.  (ff l)
  51. )
  52.  
  53. (defun fff ( l n / a b )
  54.  (while (setq a (car l))
  55.    (setq l (cdr l))
  56.    (cond ((eq (type a) 'str)
  57.           (if (eq (strlen a) n) (setq b a))
  58.          )
  59.          ((eq (type a) 'list)
  60.           (setq b (fff a n))
  61.          )
  62.    )
  63.  )
  64.  b
  65. )
  66.  

Code: [Select]
(fff (foo lst) (f (foo lst)))
=> "abcdef ghijkl"

M.R.
« Last Edit: January 22, 2013, 01:04:16 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: help list
« Reply #17 on: January 22, 2013, 04:11:01 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun f ( l )
  2.     (if (atom l)
  3.         (vl-princ-to-string l)
  4.         (cons (f (car l)) (if (cdr l) (f (cdr l))))
  5.     )
  6. )

Just a little error:
Code: [Select]
(f nil)
=> "nil"

ribarm

  • Gator
  • Posts: 3312
  • Marko Ribar, architect
Re: help list
« Reply #18 on: January 22, 2013, 04:56:58 AM »
Not error at all... nil is both atom and list :

Code: [Select]
(atom nil)
=>T
:wink:

Code: [Select]
(listp nil)
=>T

Code: [Select]
(vl-symbolp nil)
=>nil

Code: [Select]
(atom T)
=>T

Code: [Select]
(listp T)
=>nil

Code: [Select]
(vl-symbolp T)
=>T

Code: [Select]
(atom 1)
=>T

Code: [Select]
(listp 1)
=>nil

Code: [Select]
(vl-symbolp 1)
=>nil

Code: [Select]
(atom 'a)
=>T

Code: [Select]
(listp 'a)
=>nil

Code: [Select]
(vl-symbolp 'a)
=>T
« Last Edit: January 22, 2013, 05:41:57 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: help list
« Reply #19 on: January 22, 2013, 05:20:28 AM »
My 2 cents with vl-princ-to-string use:


Code: [Select]
(vl-princ-to-string '("99.001101" 77.1111111))
=> "(99.001101 77.1111)"

(vl-princ-to-string '("99.001101" "77.1111111"))
=> "(99.001101 77.1111111)"

(vl-princ-to-string '(99.001101 77.0011111))
=> "(99.0011 77.0011)"

(vl-princ-to-string "(99.001101 77.1111111)")
=> "(99.001101 77.1111111)"
Marc, check the OP. He wants the result as a list of string items or lists of string items. Not as a string in total.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: help list
« Reply #20 on: January 22, 2013, 06:22:06 AM »
My 2 cents with vl-princ-to-string use:
Code: [Select]
(vl-princ-to-string '("99.001101" 77.1111111))
=> "(99.001101 77.1111)"
< ... >
Marc, check the OP. He wants the result as a list of string items or lists of string items. Not as a string in total.

I may be wrong, but I believe Marc was referring to the loss of precision when using vl-princ-to-string in his examples.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: help list
« Reply #21 on: January 22, 2013, 06:42:57 AM »
I may be wrong, but I believe Marc was referring to the loss of precision when using vl-princ-to-string in his examples.
:ugly: Stupid of me not to realize!

Sorry Marc!  :-[
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: help list
« Reply #22 on: January 22, 2013, 09:01:10 AM »
I may be wrong, but I believe Marc was referring to the loss of precision when using vl-princ-to-string in his examples.
:ugly: Stupid of me not to realize!

Sorry Marc!  :-[

No problem, thanks Lee.

Marco