Author Topic: Help with vl-sort  (Read 103 times)

0 Members and 1 Guest are viewing this topic.

velasquez

  • Newt
  • Posts: 166
Help with vl-sort
« on: March 20, 2017, 09:01:56 pm »

In my language there are words like "Tê" "Válvula" "pé"
I'm having problems with working with vl-sort
Code: [Select]
(vl-sort '(("Tubo" "Tê" "Tão" "Válvula" "Registro"))  '(lambda (a b) (< (cadr a) (cadr b))))
;;;Returns -> (("Tubo" "Tê" "Tão" "Válvula" "Registro"))         

;;; In my language, the return must be like ->  '(("Tão" "Tê" "Tubo" "Registro" "Válvula"))
Can someone give me a way?

ifncdylan

  • Newt
  • Posts: 56
Re: Help with vl-sort
« Reply #1 on: March 20, 2017, 09:31:15 pm »
Forgive me but what language is it? :)

kdub

  • SuperMod
  • Swamp Rat
  • Posts: 820
  • class keyThumper<T>:ILazy<T>
Re: Help with vl-sort
« Reply #2 on: March 20, 2017, 10:36:11 pm »
Forgive me but what language is it? :)

I'd guess Portuguese or Spanish.
called Kerry in my other life

Sometimes the question is more important than the answer.

gile

  • Water Moccasin
  • Posts: 2034
  • Marseille, France
Re: Help with vl-sort
« Reply #3 on: March 21, 2017, 02:09:05 am »
Hi,

I don't know why you have a single list nested in a single list, but what you need is simply sort the 'car' of the parent list:
Code - Auto/Visual Lisp: [Select]
  1. (list (vl-sort (car '(("Tubo" "Tê" "Tão" "Válvula" "Registro"))) '<))

which is the same as
Code - Auto/Visual Lisp: [Select]
  1. (list (vl-sort  '("Tubo" "Tê" "Tão" "Válvula" "Registro") '<))
Speaking English as a French Frog

VovKa

  • Swamp Rat
  • Posts: 720
  • Ukraine
Re: Help with vl-sort
« Reply #4 on: March 21, 2017, 03:30:46 am »
use acad_strlsort

Peter2

  • Bull Frog
  • Posts: 400
Re: Help with vl-sort
« Reply #5 on: March 21, 2017, 04:00:17 am »
;;; In my language, the return must be like ...
Can someone give me a way?
I fear that there is no common solution  :-(
For me, the only unique sorting order is "a-z" and "0-9...". All other can be discussed and defined. Is it
  • "A a B b" or "a A b B"
  • "a ä" or "ä a" or "a-z ä" (German Umlaute)
  • "â a á à or á a à â or ....(other diacritics)
  • what's about the letters which are beyond a-z? (IIRC "ck" is an own letter in Czech ....)
So maybe you have to code it for every special character ....
Peter

AutoCAD 2011 - 2017 German (so some technical terms will be badly retranslated to English)

velasquez

  • Newt
  • Posts: 166
Re: Help with vl-sort
« Reply #6 on: March 21, 2017, 06:43:11 am »
Hi,

I don't know why you have a single list nested in a single list, but what you need is simply sort the 'car' of the parent list:
Code - Auto/Visual Lisp: [Select]
  1. (list (vl-sort (car '(("Tubo" "Tê" "Tão" "Válvula" "Registro"))) '<))

which is the same as
Code - Auto/Visual Lisp: [Select]
  1. (list (vl-sort  '("Tubo" "Tê" "Tão" "Válvula" "Registro") '<))

This list is part of a larger list.

velasquez

  • Newt
  • Posts: 166
Re: Help with vl-sort
« Reply #7 on: March 21, 2017, 06:44:12 am »
Forgive me but what language is it? :)

My language is Portuguese.