Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Sort Problem

From: louisaturk::coxinet::net at: 15-Nov-2001 5:13

Fellow Rebolers, Why won't this script work? Also, is there an easier or better way to do this? Sample data is at the bottom of this message. Important: I want to reverse sort by integer not by string (for example, sort 115 not "115"). I do not want the word strings considered in the sort. I want results as follows: a 115 abraam 73 agaqa 11 abussou 6 agaqe 6 aarwn 5 and so forth. I put the numbers before the words in the script trying to get it to work, but I really want the numbers after the words. I converted the database to objects trying to get a sort by integer, but that is not necessary. I just want a sort routine that will work. Many thanks in advance. Louis REBOL[ Title: "Frequency Sort" Date: 14-Nov-2001 Version: 0.1.6 File: %frequency.r Author: "Louis A. Turk" Email: [louisaturk--eudoramail--com] Language: 'English Purpose: {Sorts each line in a file by the integer number field largest to smallest integer} Comments: {} ] record: context [word: number: none] database: copy [] data: read/lines %gsorted.txt foreach line data [ foreach [gword num] parse line " " [ record: make object! [ number: to-integer num word: to-string gword ] database: join database record ] ] database: sort database /reverse foreach record database [ print join record/number join " " record/word ] { %gsorted.txt contains the following data: a 115 aarwn 5 abaddwn 1 abarh 1 abba 3 abel 4 abia 3 abiaqar 1 abilhnhj 1 abioud 2 abraam 73 abusson 3 abussou 6 agaboj 2 agagein 3 agagete 4 agagh 2 agagonta 1 agagontej 1 agagwsin 1 agaqa 11 agaqaj 2 agaqe 6 agaqh 4 }