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

World: r3wp

[Core] Discuss core issues

BrianH
15-Aug-2009
[14456]
JOIN takes 2 parameters, REJOIN just takes one, and is slightly slower 
because it has to retrieve the first parameter from what would be 
the second parameter of JOIN.
Graham
15-Aug-2009
[14457]
A different outcome.
Sunanda
15-Aug-2009
[14458]
Looks like a bug to me, Graham.
Graham
15-Aug-2009
[14459x2]
Opinions?
Looks like a bug to me too.
Sunanda
15-Aug-2009
[14461]
R2 work around?
    to-string rejoin [#{} "hello" #{}]
    == "hello"
Graham
15-Aug-2009
[14462x3]
not for me .. thanks!
I was constructing a payload for a http post, and need a combination 
of string and binary data.  I used rejoin... and got an unexpected 
outcome.
So, I guess I'll just have to use repeated appends instead to build 
the payload.
BrianH
15-Aug-2009
[14465x2]
ajoin: funco [
	"Reduces and joins a block of values into a new string."
	[throw]
	block [block!]
][
	make string! reduce block
]

Faster than JOIN or REJOIN.
Sorry about the funco, I copied that from R2/Forward.
Graham
15-Aug-2009
[14467]
let me guess .. part of your rebol3 backport ??
BrianH
15-Aug-2009
[14468]
Of course.
Graham
15-Aug-2009
[14469x2]
does it build a series without corrupting binary data ??
perhaps i need 'bjoin :)
BrianH
15-Aug-2009
[14471]
Yes. The mezzanine is faster than the native version, but the native 
doesn't have the intermediate block overhead.
Graham
15-Aug-2009
[14472x2]
Where is it?
'funco i.e.
BrianH
15-Aug-2009
[14474]
It's just another name for FUNC (where FUNC is redefined in R2/Forward).
Graham
15-Aug-2009
[14475x2]
ask-brian: funco [ ask-brian ]
oops... missing the second block!
BrianH
15-Aug-2009
[14477]
Just use FUNC :)
Graham
15-Aug-2009
[14478x3]
Nope... seems to give the same problems as rejoin
ajoin: func [[throw!] block [block!]][make string! reduce block]
>> ajoin [ "hello" make binary! 1 ]
== "hello#{}"
apologies .. Sunanda's workround works  viz to-string rejoin [ #{} 
.... ]
Ashley
15-Aug-2009
[14481]
Wow, that make string! change to join/rejoin yields about a 300% 
speed increase! Definiately one to backport to R2.
Graham
15-Aug-2009
[14482]
doesn't help with 'ajoin though ... need to coerce to binary first
Sunanda
15-Aug-2009
[14483]
Graham -- glad the workaround  works.
But it is R2 only. R3 has other problems.
Graham
15-Aug-2009
[14484]
not too fast .. it exhibits different behaviours
Ashley
15-Aug-2009
[14485]
Just needs a bit of datatype coercing added.
Graham
15-Aug-2009
[14486x4]
this has always got me
 rejoin [ <text> "hello" </text> ]
== <texthello</text>>
rejoin [ "" <text> "hello" </text> ]
== "<text>hello</text>"
which is I guess one should use 'reform when constructing strings 
for web output.
this fix allows me to upload a binary document using the googleapi 
.. eg. docx
Ashley
15-Aug-2009
[14490]
First cut QAD on join/rejoin, still about twice as fast the originals:

	join: make function! [
		"Concatenates values."
		value "Base value"
		rest "Value or block of values"
	][
		either series? value [
			make type? value reduce [value rest]
		][
			make string! reduce [value rest]
		]
	]


	rejoin: make function! [
		"Reduces and joins a block of values."
		block [block!] "Values to reduce and join"
	][
		either empty? block: reduce block [block] [

   make either series? first block [type? first block] [string!] block
		]

	]
Graham
15-Aug-2009
[14491]
try rejoin with using #{} as the first element!
BrianH
15-Aug-2009
[14492]
Ashley, that JOIN doesn't work for block types. It should be:
>> join [a b] [1 2]
== [a b 1 2]
Yours returns  [[a b] [1 2]]]
Graham
15-Aug-2009
[14493x4]
Anyone can tell me why my googledocs object won't clone?

http://rebol.wik.is/Googledocs

gdoc: make object! googledocs []
** Script Error: Invalid argument: object
** Near: gdoc: make object! googledocs []
crap
still asleep ...
ignore
Graham
17-Aug-2009
[14497]
Has anyone done any work with OAUTH ie. open authentication?
Geomol
19-Aug-2009
[14498x2]
REPEAT is a native. Can it be made as a mezzanine using WHILE? It 
takes 3 arguments:
'word value body


The first is seen as a lit-word by the function. This should be bound 
to body and only be used as a local variable in the function context. 
My first attemp to make a REPEAT mezzanine didn't go well:

my-repeat: func [
	'word value body
][
	bind/copy body word
	word: 0
	while [(word: word + 1) <= value] body
]

>> my-repeat i 10 [print i]
** Script Error: i has no value

Suggestions?
One problem is, that WORD become an integer, when I set it to zero. 
If I write:
set word 0

instead, I create a global variable. I'm wondering, if this can be 
done at all!?
Chris
19-Aug-2009
[14500x2]
my-repeat: func ['w v b][use reduce [w] compose/deep [(to-set-word 
w) 0 while [v >= (to-set-word w) (w) + 1][(b)]]]
(sorry for abbreviations, using small keyboard)
Geomol
20-Aug-2009
[14502x3]
Nice Chris! I expected, it could be done somehow. Do you know, if 
REPEAT was a mezzanine in some of the first versions of REBOL?
Can it be made without COMPOSE?
This version without COMPOSE seems to work:

my-repeat: func [
	'word value body
][
	use reduce [word] reduce [
		to set-word! word 0

  'while reduce ['value to word! ">=" to set-word! word word '+ 1]
			body
	]
]


I'm not quite sure, why it works without using BIND to connect body 
with word?
Ladislav
20-Aug-2009
[14505]
...why it works without using BIND to connect body with word?
 - of course it binds the body, USE takes care of that