Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #49142
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | "WJ" <w_a_x_man@yahoo.com> |
| Newsgroups | comp.lang.forth |
| Subject | Tricky sorting |
| Date | Thu, 14 Jul 2016 06:13:45 -0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 45 |
| Message-ID | <nm7ain$gd2$1@dont-email.me> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-1 |
| Injection-Date | Thu, 14 Jul 2016 06:13:45 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="00476de4ebe93eabaf0eb1c04aae8175"; logging-data="16802"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ieDvMxvKEngOWEobIf8Mn" |
| User-Agent | XanaNews/1.18.1.6 |
| Cancel-Lock | sha1:axf6Pl1n6UG2gyNTIQk7gaJgwvs= |
| Xref | csiph.com comp.lang.forth:49142 |
Show key headers only | View raw
You have a list of pairs. After sorting, if you look only at the first element of each pair, it should seem that nothing has changed. Example. (Since we're temporarily ignoring the second elements, they're represented by underscores.) Before: [(5,_); (5,_); (2,_); (2,_)] After: [(5,_); (5,_); (2,_); (2,_)] However, the list should be ordered by the second elements, in so far as that can be done without changing the order of the first elements. Before: [(5,8); (5,0); (2,6); (2,3)] After: [(5,0); (5,8); (2,3); (2,6)] OCaml: List.sort (fun (a,b) (c,d) -> if a=c then compare b d else 0) [3,5; 3,1; 3,3; 1,2; 1,7; 1,1; 888,9; 3,42; 3,0] ;;5 ===> [(3, 1); (3, 3); (3, 5); (1, 1); (1, 2); (1, 7); (888, 9); (3, 0); (3, 42)] For this task, or any task not trivially simple, why would one want to use ANS Forth, a language lacking sorting, lists, arrays, tuples, and just about everything else? -- Amazon bans book. After nearly a month on the site, all traces of the book and its 80 reviews have been removed. http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunkers-5.html https://www.youtube.com/watch?v=EEl_1HWFRfo
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread
Tricky sorting "WJ" <w_a_x_man@yahoo.com> - 2016-07-14 06:13 +0000
Re: Tricky sorting "WJ" <w_a_x_man@yahoo.com> - 2016-07-14 06:25 +0000
Re: Tricky sorting "WJ" <w_a_x_man@yahoo.com> - 2016-07-14 06:44 +0000
Re: Tricky sorting Richard Todd <richard.wesley.todd@gmail.com> - 2016-07-14 14:56 -0700
csiph-web