Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #43789

Re: For sorting, compare two sequences

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Re: For sorting, compare two sequences
Date 2015-11-25 23:56 +0000
Organization A noiseless patient Spider
Message-ID <n35hra$v6e$1@dont-email.me> (permalink)
References <kjh3on$536$1@dont-email.me> <mei35d$ivm$1@dont-email.me>

Show all headers | View raw


WJ wrote:

> WJ wrote:
> 
> > Sort a sequence of sequences.  When comparing two sequences,
> > work from left to right and stop when the two elements differ.
> > 
> > Factor:
> > 
> > { { 2 5 "task" }
> >   { 2 4 "trollop" }
> >   { 0 9 "zoo" }
> >   { 2 5 "talk" }
> >   { 7 0 "able" }
> >   { 2 5 "less" }
> >   { 7 8 "ease" }
> >   { 2 5 "clear" } }  [ <=> ] sort .
> > 
> > 
> > {
> >     { 0 9 "zoo" }
> >     { 2 4 "trollop" }
> >     { 2 5 "clear" }
> >     { 2 5 "less" }
> >     { 2 5 "talk" }
> >     { 2 5 "task" }
> >     { 7 0 "able" }
> >     { 7 8 "ease" }
> > }
> 
> Oforth:
> 
> func: list<
> { zip detect( #[ reduce(#<>) ], -1 )
>   dup isNull ifTrue: [ drop 0 ]
>   else: [ reduce(#<) ]
> }
> 
> func: ; { [yourself] + }
> 
> 
> [ [ 7, 0, "able" ] ]
>   [ 2, 5, "task" ];
>   [ 2, 4, "trollop" ];
>   [ 8, 9, "zoo" ];
>   [ 2, 5, "talk" ];
>   [ 2, 5, "harridan" ];
>   [ 7, 8, "ease" ];
>   [ 2, 5, "clear" ];
> 
>  > sortWith( #list< ) println
> [[2, 4, trollop],
>  [2, 5, clear],
>  [2, 5, harridan],
>  [2, 5, talk],
>  [2, 5, task],
>  [7, 0, able],
>  [7, 8, ease],
>  [8, 9, zoo]]

Ocaml:

List.sort compare [7, 0, "able" ;
 2, 5, "task" ;
 2, 4, "trollop" ;
 8, 9, "zoo" ;
 2, 5, "talk" ;
 2, 5, "harridan" ;
 7, 8, "ease" ;
 2, 5, "clear" ];;

[(2, 4, "trollop");
 (2, 5, "clear");
 (2, 5, "harridan");
 (2, 5, "talk");
 (2, 5, "task");
 (7, 0, "able");
 (7, 8, "ease");
 (8, 9, "zoo")]

Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread


Thread

Re: For sorting, compare two sequences "WJ" <w_a_x_man@yahoo.com> - 2015-11-25 23:56 +0000

csiph-web