World: r3wp
[!REBOL3-OLD1]
older newer | first last |
Anton 8-Sep-2006 [1381x3] | Yes, but you have to write all the delimiters. |
That's what conjoin allows you to do - compress the common delimiter. | |
(imagine there were 30 options) | |
Volker 8-Sep-2006 [1384x3] | But in this example the delemiter-version is actually shorter. And if i have something really one, i can live with an extra var. I guess i would pull it out of the code anyway. |
So i think its rare and acceptable. While i would use it a lot for printing a result-block nicely delemited. | |
really one -> really long | |
Anton 8-Sep-2006 [1387] | In this example the delimiter was very short and the data block was very short. Such short blocks can usually be processed manually in many different ways, so they are not good examples as is. You have to imagine much longer blocks. |
Volker 8-Sep-2006 [1388x2] | But do such blocks happen often enough? IE more often then using conjoin to format results? I personally think not, but others may code different. |
just conjoin results as CSV and show them in spreadsheet.. | |
Anton 8-Sep-2006 [1390x3] | Maybe it's hard to think of the usages now, but, you know, it took a while to learn when and how to use rejoin. |
How about this, imagine it's HTML code: conjoin/only table-divider reduce [table1 table2 table3] | |
Hmm.... | |
Oldes 8-Sep-2006 [1393x2] | Will be rebocode available in R3? |
(rebcode) | |
Ladislav 8-Sep-2006 [1395] | yes, according to http://www.rebol.com/notes/rebol3roadmap.html |
Oldes 8-Sep-2006 [1396] | Just wanted to remind, that Rebcode was here for a short time:-) Hope it will come back:-) |
Henrik 8-Sep-2006 [1397] | it better come back... |
BrianH 9-Sep-2006 [1398x6] | Anton, good to know the timing. It could have gone either way so it's good to know which is faster. The either method is more compilable too (or translatable to rebcode if you prefer). |
As for the word "delimiter" I made sure it wouldn't be exported to the external programming environment - no keyword arguments in REBOL, and I didn't use it for a function name or refinement. The more precise meaning of the word makes it a better choice for source that may serve as documentation, using the help or source commands. | |
I did understand your point about the /only and /pad-only refinements, but I realized that my delimit function made the change unnecessary, since its behavior was exactly what you were getting at. Using your example: >> delimit ["one" 2 [3]] '| == ["one" | 2 | [3]] | |
The behavior of your conjoin/only isn't really joining, it's more like aggregation. Your preference, I suppose. | |
Keeping the concepts distinct wasn't the only reason I made seperate "conjoin" and "delimit" functions - it's more efficient too. | |
I have switched my functions from pick to either. If you like I will post the changed versions. | |
Anton 10-Sep-2006 [1404x2] | Yes, please. I think I lost sight of the overall picture when I added /only and /pad-only. (Reminds me of a similar thought process in another frenetic function creation a year or two ago (?)) I was not thinking of the functionality that DELIMIT covered when I was "designing" those refinements. So on further reflection, it looks to me like you are right, for CONJOIN, using INSERT rather than INSERT/ONLY on the DATA values is more useful. |
Ok "delimiter" wins. | |
BrianH 10-Sep-2006 [1406x2] | Yeah, that was fun. We should do this more often. Here it is: |
delimit: func [ "Put a value between the values in a series." data [series!] "The series to delimit" delimiter "The value to put into the series" /only "Inserts a series delimiter as a series." /copy "Change a copy of the series instead." /local ] [ while either copy [ if empty? data [return make data 0] local: make data 2 * length? data [ local: insert/only local first data not empty? data: next data ] ] [ local: data [not empty? local: next local] ] either only [ [local: insert/only local delimiter] ] [[local: insert local delimiter]] head local ] conjoin: func [ "Join the values in a block together with a delimiter." data [any-block!] "The values to join" delimiter "The value to put in between the above values" /only "Inserts a series delimiter as a series." /quoted "Puts string values in quotes." /local ] [ if empty? data [return make data 0] local: tail either series? local: first data [copy local] [form :local] while [not empty? data: next data] either any-string? local [ either quoted [ local: insert tail insert head local {"} {"} [local: insert insert insert insert local (delimiter) {"} first data {"}] ] [[local: insert insert local (delimiter) first data]] ] [ either only [ [local: insert insert/only local (delimiter) first data] ] [[local: insert insert local (delimiter) first data]] ] head local ] | |
Tomc 10-Sep-2006 [1408] | consider /delimiter accepting a block that is rotated through. ["|" "|" "|" "|^/"] |
Anton 11-Sep-2006 [1409x2] | You can do this and anything else when passing in a function as delimiter. |
Brian, maybe delimiter needs to be parenthesised in DELIMIT as well ? | |
BrianH 11-Sep-2006 [1411x4] | Tom, you can do that by passing a function as the delimiter, like this: has [x y] [x: ["|" "|" "|" "|^/"] y: first x if tail? x: next x [x: head x]] |
Sorry, missed you saying that Anton. Still, the example should work. | |
You don't need to parenthesise delimiter in delimit because every reference to it is at the end of a block. Using parentheses is slower in REBOL, so why use them when you don't have to? | |
So much for the function working :( x: ["|" "|" "|" "|^/"] has [y] [y: first x if tail? x: next x [x: head x] y] | |
Anton 12-Sep-2006 [1415x5] | Ok, very good |
You could do it this way: | |
d: has [x i][i: [1] i/1: i/1 + 1 pick [a b c] (i/1 - 2 // 3 + 1)] | |
Or like this: | |
d: has [x][x: [[a b c]] x/1: next either tail? x/1 [head x/1][x/1] first back x/1] | |
Tomc 12-Sep-2006 [1420] | I confess I had not read thru what you have been working on (time) I just wanted to be sure it was considered |
Anton 12-Sep-2006 [1421] | fair enough. :) |
Gregg 12-Sep-2006 [1422] | Wow. A lot of thought here. I've skimmed it (trying to catch up on things quickly), and will just post a couple quick thoughts. * REJOIN is probably a good enough name to stick with; I don' t know that any of the others are that much more meaningful in the context of REBOL. * Changing JOIN's params would break a lot of code. * I have a DELIMIT function as well, and like the name. Mine doesn't have /copy or /only refinements (it always uses insert/only), but it has /skip. |
Pekr 12-Sep-2006 [1423] | i did not follow the whole discussion, so dunno what exactly 'delimit does, but could we have also a 'pad function? |
Gregg 12-Sep-2006 [1424] | Yes, that would be nice; PAD, JUSTIFY, and FORMAT are all related needs. |
Anton 13-Sep-2006 [1425x2] | Gregg, I think Brian's last post with DELIMIT and CONJOIN are probably the best in this thread. |
.. and as far as I can tell, we are now not thinking to replace REJOIN with either of those, they would be complementary. | |
Cyphre 14-Sep-2006 [1427] | What about CONCAT? |
Pekr 14-Sep-2006 [1428x2] | concat came to my mind - because, really guys, for me, czech speaking person, conjoin sounds like something rude I even don't know. So concat, I at least know as a term from other languages :-) |
sorry - I don't properly follow the discussion, so I even don't know, what conjoin should do in opposite to join, or rejoin ... I am fine with both old names ... | |
Volker 14-Sep-2006 [1430] | conjoin inserts delemiters too, did i get that right? How about a simple 'list, i feel its a good match, listing things. But not native speaker.. Another idea: it icould be related to csv (this spreadsheet-format, got i the letters right), a conjoin is close to exporting? |
older newer | first last |