Next: mpg-ref-source_file, Previous: mpg-ref-skip_line, Up: mpg-bpr [Contents][Index]

`sort/2`

`sort(`

`+List`, `-Sorted`)

Sorts the elements of the list `List` into the ascending
standard order, and removes any multiple occurrences of an element.
The resulting sorted list is unified with the list `Sorted`.

`List`*list of term*, must be a proper list`Sorted`*list of term*

`Sorted` is type checked since release 4.3 for alignment with the
ISO Prolog standard. Previous releases simply failed instead of
reporting an error for malformed `Sorted`.

`instatiation_error`

`type_error`

`List`is not a proper list`type_error`

`Sorted`cannot be unified with a proper list

| ?-sort([a,X,1,a(x),a,a(X)], L).L = [X,1,a,a(X),a(x)]

(The time taken to do this is at worst order (`N` log `N`) where
`N` is the length of the list.)

Send feedback on this subject.