r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3-OLD1]

Anton
31-Aug-2006
[1195x2]
How about taking a page from Andrew Martin's book: rename REJOIN 
-> JOINS ? ie.  JOIN joins two arguments, JOINS joins any number 
of arguments.
Or it could also be ENJOIN (N-JOIN).
I think the Francophones would also like ENJOIN.
JaimeVargas
31-Aug-2006
[1197x5]
Why not simply get rid of rejoin and replace for the more useful 
DELIMIT?
delimit [1 2 3] ;== "123"
delimit/with [1 2 3] "," ;== "1,2,3"
delimit/quoted 
[1 2 3] ;== {"1","2","3"}
delimit/quoted/with [1 2 3] "|" ;== {"1"|"2"|"3"}

npa: 
703
nxx: 938
delimit [npa nxx] ;== "npa nxx"
delimit/reduce [npa 
nxx] ;= "703938"
delimit/reduce/with [npa nxx] "-" ;== "703-938"
delimit/reduce/quoted/with 
[npa nxx] "|" ;== {"703"|"938"}
Sorry for that it drives me nuts that Altme in OSX doesn't preserve 
newlines.
;; usage examples

delimit [1 2 3] ;== "123"
delimit/with [1 2 3] "," ;== "1,2,3"
delimit/quoted [1 2 3] ;== {"1","2","3"}
delimit/quoted/with [1 2 3] "|" ;== {"1"|"2"|"3"}

npa: 703
nxx: 938
delimit [npa nxx] ;== "npa nxx"
delimit/reduce [npa nxx] ;= "703938"
delimit/reduce/with [npa nxx] "-" ;== "703-938"
delimit/reduce/quoted/with [npa nxx] "|" ;== {"703"|"938"}
;; Here is my implementation, maybe in can be fine tuned.


delimit: func [data [block!] /reduce /quoted /with separator  [string! 
char!]  /local result quote][
  unless empty? data [
    result: copy {}
    unless with [separator: ""]
    quote: either quoted [
        func[x][rejoin [{"} x {"}]]
    ][
        func[x][x]
    ]

    insert result quote form either reduce [do first data][first data]
    foreach value next data [

    insert insert tail result separator quote form either reduce [do 
    value][value]
    ]
    result
  ]
]
Anton
31-Aug-2006
[1202]
It looks like a very fine function - *except* I would name it differently 
(I prefer GLUE).
JaimeVargas
31-Aug-2006
[1203]
I think the form use to produce the  reduce effect is incorrect. 
Most probablay it needs to written using DO/NEXT.
Anton
31-Aug-2006
[1204x2]
Lots of English candidate words suffer because they don't imply copy, 
whereas in rebol this is important and it would be nice to distinguish 
between when we are copying and when we are not.
I think you are right. FOREACH is stepping through each value of 
the block unevaluated, then, expecting to be able to evaluate it 
successfully. But what if it is a function expecting arguments ?
JaimeVargas
31-Aug-2006
[1206x2]
;; New version does proper reduction


delimit: func [data [block!] /reduce /quoted /with separator  [string! 
char!]  /local result quote][
  if reduce [data: system/words/reduce data]
  unless empty? data [
    result: copy {}
    unless with [separator: ""]
    quote: either quoted [
        func[x][rejoin [{"} x {"}]]
    ][
        func[x][x]
    ]
    insert result quote form first data
    foreach value next data [
      insert insert tail result separator quote form value
    ]
    result
  ]
]
;; example

>> delimit/reduce/with [npa nxx square-root 4] " "  ;== "703 938 
2.0"
Anton
31-Aug-2006
[1208]
Note, if this is going to be Rebol3, then you should be able to use 
APPEND instead of INSERT TAIL without penalty.
JaimeVargas
31-Aug-2006
[1209x6]
Now we need a good name. I am not sure about glue. How about CONCAT
Another one is CHAIN
concatenate: 
verb [ trans. ] formal or technical 
link (things) 
together in a chain or series : some words may be concatenated, such 
that certain sounds are omitted.
Another optin is LINK
To summarize  we have: REJOIN, GLUE, CONCAT, CONCATENATE, CHAIN, 
LINK.
And DELIMIT
Henrik
31-Aug-2006
[1215x3]
'link? is already used, so it might be interpreted as 'link is somehow 
... linked to 'link? :-)
interpreted as if 'link is
weld?
Anton
31-Aug-2006
[1218]
Just looking at the Thesaurus:
http://thesaurus.reference.com/search?q=join&x=0&y=0
Some nice words:

adhere, affix, (agglutinate), cement, conjoin, fasten, fuse, leash, 
marry, wed, weld.
JaimeVargas
31-Aug-2006
[1219]
Do you want the added functionality of the DELIMIT above?
Henrik
31-Aug-2006
[1220]
jaime, yes that would be very nice
Anton
31-Aug-2006
[1221x3]
conjoin is cool, language root are like "delimit/with"
Ah yes, Jaime, I wanted to say "DELIMIT" lies to you when it is used 
without the /WITH refinement, because DELIMIT implies delimiters. 
If there aren't any delimiters, then it is lying.
So an idea I would like to explore is to split the functionality 
of DELIMIT into perhaps two functions. As this kind of operation 
is very common, I suggest that this will save lots of typing.
JaimeVargas
31-Aug-2006
[1224x2]
How will you split it.
The description I have for DELIMIT is "Returns a string! constructed 
from the chained values in the block."
Anton
31-Aug-2006
[1226]
Must think about that.
JaimeVargas
31-Aug-2006
[1227x2]
I should not that I am not attached to DELIMIT. It stated like with 
a different purpose, but now I see that is more generic than REJOIN. 
So I offer it after modifying it a bit.
I like the CONJOIN word.
Anton
31-Aug-2006
[1229]
Currently we use REJOIN for most things, and sometimes we miss being 
able to add delimiters, after that, the next functionality is probably 
the quoting.
JaimeVargas
31-Aug-2006
[1230x2]
But CONJOIN is not very common. I thinkn CONCAT will be more mnemonic 
for newbies.
Picking names is very hard. I kind of like to have all the functionality 
cram in one function, less words to remember. So I left the naming 
decision to the community, just hope the features of delimit are 
include in R3.
Anton
31-Aug-2006
[1232x2]
So I would drop the /WITH refinement and make it implicit in a DELIMIT 
or CONJOIN function... (maybe..)

1) rejoin/quoted [...]   ; <-- this is most similar to rejoin, or 
delimit without the /WITH

2) conjoin/quoted "," [...]    ; <-- this is like delimit/with/quoted 
 (and the non-optional "with" argument is specified first)
I dislike CONCAT because it is an abbreviation.
JaimeVargas
31-Aug-2006
[1234x2]
me too, but a lot of people knows it.
I am not sure I follow your points.
Anton
31-Aug-2006
[1236]
The first function, REJOIN, is like the current rebol REJOIN, except 
it now has your /QUOTED refinement.
JaimeVargas
31-Aug-2006
[1237]
I don't really see the reason for splitting features of the function.
Anton
31-Aug-2006
[1238]
The second function, CONJOIN, is like your DELIMIT, except with WITH 
refinement implicit.
JaimeVargas
31-Aug-2006
[1239]
I think is better to keep Rebol's lexicon short.
Anton
31-Aug-2006
[1240]
I think the /REDUCE refinement usually isn't needed (I could be wrong), 
because if you are not going to reduce the block then you already 
know what the result is.
JaimeVargas
31-Aug-2006
[1241]
>> delimit [1 1 / 2 ]  ;
== "11/2"

>> delimit/reduce [1 1 / 2]  ;
== "10.5"
Anton
31-Aug-2006
[1242]
I think functions that are used very often with certain combinations 
of refinements ought to be split.
JaimeVargas
31-Aug-2006
[1243]
That can be changed easily.
Anton
31-Aug-2006
[1244]
If we make the right decisions about which functions are important 
enough to have their own word, we free ourselves with clearer code 
etc. Imagine if there was no DO function, but that functionality 
was a refinement of LOAD or REDUCE   --->    We would write REDUCE/DO 
 all the time.