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

World: r3wp

[Core] Discuss core issues

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
Geomol
20-Aug-2009
[14506x3]
It does? That's not clear from this example:


>> f: func ['w b] [use reduce [w] reduce [to set-word! w 1 'do 'b]]
>> f i [print i]
** Script Error: i has no value
Changing 'b to b and it works:


>> f: func ['w b] [use reduce [w] reduce [to set-word! w 1 'do b]]
>> f i [print i]
1

(Still a bit confused.)
Is it possible to give a function with a refinement as an argument 
to another function? If I e.g. would make a MAP function in REBOL, 
it could be:


>> map: func [:function list /local result][result: clear [] foreach 
value list [append result function value]
>> map sine [0 15 100]
== [0.0 0.258819045102521 0.984807753012208]


MAP apply the function to each member of the list. But I can't give 
sine/radians to map:

>> map sine/radians [0 15 100]
== 100

Is there a way around this?
Sunanda
20-Aug-2009
[14509]
You could use the MAP syntax that R3 uses (soon to be renamed MAP-EACH)

 map x [0 15 100] [sine/radians x]
== [0.0 0.650287840157117 -0.506365641109759]
Geomol
20-Aug-2009
[14510x2]
It seems to work, if I put DO before function:


map: func [:function list /local result][result: clear [] foreach 
value list [append result do function value]]
It's because, sine/radians is seen as a path! datatype, when the 
argument is defined as :function
Chris
20-Aug-2009
[14512]
G: re. confused - try stepping through the function in the order 
it is interpreted.  Should be clear by the time 'use evaluates the 
two blocks...
Graham
21-Aug-2009
[14513x5]
Anything more efficient than this?



findall: func [s items [block!] /local result][result: copy [] foreach 
i items [repend result [find s i]]]
I want to make sure each item in the block of items occurs in the 
series S
reformatted 

findall: func [s items [block!] 
	/local result
][
	result: copy [] 
	foreach i items [repend result [find s i]]
	all result
]
if the first item is not found, it still searches all the rest which 
is no good
is this something that one can use 'map for?
Geomol
21-Aug-2009
[14518x2]
Using INTERSECT leads to a shorter function, but I'm not sure, it's 
the fastest way:

findall: func [s items [block!]] [items = intersect s items]
Being danish, I'm wondering, if the word INTERSECTION cover the same 
meaning as a JOINT set? If yes, why isn't INTERSECT called JOINT?
Graham
21-Aug-2009
[14520x3]
I guess joint is commonly used for marijuana
>> findall "this is a test string" [ "this" "not here" ]
** Script Error: Expected one of: string! - not: block!
** Where: findall
** Near: items = intersect s items
>>
graham- findall "this is a test string" [ "this" "not here" ]
== none
Geomol
21-Aug-2009
[14523x2]
I guess joint is commonly used for marijuana


LOL, I didn't see that! (And I went to a Reggae festival last week, 
so I should know.) :-)
Do you want your function to find "ring" in this string: "this is 
a test string"?
Graham
21-Aug-2009
[14525]
yes
Sunanda
21-Aug-2009
[14526]
Geomol -- your code works only if the blocks are sorted, and contain 
no duplicates:
     findall [5 4 3 3 2 1] [3 2 1 1]
     == false
One way to fix that:

     findall: func [s items [block!]] [0 = length? exclude items intersect 
     s items]
     findall [5 4 3 3 2 1] [3 2 1 1]
     == true

But it does not help much with Graham's example which is looking 
for substrings :(
Geomol
21-Aug-2009
[14527]
What about this version?


findall: func [s items [block!]] [foreach i items [if not find s 
i [return false]] true]
Graham
21-Aug-2009
[14528x2]
I thought with map you can apply a function over all the parameters 
...
looks good
Geomol
21-Aug-2009
[14530x3]
Yes, you can with map, but you want it to stop, if one item isn't 
found, so not on all parameters.
Chris wrote: "G: re. confused - try stepping through the function 
in the order it is interpreted.  Should be clear by the time 'use 
evaluates the two blocks..."


What I find a bit confusing is, when I have to BIND and when I don't. 
It's the context binding rules in REBOL, that is not 100% clear to 
me. Let me give a simple example:

>> b: [print i]
== [print i]
>> f: has [i] [i: 1 do b]
>> f
** Script Error: i has no value


This doesn't work, because the b block is defined outside the f function, 
outside f's function context. Therefore I have to bind b to f's context, 
like this:

>> f: has [i] [i: 1 bind b 'i do b]
>> f
1


That is clear, and I would expect USE to work by the same rules, 
but it doesn't quite, it seems to me:

>> f: does [use [i] [i: 1 do b]]
>> f
1


By some magic, this works without the need to BIND. I'm a bit confused 
by that.
ARGH! It only works, because I first made the f function using BIND. 
So b was already bound to f, when I changed f to include USE. If 
I try to USE version from a fresh REBOL, it doesn't work. (More confusion!) 
:-p
Anton
21-Aug-2009
[14533x2]
Graham, I think your FINDALL is not well named. Just because it's 
using FIND doesn't mean it's doing the same thing. It should be more 
like COLLECT-ALL or COLLECT-EVERY.
Sorry, I'm wrong. Wrote too quickly.