All Manuals > CAPI User Guide and Reference Manual > 21 CAPI Reference Entries

NextPrevUpTopContentsIndex

make-sorting-description

Function
Summary

Makes a sorting description suitable for use in a sorted-object.

Package

capi

Signature

make-sorting-description &key type key sort reverse-sort sort-function object-sort-caller => sorting-description

Arguments

type

A Lisp object naming the type of sorting.

key

A function of 1 argument.

sort

A function of 2 arguments.

reverse-sort

A function of 2 arguments.

sort-function

A sorting function.

object-sort-caller

A function of 5 arguments.

Description

The function make-sorting-description makes a sorting description object that can be used as one of the sort-descriptions in a sorted-object such as a list-panel.

type is a name that should be unique (compared by cl:equalp) amongst the sort-descriptions of a sorted-object.

key is a function that is passed to sort-function as its :key argument. The default value of key is cl:identity.

sort is a predicate function that is passed to sort-function to compare pairs of items.

reverse-sort is a predicate function that is passed to sort-function for reverse sorting.

Unless object-sort-caller is supplied, sort-function is the function that is called to actually do the sorting. Its signature is:

sort-function items predicate &key key

The default value of sort-function is cl:sort.

When object-sort-caller is supplied, then it is called instead of calling the sort-function , and is responsible for the sorting. The signature of the caller is:

object-sort-caller sorted-object items sort-function sort sort-key => sorted-items

where sorted-object is the sorted-object itself, items is the list of items to sort, and sort-function , sort and key are taken from the description. sort is either the sort or reverse-sort as appropriate. The caller needs to return a sorted list of the items.

The caller can do the default behavior by:

funcall sort-function item sort :key key
Notes
  1. The purpose of using object-sort-caller is to allow access to the sorted-object to decide how to do the sorting. When using object-sort-caller , the sort-function , sort , reverse-sort and key are used solely as arguments to it, hence in this case you can supply arbitrary values which the caller interprets.
  2. The sorting can be destructive
Example
(setq lp 
      (capi:contain 
       (make-instance 
        'capi:list-panel 
        :items '("Apple" 
                 "Orange" 
                 "Mangosteen" 
                 "Pineapple")
        :visible-min-height '(:character 5)
        :sort-descriptions 
        (list (capi:make-sorting-description 
               :type :length
               :sort 
               #'(lambda (x y) 
                   (> (length x) (length y)))
               :reverse-sort 
               #'(lambda (x y) 
                   (< (length x) (length y))))
              (capi:make-sorting-description 
               :type :alphabetic
               :sort 'string-greaterp
               :reverse-sort 'string-lessp)))))
 
(capi:sorted-object-sort-by lp :length)
 
(capi:sorted-object-sort-by lp :alphabetic)
See also

sort-object-items-by
sorted-object
sorted-object-sort-by


CAPI User Guide and Reference Manual (Macintosh version) - 3 Aug 2017

NextPrevUpTopContentsIndex