built in compound context operators: sort-by


sort-by:
    description:
        sort-by[op] input-seq
        sort the superpositions in input-seq with respect to op applied to the kets in those superpositions

    examples:
        -- learn some knowledge:
        age |Fred> => |47>
        age |Sam> => |43>
        age |Rob> => |29>
        age |Emma> => |26>

        -- now sort them:
        sort-by[age] split[" "] |Rob Sam Emma Fred>
            |Emma> + |Rob> + |Sam> + |Fred>

    see also:
        ket-sort, coeff-sort, natural-sort, ket-length

Home