Algorithms


Functions

muse_cell fn_sort_inplace (muse_env *env, void *context, muse_cell args)
 (sort! list [propertyFn]).
muse_cell fn_sort (muse_env *env, void *context, muse_cell args)
 Just like fn_sort_inplace(), except that the original list is not modified.

Function Documentation

muse_cell fn_sort_inplace ( muse_env env,
void *  context,
muse_cell  args 
)

(sort! list [propertyFn]).

Sorts a list in place according to an optional property function. The first argument is the list of objects to sort. The cells in the list are replaced with the same objects in sorted order. The usual object ordering is used, which will sort a numeric list in ascending order.

A propertyFn can be specified to control the sorting order. The ordering of two objects in the list is determined by the ordering of the objects resulting from the application of the property function to the list objects.

This method is not as flexible as giving a comparator function, but it is good enough for most purposes in a scripting language and is more efficient than giving a comparator function. For example, if you want to sort a numeric list in descending order instead of ascending order, you can write -

 (sort! ls -) 
instead of
 (sort! ls) 
If the list consists of lists, then you can use the propertyFn to select an element of the list entries to sort by.

muse_cell fn_sort ( muse_env env,
void *  context,
muse_cell  args 
)

Just like fn_sort_inplace(), except that the original list is not modified.

A new list of the same objects in sorted order is returned.


Generated on Mon Sep 25 23:12:50 2006 for muSE by  doxygen 1.4.7