Author Topic: Is there a way to make a list of a list of two tie?  (Read 1406 times)

0 Members and 1 Guest are viewing this topic.

rlxozzang

  • Guest
Is there a way to make a list of a list of two tie?
« on: September 26, 2012, 04:29:51 AM »
((130.50 240.75)(130.50 280.75)(157.35 240.75)(157.35 280.75)( 15.   256.75)(195.   256.75))

The list above

(
  ((130.5 240.75) (130.5 280.75))
  ((157.35 240.75)(157.35 280.75))
  (( 15.   256.75)(195.   256.75))
)

I would like to list up to three so two tied ...

Help ask me ..
Thank you very much.!

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Is there a way to make a list of a list of two tie?
« Reply #1 on: September 26, 2012, 04:55:13 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun f (l)
  2.   (if l
  3.     (cons (list (car l) (cadr l)) (f (cddr l)))
  4.   )
  5. )

Code: [Select]
(setq l '((130.50 240.75)
          (130.50 280.75)
          (157.35 240.75)
          (157.35 280.75)
          (15. 256.75)
          (195. 256.75)
         )
)
(f l)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Is there a way to make a list of a list of two tie?
« Reply #2 on: September 26, 2012, 05:36:17 AM »
To group by any number:

http://lee-mac.com/groupbynum.html

For your example:
Code: [Select]
(setq lst
   '(
        (130.50 240.75)
        (130.50 280.75)
        (157.35 240.75)
        (157.35 280.75)
        (15.0 256.75)
        (195.0 256.75)
    )
)
(LM:GroupByNum lst 2)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Is there a way to make a list of a list of two tie?
« Reply #4 on: September 26, 2012, 08:38:04 AM »
Hi,

Nothing new about specifically "grouping by number", but a way using a re-usable subroutine which allows to define some more (maybe) usefull ones.

Code - Auto/Visual Lisp: [Select]
  1. ;; gc:BreakAt
  2. ;; Breaks a list into two sublists.
  3. ;;
  4. ;; Arguments
  5. ;; i: index of the second sublist first item (IOW length of the first one).
  6. ;; l: source list.
  7. (defun gc:BreakAt (i l / r)
  8.   (while (and l (< 0 i))
  9.     (setq r (cons (car l) r)
  10.           l (cdr l)
  11.           i (1- i)
  12.     )
  13.   )
  14.   (list (reverse r) l)
  15. )
  16.  
  17. ;; gc:Split
  18. ;; Splits a list into sublists of specified length
  19. ;;
  20. ;; Arguments
  21. ;; n: number of items of each sublist.
  22. ;; l: source list.
  23. (defun gc:Split (n l / s)
  24.   (if (and l (setq s (gc:BreakAt n l)))
  25.     (cons (car s) (gc:Split n (cadr s)))
  26.   )
  27. )
  28.  
  29. ;; gc:Take
  30. ;; Returns a list containing the nth first items of the source list
  31. ;;
  32. ;; Arguments
  33. ;; n: length of the returned list.
  34. ;; l: source list.
  35. (defun gc:Take (n l)
  36.   (car (gc:BreakAt n l))
  37. )
  38.  
  39. ;; gc:Skip
  40. ;; Returns the source list but its nth first items
  41. ;;
  42. ;; Arguments
  43. ;; n: number of items to remove from the list start.
  44. ;; l: source list.
  45. (defun gc:Skip (n l)
  46.   (cadr (gc:BreakAt n l))
  47. )
  48.  
  49. ;; gc:SubList
  50. ;; Returns a sublist of the source list.
  51. ;;
  52. ;; Arguments
  53. ;; i: ind of the first sublist item.
  54. ;; n: length of the sublist.
  55. ;; l: source list.
  56. (defun gc:SubList (i n l)
  57.   (gc:Take n (gc:Skip i l))
  58. )
Speaking English as a French Frog

rlxozzang

  • Guest
Re: Is there a way to make a list of a list of two tie?
« Reply #5 on: September 27, 2012, 01:06:36 AM »
Help us thank all those  :lmao: