Home   Archive   Permalink



sort/skip size question

i am not clear about the sort/skip function in Rebol.
    
at the following link http://www.rebol.com/docs/words/wsort.html
    
/skip - Treat the series as records of fixed size.
size - Size of each record. (must be: integer)
    
what is the SIZE about ? it's not clear to me. is it the number of columns in a record? to me the size of a record is normally in bytes
    
thanks.

posted by:   sort/skip       7-Sep-2017/18:55:45-7:00



this is my code and my trials with different sizes and the results are quite confusing.
    
names: [
     Evie Jordan 43 eve@jordan.dom
     Matt Harrison 87 matt@harrison.dom
     Luke Skywader 32 luke@skywader.dom
     adam Landwalker 104 beth@landwalker.dom
     Adam Beachcomber 29 adam@bc.dom
]
    
sort/skip names 1
    
foreach [first-name last-name age email zz] names [
     print [first-name last-name age email zz]
]
        
    
results I get with size 1 :-
adam Adam Beachcomber Evie Harrison
Jordan Landwalker Luke Matt Skywader
29 32 43 87 104
adam@bc.dom beth@landwalker.dom eve@jordan.dom luke@skywader.dom matt@harrison.dom
    
results I get with size 2
adam Landwalker Adam Beachcomber Evie
Jordan Luke Skywader Matt Harrison
29 adam@bc.dom 32 luke@skywader.dom 43
eve@jordan.dom 87 matt@harrison.dom 104 beth@landwalker.dom
    
with size 3:-
** Script Error: Invalid argument: 3
** Near: sort/skip names 3
foreach [first-name last-name age email zz]
>>
    
with size 4:-
adam Landwalker 104 beth@landwalker.dom Adam
Beachcomber 29 adam@bc.dom Evie Jordan
43 eve@jordan.dom Luke Skywader 32
luke@skywader.dom Matt Harrison 87 matt@harrison.dom
>>
    
with size 5
    
Evie Jordan 43 eve@jordan.dom Matt
Harrison 87 matt@harrison.dom Luke Skywader
32 luke@skywader.dom adam Landwalker 104
beth@landwalker.dom Adam Beachcomber 29 adam@bc.dom
    
********************************************
looks a bit confusing to me.


posted by:   sort/skip question continued       7-Sep-2017/19:22:10-7:00



sorry I reran with the following code, with varying sizes and the results printed below.
    
names: [
     Evie Jordan 43 eve@jordan.dom
     Matt Harrison 87 matt@harrison.dom
     Luke Skywader 32 luke@skywader.dom
     adam Landwalker 104 beth@landwalker.dom
     Adam Beachcomber 29 adam@bc.dom
]
    
sort/skip names 5
    
foreach [first-name last-name age email ] names [
     print [first-name last-name age email ]
]
    
    
size 1 :-
adam Adam Beachcomber Evie
Harrison Jordan Landwalker Luke
Matt Skywader 29 32
43 87 104 adam@bc.dom
beth@landwalker.dom eve@jordan.dom luke@skywader.dom matt@harrison.dom
    
size 2 :
adam Landwalker Adam Beachcomber
Evie Jordan Luke Skywader
Matt Harrison 29 adam@bc.dom
32 luke@skywader.dom 43 eve@jordan.dom
87 matt@harrison.dom 104 beth@landwalker.dom
    
size 3 :
** Script Error: Invalid argument: 3
** Near: sort/skip names 3
foreach [first-name last-name age email]
>>
    
    
size 4 :
adam Landwalker 104 beth@landwalker.dom
Adam Beachcomber 29 adam@bc.dom
Evie Jordan 43 eve@jordan.dom
Luke Skywader 32 luke@skywader.dom
Matt Harrison 87 matt@harrison.dom
    
size 5 :
Evie Jordan 43 eve@jordan.dom
Matt Harrison 87 matt@harrison.dom
Luke Skywader 32 luke@skywader.dom
adam Landwalker 104 beth@landwalker.dom
Adam Beachcomber 29 adam@bc.dom

posted by:   sort/skip       7-Sep-2017/19:47:46-7:00



/skip groups values into 'columns'. This example groups and sorts the values by every 2 items, so each pair of integer and string is sorted according to the integer value:
    
x: [11 "wer" 32 "rte" 23 "erw"]
sort/skip x 2

posted by:   Nick       8-Sep-2017/8:04:17-7:00



If you really want to sort columns, learn to use sort/compare - it gives you the option to sort by any column (not just the first in a group):
    
asc: 1 repeat i 999 [repend/only x:[] [i random now random "abc"]]
srt: func [c] [
    sort/compare x func [a b] [(at a c) < (at b c)]
    if asc: not asc [reverse x]
]
srt 1 editor x
srt 1 editor x
srt 2 editor x
srt 2 editor x
srt 3 editor x
srt 3 editor x
    
I adjusted the code above from my grid examples at http://re-bol.com/shorter_examples.r :
    
s: 0 asc: 1 repeat i 999 [repend/only x:[] [i random now random "abc"]]
edit: func [f] [f/text: request-text/default f/text show l]
srt: func [c] [sort/compare x func [a b] [(at a c)< at b c]
    if asc: not asc [reverse x] show l]
view g: layout [
    style t text 91x24 edge [size: 2x2][edit face] across space 0x0
    h4 "ID" 55 [srt 1] h4 "Date" 200 [srt 2] h4 "Text" [srt 3] return
    l: list 350x412 [across space 0x0 info 55 tan info t] supply [
     face/text: either e: pick x count: count + s [e/:index] [none]
    ] sl: slider 20x412 [s: value * length? x show l] return
    btn "Add"[y: maximum-of x repend/only x[1 + y/1/1 random now cp""]show l]
    btn "Delete" [r: do request-text/title"#" remove-each i x[i/1 = r]show l]
    btn "Find"[u: cp[] h: request-text foreach i x[if find v: form i h[append
     u v]] if not f: request-list""u[exit]s:(do first parse f"")- 1 show l]
    btn "Save" [attempt [save request-file/only/save/file %x.txt x]]
    btn "Load" [attempt [x: load request-file/only/file %x.txt show l]]
    btn "Sum" [sm: 0 foreach i x [sm: sm + i/1] notify form sm]
    btn "Avrg" [sm: 0 foreach i x [sm: sm + i/1] notify form sm / length? x]
    btn "Max" [foreach i x [append y:[] i/1] notify form first maximum-of y]
    key keycode [down] [sl/data: (s: s + 10)/ length? x show g]
]

posted by:   Nick       8-Sep-2017/8:15:13-7:00



In that example, click the column headers to sort by any column (alternately ascending/descending).
    
It's probably better for me to link to http://personal-programming.com (includes descriptions of all the features in each app example). This is example http://personal-programming.com/personal-programming.html#section-3.28

posted by:   Nick       8-Sep-2017/8:21:35-7:00



I am totally with you in not understanding AT ALL the "sort" documentation on the REBOL web site, but after your question and Nick's answer I stared at it a bit and came up with the following.    
    
I modified your data to be a block of blocks, with each block being a "record" representing a person. I also changed the data types of the names to strings because that seemed logical. Then I tried a sort using the second field of the record for comparison, because normally one sorts on the last name. Then I made my best guess at how to use the "compare" refinement and came up with the following script, which produces the following results.
    
R E B O L []
    
names: [
     ["Evie" "Jordan" 43 eve@jordan.dom]
     ["Matt" "Harrison" 87 matt@harrison.dom]
     ["Luke" "Skywader" 32 luke@skywader.dom]
     ["adam" "Landwalker" 104 beth@landwalker.dom]
     ["Adam" "Beachcomber" 29 adam@bc.dom]
]
    
print "----------- before ----------------"
foreach rec names [
     probe rec
]
    
sort/compare names func [rec1 rec2] [rec1/2 < rec2/2]
    
print "----------- after -----------------"
    
foreach rec names [
     probe rec
]
    
halt
    
----------- before ----------------
["Evie" "Jordan" 43 eve@jordan.dom]
["Matt" "Harrison" 87 matt@harrison.dom]
["Luke" "Skywader" 32 luke@skywader.dom]
["adam" "Landwalker" 104 beth@landwalker.dom]
["Adam" "Beachcomber" 29 adam@bc.dom]
----------- after -----------------
["Adam" "Beachcomber" 29 adam@bc.dom]
["Matt" "Harrison" 87 matt@harrison.dom]
["Evie" "Jordan" 43 eve@jordan.dom]
["adam" "Landwalker" 104 beth@landwalker.dom]
["Luke" "Skywader" 32 luke@skywader.dom]
    


posted by:   Steven White       8-Sep-2017/9:56:01-7:00



thanks Nick/Steven for your explanation.
I am starting with the sort/skip first then will progress to /compare later on.
Let me try some more to see if I get it or not.
    
to give you the context. what I was trying to do was read a text file with data that is space delimited and sort them of the first column.
    
My approach was to use a block of record stored in a variable to experiment with/learn the SORT function, then once I get to understand how it works, then do a myLines: read/lines on the file and use sort/skip myLines to sort the file, and then write it out to another file. the reason I was using read/lines is that from the doc, it says it reads into a block.
    
    
this is the reason in my block, there is no " ", it's in the foll format :-
    
Name lastname age emailaddress
Evie Jordan    10 evie@jordan.dom    
Matt Harrison 87 matt@harrison.dom


posted by:   sort/skip       8-Sep-2017/20:17:40-7:00



http://business-programming.com/business_programming.html#section-2.10

posted by:   Nick       10-Sep-2017/9:34:47-7:00



thanks Nick, will go through the link provided.
    
I think I understand the sort/skip better now. the one thing I did observe is that it has some problem handling some alphanumeric column that also contains "-". unless I enclose the alphanumeric between " ".
    
the problem is, in real life, a lot of files come in with columns without quotes. so having to manipulate the data and adding quotes, adds extra time to the processing. we are talking of files that have 500,000 to 600,000 lines. so it would have been good to not have to massage the data, and for sort to be able to distinguish the different types of data on the fly.

posted by:   SORT/SKIP       12-Sep-2017/21:47:38-7:00



In case you missed the one key line in Nick's examples, you don't have to use read/lines to bring in the data; you can load it with one line of code. Then you can sort it with one more. It would be interesting to know if this works with half a million lines. As I understand it, this would allow only for sorting on the first name. I you would want to sort on the last name, you would have to massage, unless you can get the source of the data to provide it in a better form.
    
R E B O L []
    
names-data: {
        "Evie" "Jordan" 43 eve@jordan.dom    
        "Matt" "Harrison" 87 matt@harrison.dom    
        "Luke" "Skywader" 32 luke@skywader.dom    
        "adam" "Landwalker" 104 beth@landwalker.dom    
        "Adam" "Beachcomber" 29 adam@bc.dom    
}
write %testnames.txt names-data
names: load %testnames.txt
print ["names is of type " type? names ", length " length? names]
    
print "----------- before ----------------"
foreach [firstname lastname age email] names [
     print rejoin [
         mold firstname " "
         mold lastname " "
         mold age " "
         mold email
     ]
]
    
sort/skip names 4    
    
print "----------- after -----------------"
foreach [firstname lastname age email] names [
     print rejoin [
         mold firstname " "
         mold lastname " "
         mold age " "
         mold email
     ]
]
    
halt
    
    


posted by:   Steven White       13-Sep-2017/15:23:11-7:00



This example generates a data file with 600,000 lines of 10 values on each line (6 million values). Massaging *every single* one of those values into a data type takes about 10-20 seconds total, depending on machine. That's not a problem for things like internal reports. Depending on your data, a pure 'parse solution may be possible, and likely many times faster (parse is typically very fast - notice that the simple parse operation in this example (separating all 6 million values) takes about 1/10 the time of the foreach loop). If you need more speed, you could write the bottleneck part of the routine in C, and import it in Rebol as a DLL function. That's a typical solution employed by most traditional scripting languages.
    
I expect that massaging such a volume of raw data values into date, time, and other sorts of structured objects would likely take a similar amount of processing time in most scripting languages, and the solution of using a C library would likely be the prescribed solution for greater speed. Any way you cut it, using a single core, it's going to take at least a moment to parse and process millions of raw data values. If you need faster speed, take a look at Julia (see the petaflop news they made recently).
    
R E B O L []
print "starting..."
x: copy [] repeat i 600000 [repend x [
    i (i + 1) random 9999 random "asdfghjklzxcvbnm" random now
    random 99999 random 9:00pm '- random "ghuu66-jiyggg" 99999
]]
print delta-time [write %testdata form x]
print delta-time [y: read %testdata]
print delta-time [z: parse y none]
print delta-time [
    foreach [a b c d e f g h i j] z [
     repend t:[] [
        to-integer a to-integer b to-integer c form d to-date e
        to-integer f to-time g form h form i to-integer j
     ]
    ]
]
halt

posted by:   Nick       13-Sep-2017/21:40:42-7:00



thanks Nick/Steven -
    
I did finally used something similar to the following :
    
myContents: to-block read %file.txt
mySortedText: sort/skip myContents 4
    
the 2 steps above did not take long even with the 500000 to 600000 lines in the file.
    
however my problem was that when I did
    
write/lines/append %out.txt mySortedContents or write/append %out.txt mySortedContents
    
it put everything on one line, it did not create 500,000-600,000 lines. by the way this operation went fast too in a few seconds.
    
so I had to actually use a    
    
foreach [ col1 col2 col3 col4] mySortedContents to loop through each line and add a LF and then write each line to %out.txt file. this took a loooong time mover 1.5 hour.
    
not sure why the foreach loop took so much time to write the 500K-600K lines to the file.
    
I don't believe it is the disk speed otherwise the first write did take a few seconds, however did not write each line separately from the previous line.
    
write/lines/append %out.txt mySortedContents or write/append %out.txt mySortedContents
    


posted by:   sort/skip       16-Sep-2017/8:48:05-7:00



correction to my previous comment :-
I don't believe it is the disk speed that is the problem as the first write/lines/append or write/append did take a few seconds only, however it did not write each line separately from the previous line. everything was written on one line.

posted by:   sort/skip       16-Sep-2017/8:52:02-7:00



For 1.5 hours of processing to occur, there must be some repeating internal loop causing trillions of unintentional iterations. Simply adding 600,000 carriage returns to a string of text in memory generally takes less than a second on almost any machine.
    
If you're saving structured data, there's no reason to need a line terminator to delineate records (it's a useful simple hack for simply structured records, but not really the best option). Either structuring the data into consistent rows and columns of values, or grouping records into separate blocks, is all that's needed. To append new records to a file, you can use write/append, or append the new records to the data in memory, and then save the whole block to the file. Even if you save the entire database often, a complete save process should take 1-2 seconds for the volume of data you're processing. The only time you should need to use read/lines is if you're reading in some data from a foreign source, the formatting of which you don't control. Once you've converted everything into a block of Rebol data, you can do this (using your block and file name above):
    
save %out.txt mySortedContents
    
To load it all back in:
    
mySortedContents: load %out.txt
    


posted by:   Nick       16-Sep-2017/9:55:35-7:00



BTW, If you want to write/append individual records to a 'save(d) block (without having to load and re-save the entire block) you can use 'mold:
    
x: [[2123 213][5453 653]]
save %x x
y: [234]
write/append %x mold y
editor %x

posted by:   Nick       16-Sep-2017/10:02:18-7:00



And also, BTW, if you really wanted, you could even do something similar if you aren't saving blocks of blocks (i.e., just a 'flat' block of consecutive values meant to be treated as rows and columns):
    
z: copy ["awdf" 23 "5tr4e"]
write/append %z copy/part at mold z 2 ((length? mold z) - 2)
editor %z

posted by:   Nick       16-Sep-2017/10:11:43-7:00



thanks Nick.
    
The sort function seems to have a bug.
    
my tosort.txt file has these 6 lines. evie jordan on line 1 of my tosort.txt file
    
Evie Jordan 43 eve@jordan.dom
Matt Harrison 87 matt@harrison.dom
Luke Skywader 32 luke@skywader.dom
adam Landwalker 104 beth@landwalker.dom
Adam Beachcomber 29 adam@bc.dom
    
    
when i sort and do a probe, this what I see :-
    
[
     adam Landwalker 104 beth@landwalker.dom
     Adam Beachcomber 29 adam@bc.dom Evie Jordan 49 eve@jordan.dom
     Evie Jordan 43 eve@jordan.dom
     Luke Skywader 32 luke@skywader.dom
     Matt Harrison 87 matt@harrison.dom
]
    
you see evie, is attached to adam beachcomber line.
    
this what i see in my aftersort.txt file:-
"empty line"
adam Landwalker 104 beth@landwalker.dom
Adam Beachcomber 29 adam@bc.dom Evie Jordan 49 eve@jordan.dom
Evie Jordan 43 eve@jordan.dom
Luke Skywader 32 luke@skywader.dom
Matt Harrison 87 matt@harrison.dom
    
    
    
this is the rebol script I use:-
names: load %tosort.txt
ww: sort/skip names 4
probe ww
save %aftersort.txt ww
    
    
the language seems to have a quirky behaviour.

posted by:   sort/skip       17-Sep-2017/10:44-7:00



thanks Nick you have been very helpful as well as Steven.
    
what I was expecting if i use this in my input file:-
Evie Jordan 43 eve@jordan.dom
Matt Harrison 87 matt@harrison.dom
Luke Skywader 32 luke@skywader.dom
adam Landwalker 104 beth@landwalker.dom
Adam Beachcomber 29 adam@bc.dom
    
to get this in my output file:-
adam Landwalker 104 beth@landwalker.dom
Adam Beachcomber 29 adam@bc.dom
Evie Jordan 49 eve@jordan.dom
Evie Jordan 43 eve@jordan.dom
Luke Skywader 32 luke@skywader.dom
Matt Harrison 87 matt@harrison.dom
    
and Not this
"empty line"
adam Landwalker 104 beth@landwalker.dom
Adam Beachcomber 29 adam@bc.dom Evie Jordan 49 eve@jordan.dom
Evie Jordan 43 eve@jordan.dom
Luke Skywader 32 luke@skywader.dom
Matt Harrison 87 matt@harrison.dom
    
it did the same when using a "to-block read tosort.txt" which I was using at first. when I tried the load %tosort.txt, it gives the same result.
    
the thing is because of this quirk, now it looks like we are forced to go through the result to separate the evie from adam beachcomber. Of course here I am just using evie , adam as an example, this is not my actual data at work, which i cannot use here for this example.
    
    


posted by:   sort/skip continued       17-Sep-2017/10:58:19-7:00



If you're just sorting the lines by the first characters, and writing back to a file:
    
write/lines %aftersort.txt sort read/lines %tosort.txt
    
If you're importing the data for use as a Rebol data structure (which can be manipulated easily using Rebol series operations - i.e., I would do this for any significant data processing beyond a simple script):
    
editor x: sort/skip parse read %tosort.txt none 4
    
I did this with http://re-bol.com/tosort.txt

posted by:   Nick       17-Sep-2017/17:26:55-7:00



thanks again Nick.
    
I already know how to sort a file using windows sort command at the command prompt, It is one liner and we just use the pipe and redirection, which runs very fast too.
    
I was trying to compare that with using a scripting language like Rebol which i have read from some forum as being very concise and swiss army knife.
    
Also when I use a scripting language, it would allow me to do extra processing on each line of the file, if needed.
    
the only thing , it looks to me like Rebol is not very consistent, whichever way we approach a sort and then saving result to a file (as long as we are using rebol functions), it should yield the same end result. With all the variations i have used, it is not the case.
Maybe it is a bug. unfortunately as version 2.7.8.3.1 is no longer being supported and the creator is no longer around, we will never know, why it is behaving weird. I may try it using Red. since Red is still being developed, I am sure I will get an explanation there.
    
    
by the way my tosort.txt is like this. I missed one evie line in my earlier comments above. just saying that so that people are not confused as to why there are 2 evie in the output and one evie in the input.
Evie Jordan 43 eve@jordan.dom
Matt Harrison 87 matt@harrison.dom
Luke Skywader 32 luke@skywader.dom
adam Landwalker 104 beth@landwalker.dom
Adam Beachcomber 29 adam@bc.dom
Evie Jordan 49 eve@jordan.dom
    
    


posted by:   sort/skip       17-Sep-2017/22:04:48-7:00



There is no bug, and the performance of each script I've posted is 100% consistent, using the data that has been posted:
    
write/lines %aftersort.txt sort read/lines %tosort.txt
editor %aftersort.txt
    
The tosort.txt file that I used above is the example data you posted, and can be downloaded from re-bol.com/tosort.txt
    
It IS POSSIBLE to recreate the type of unexpected output you received above, by manually editing the example data and mixing CR/LF ending types. If you did that unknowingly during the edit process (I actually did that during a manual copy/paste/edit in which I was examining and manipulating the line endings of your data), or if that condition appears otherwise in your dataset, then it's not an inconsistency with the way Rebol (or any language/tool) has handled the data, it's an inconsistency in the data itself. Unfortunately, that's one of the hassles inherent in coding - the computer will do *exactly* what you instruct it to do, and if you're not aware of the specification of a function, or the properties of a given data set, then you'll get output which is different from your assumption.
    
Although the example above is working correctly with the data you provided, it's possible that on another OS, or with a data set in which line endings are handled differently (that's one thing which happens in the current state of computing, which can produce unexpected, although technically correct results), you may have to explicitly provide finer grained control of the data manipulation. In this case, as I suggested, you may want to use 'parse, instead of relying on the default behaviors of read/lines and write/lines (and definitely don't use 'save to produce an text output file other than that which is intended to be read by the Rebol 'load function). The more explicit control you provide, the better your outcome will be - and Rebol provides beautiful, concise (and 100% consistent) means of achieving the goals you want:
    
x: sort/skip parse read http://re-bol.com/tosort.txt none 4
foreach [a b c d] x [append y:"" rejoin [a " " b " " c " " d newline]]
write %aftersort.txt y
editor %aftersort.txt
    
Also, be aware that you can use sort/skip/case if you want to control the sort process according to uppercase/lowercase rules.
    
If the Windows sort you tried worked in this case the way you anticipated, it simply means that it was configured the way you assumed/needed it to work, with the input data - but in a case in which that assumption was incorrect or the data contained unexpected exceptions, you would get unanticipated output, and unless that particular sort function provides the fine grained control to handle every possibility, and you have the knowledge and experience to anticipate every condition, the computer will do exactly what you tell it, and potentially provide unexpected results. This is the case with EVERY current programming tool in existence (as AI techniques improve, that state will likely change). Rebol provides a wide variety of tools to handle data, in ways which are both simple and fine grained. As with any other tool, you just need to discover what those tools are, and how to use them.

posted by:   Nick       18-Sep-2017/7:32:49-7:00



BTW, clearly, the data you posted IS NOT exactly what you processed (it didn't even contain one of the lines of data, let alone the exact line feeds you were processing), and the detail which caused your unexpected result is in that inconsistency - it's not a 'bug' in the Rebol sort function.

posted by:   Nick       18-Sep-2017/7:52:17-7:00



I just noticed that you were using this in one of your examples:
    
myContents: to-block read %file.txt
    
That creates a block of words, as opposed to a parsable string, or a block of strings. Don't do that if you want to sort strings :)

posted by:   Nick       18-Sep-2017/8:19:04-7:00



That last point is perhaps the most important message to 'get' in this entire discussion. Basically, all data structures in Rebol are meant to be dealt with as series (or, at least, they can be manipulated using the same functions which interact with series (i.e., when dealing with data in ports - the data in the ports are dealt with using series functions, but that foreign data may not be a native Rebol series)). A string is just a series of characters. Both the 'load and the 'to-block functions which you used above, create a series of values, each with a given data type, as opposed to a series (block) containing individual string values, or even a single string series. Take a look at this:
    
x: load %tosort.txt
== [Evie Jordan 43 eve@jordan.dom
     Matt Harrison 87 matt@harrison.dom
     Luke Skywader 32 luke@skywader.dom
     adam Landwal...
>> type? x/1
== word!
>> type? x/4
== email!
    
So, you should use 'load when you're loading a file which contains a structure of Rebol data values (typically a data structure which was created with Rebol's 'save function). This isn't an unexpected 'quirk' - it's just a useful function which does what it's supposed to do when loading saved Rebol data, made to work with existing data types (and data types are one thing which plays a big role in making Rebol so productive).
    
Take a look at the following example. By doing this, you're setting 'x to a string value (series):
    
x: read %tosort.txt
    
== {Evie Jordan 43 eve@jordan.dom
Matt Harrison 87 matt@harrison.dom
Luke Skywader 32 luke@skywader.dom
adam Landwalker 104 beth...
    
Notice that this is a big single string value (which can be dealt with as a series of character values, shown by enclosing curly braces). You can separate that string into a series of individual string values, using the 'parse function:
    
y: parse x none
    
== ["Evie" "Jordan" "43" "eve@jordan.dom" "Matt" "Harrison" "87"
"matt@harrison.dom" "Luke" "Skywader" "32" "luke@skywader.dom" "a
d...
    
Note that the result of the 'parse function is a block (series) of separate string values. 'Parse is an incredibly powerful function, encompassing an entire deeply powerful dialect, which can be used to parse text in ways which are just as complex as regular expressions (but using much more readable code, and often with greater performance than regex).
    
That block of text values can now be sorted with the 'sort function, using any of it's refinements (/skip, /compare, /case, /etc.). Note that you can perform "massaging" of the data during the parse operation, if for example, you want it to output a block (series) containing email addresses, times, dates, money, and/or any other type of valid Rebol data types. That's perhaps one of the most important and powerful things to learn, if you want to do processing of raw data which comes from foreign data sources. Many people use Rebol just for the power of the 'parse dialect.
    
I think that just understanding the basics of how data types, series, strings, etc. are used to represent data in Rebol is a quick thing to learn, but often leads to a great deal of confusion. That whole system, and tools such as 'parse, which are built into the fabric of Rebol, are a big part of what makes the whole Rebol environment so productive. If you miss those basics, though, it can be incredibly confusing.

posted by:   Nick       18-Sep-2017/10:33:49-7:00



The tl;dr here is learn how Rebol series work (especially how to handle strings), and learn how to use the functions which save, load, and manipulate series: read, write, save, load, parse, to-<type>, etc. (and all the refinements of those functions, such as read/lines). That's where the confusion came from in this entire topic, and this confusion, which is easy to remedy, seems to be the most common initial barrier for new users of Rebol.
    
I hope that helps (BTW, you'll run into all the same approach if you look at Red).

posted by:   Nick       18-Sep-2017/11:00:54-7:00



There's a lot in this thread, so I want to be sure to point out this example - it serves as a useful basic model to provide potentially fine grained control over input, processing, and output (remember that the 'sort function with its refinements and 'parse function dialect are capable of handling virtually any level of complexity and intended control):
    
x: sort/skip parse read http://re-bol.com/tosort.txt none 4
foreach [a b c d] x [append y:"" rejoin [a " " b " " c " " d newline]]
write %aftersort.txt y

posted by:   Nick       18-Sep-2017/13:37:22-7:00



And this is the basic 1-liner that you can use to sort lines in a text file (note that read/lines creates a block of string values (1 string value for each line)):
    
write/lines %aftersort.txt sort read/lines %tosort.txt

posted by:   Nick       18-Sep-2017/13:39:43-7:00



Thanks NIck. You have been very helpful. Will try it again this week end.
will also need to go through the series/block chapters in the rebol core manual again. It looks like i did not get everything right when I went through.
    
is there a difference between    
    
[ sam curtis england ali pretzel france ]
    
and    
    
[ sam curtis england
    ali pretzel france ]
        
    
I was thinking that they were the same.

posted by:   sort/skip       20-Sep-2017/9:33:01-7:00



Those ARE the same. White space doesn't make any difference:
    
>> x: [ sam curtis england ali pretzel france ]
== [sam curtis england ali pretzel france]
>> y: [ sam curtis england
[        ali pretzel france ]
== [sam curtis england
     ali pretzel france
]
>> x = y
== true
    
What's not the same:
    
>> z: ["sam" "curtis" "england" "ali" "pretzel" "france" ]
== ["sam" "curtis" "england" "ali" "pretzel" "france"]
>> x = z
== false
    
>> type? x/1
== word!
>> type? z/1
== string!

posted by:   Nick       20-Sep-2017/22:00:51-7:00



Name:


Message:


Type the reverse of this captcha text: "h c a t t a"



Home