Code Red > AutoLISP (Vanilla / Visual)

BFindV2 - sorting by length not alphabetically

(1/2) > >>

dami:
Hello,
I'm using BFindV2 by Lee Mac (http://www.lee-mac.com/bfind.html) and came across a problem when source text cannot be found because it contained the word which have been already replaced. Easy solution for this can be just sorting all elements of list by lenght - longer element can not be included in shorter one.
I noticed that elements of the list are being sorted alphabetically. Was trying to get into code, but have never using LISP before.

Probably this method is doing the job:

--- Code: ---  (defun _SortByFirst ( lst )
    (vl-sort lst (function (lambda ( a b ) (< (car a) (car b)))))
  )
--- End code ---

I was trying this:

--- Code: ---(vl-sort lst (function (lambda ( a b ) (< (length a) (length b)))))
--- End code ---

...but It does not work. I probably misunderstand the code.

Please, can you guys help me?
best,
D

Dlanor:

--- Quote from: dami on May 18, 2019, 07:30:32 AM ---Hello,
I'm using BFindV2 by Lee Mac (http://www.lee-mac.com/bfind.html) and came across a problem when source text cannot be found because it contained the word which have been already replaced. Easy solution for this can be just sorting all elements of list by lenght - longer element can not be included in shorter one.
I noticed that elements of the list are being sorted alphabetically. Was trying to get into code, but have never using LISP before.

Probably this method is doing the job:

--- Code: ---  (defun _SortByFirst ( lst )
    (vl-sort lst (function (lambda ( a b ) (< (car a) (car b)))))
  )
--- End code ---

I was trying this:

--- Code: ---(vl-sort lst (function (lambda ( a b ) (< (length a) (length b)))))
--- End code ---

...but It does not work. I probably misunderstand the code.

Please, can you guys help me?
best,
D

--- End quote ---

Perhaps


--- Code - Auto/Visual Lisp: --- (vl-sort lst (function (lambda ( a b ) (< (strlen (car a)) (strlen (car b))))))

dami:
Nope, it doesn't sort properly.
Well, I just sorted my .txt file and left fuction in such silly definition:

--- Code: --- (defun _SortByFirst ( lst )
    lst
  )
--- End code ---

At least I achieved what I wanted :-)

kdub_nz:

--- Quote from: dami on May 18, 2019, 05:32:49 PM ---Nope, it doesn't sort properly.
Well, I just sorted my .txt file and left fuction in such silly definition:

--- Code: --- (defun _SortByFirst ( lst )
    lst
  )
--- End code ---

At least I achieved what I wanted :-)

--- End quote ---


It's very difficult not to laugh ...

roy_043:
Probably '<' should be '>' in Dlanor's suggestion.

Navigation

[0] Message Index

[#] Next page

Go to full version