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

World: r3wp

[!REBOL3-OLD1]

JaimeVargas
31-Aug-2006
[1213x2]
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.
JaimeVargas
31-Aug-2006
[1245]
The default behaviour could be to reduce.
Anton
31-Aug-2006
[1246]
That might be an idea. Closer to current rebol behaviour too.
JaimeVargas
31-Aug-2006
[1247]
delimit [1 1 / 2] ;== "10.5"
delimit/literal [1 1 / 2] ;== "11/2"
Anton
31-Aug-2006
[1248x2]
Yes, I think that's better. That refinement is the "weakest" of the 
three.
Please excuse me if I'm a little hazy today. Feeling a bit quantum 
mechanical today.
Tomc
31-Aug-2006
[1250]
I like 'conjoin
Henrik
31-Aug-2006
[1251]
anton, don't go phase into higher dimensions jus yet. :-)
Anton
31-Aug-2006
[1252]
it is ... too late... for me...
Pekr
31-Aug-2006
[1253x2]
but then also think about form vs reform
wasn't there supposed to be kind of formatting dialect at one time? 
IIRC Carl never added it to rebol. Maybe 'form could be used even 
for joining, although its purpose is slightly different.
Oldes
31-Aug-2006
[1255]
I think, there are more important issues than renaming rejoin
Pekr
31-Aug-2006
[1256]
:-)
Anton
31-Aug-2006
[1257]
Well, I agree, but it's worth consideration when taking a break from 
work. Rejoin is pretty close to the core. So if we can improve it, 
that would be great.
Pekr
31-Aug-2006
[1258]
as for us, there are no issues, unless we have something to test 
in our hands .... which seems being slipped to some late fall imo 
....
Anton
31-Aug-2006
[1259]
adjoin: func [
	data [block!] 
	/literal 
	/quoted 
	/local result
][
	unless literal [data: reduce data]
	result: copy {}
	foreach value data compose [
		insert tail result (
			either quoted [
				[rejoin [{"} form value {"}]]
			][
				[form value]
			]
		)
	]
	result
]
; test
adjoin []
adjoin [1 + 2 3 + 4]
adjoin/quoted [1 + 2 3 + 4]
adjoin/literal [1 + 2 3 + 4]
adjoin/literal/quoted [1 + 2 3 + 4]

conjoin: func [
	separator [string! char!] 
	data [block!] 
	/literal 
	/quoted 
	/local result process
][
	unless literal [data: reduce data]
	result: copy {}
	process: func [x] either quoted [
		[rejoin [{"} form x {"}]]
	][
		[form x]
	]
	unless empty? data [
		insert result process first data
	]
	foreach value next data [
		insert insert tail result separator process value
	]
	
	result
]

; this way inlines more code, could be faster
conjoin: func [
	separator [string! char!] 
	data [block!] 
	/literal 
	/quoted 
	/local result process
][
	unless literal [data: reduce data]
	result: copy {}
	process: func [code][
		compose/deep either quoted [
			[rejoin [{"} (code) {"}]]
		][
			[(code)]
		]
	]
	unless empty? data compose [
		insert result (process [first data])
	]
	foreach value next data compose [
		insert insert tail result separator (process [form value])
	]
	result
]

;test
conjoin "," []
conjoin "," [1 + 2 3 + 4]
conjoin/quoted "," [1 + 2 3 + 4]
conjoin/literal "," [1 + 2 3 + 4]
conjoin/literal/quoted "," [1 + 2 3 + 4]
JaimeVargas
31-Aug-2006
[1260x3]
Anton, I really don't see the need for having ADJOIN and CONJOIN. 
There is a lot of code repetition for little gain in expresiveness.
Besides enlarging the lexicon.
Also, your implementation is slower than DELIMIT, by an order of 
magnitude.

>> time-block [conjoin "," []] 0.05  ;
== 4.953515625E-5

>> time-block [delimit/with [] ","] 0.05  ;
== 2.453125E-6