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

World: r3wp

[!REBOL3-OLD1]

Henrik
13-Feb-2009
[11231]
BrianH, check #1804, for a GATHER function that does something else.
BrianH
13-Feb-2009
[11232x4]
That sounds like a better function to call GATHER. ACCUMULATE will 
get called less than that.
It could use the /into option though.
With all of these collection synonym functions it will be interesting 
to keep them straight.
Use FORALL for the R3 version of GATHER - FORALL is faster than FOREACH 
in R3.
Henrik
13-Feb-2009
[11236]
ASSEMBLE might be a nice word to reserve.
Steeve
13-Feb-2009
[11237]
Could be disturbing for beginners, a same thing can be writed  using 
so many various ways with the tons of mezz we have now.
BrianH
13-Feb-2009
[11238]
Yeah. For an assembler :) We want reserve COMPILE too :D
Henrik
13-Feb-2009
[11239]
Steeve, you have a point. For a couple of years, I would write mezzanines 
for things that already existed in R2, but hadn't noticed.
Steeve
13-Feb-2009
[11240]
ahah, shame on you ;-)
BrianH
13-Feb-2009
[11241]
I'm converting GATHER to mezzanine/library code standards now. We'll 
probably put all of these is an advanced series manipulation library 
module.
Steeve
13-Feb-2009
[11242]
types-of is ugly Brian :)
BrianH
13-Feb-2009
[11243x2]
You have no idea. TYPES-OF was the only reflector that had no corresponding 
hack in R2. I had to do it from scratch.
Mezzanine-quality version of Henrik's GATHER, R3 version:

gather: func [
	"Get the values of a given field from all objects in a block."
	block [block!]
	word [word!]

 /into "Insert into a buffer instead (returns position after insert)"
	output [series!] "The buffer series (modified)"
][
	unless output [output: make block length? block]
	forall block [
		all [
			object? block/1
			in block/1 word
			output: insert/only output select block/1 word
		]
	]
	either into [output] [head output]
]
PeterWood
13-Feb-2009
[11245x3]
Has the spec for make function! been changed on purpose in R3? Is 
for what reason?
Is => if
>> a: make function! [spec] [body]

** Script error: cannot MAKE/TO function! from: function!

** Where: make

** Near: make function! [spec] [body]

>> my-func: make function! [[b] [print b]
]
== make function! [[b][print b]]
BrianH
13-Feb-2009
[11248x2]
Yes. Reason: To simplify and speed up MAKE, and REBOL, and to make 
code generation easier.
Use the wrappers if you want to be R2 compatible.
Steeve
13-Feb-2009
[11250]
Brian, are you sure that (output: insert/only output ..) is faster 
than (append/only output) in R3 ?
BrianH
13-Feb-2009
[11251]
No, it's not, but not by much and it's necessary for the /into option.
Steeve
13-Feb-2009
[11252]
ah yes, i forget
BrianH
13-Feb-2009
[11253x2]
Strangely enough the REBOL overhead of the /into option (one UNLESS, 
one EITHER, and n assignments) is dwarfed by the overhead saved if 
the /into option is implemented pervasively.
Plus, I can copy-paste most of the code :)
Steeve
13-Feb-2009
[11255]
and you say that foreach is slower than forall in this case ? (overhead 
with 3 path evaluations block/1 , no ?)
Henrik
13-Feb-2009
[11256]
BrianH, nice GATHER function. :-)
BrianH
13-Feb-2009
[11257x2]
FOREACH does a BIND/copy of its code block, but you might have a 
point in this case because the 3 paths are N*3.
Final submitted R3 version:

gather: func [

 "Get the values of a given field from all objects in a block that 
 have it."
	block [block!] "A block which may contain objects"
	word [word!] "The field to look for"

 /into "Insert into a buffer instead (returns position after insert)"
	output [series!] "The buffer series (modified)"
][
	unless output [output: make block length? block]
	foreach item block [all [
		object? :item
		in item word
		output: insert/only output select item word
	]]
	either into [output] [head output]
]
Henrik
13-Feb-2009
[11259]
So FOREACH is better, anyway?
Steeve
13-Feb-2009
[11260]
not anyway
Henrik
13-Feb-2009
[11261]
Argh, I need to read better. You wrote this already.
BrianH
13-Feb-2009
[11262x2]
It seems like speed is more important than memory in this function.
Henrik, if you can write up a CureCode wish for this function I can 
mark it as pending.
Henrik
13-Feb-2009
[11264]
For GATHER? Should I just copy your code and credit it to myself? 
:-)
Steeve
13-Feb-2009
[11265]
yes, we all do that :)
BrianH
13-Feb-2009
[11266]
Write up a descriptive request, explaining why you need it, or reference 
your R3 chat message number.
Henrik
13-Feb-2009
[11267]
Sounds bureaucratic, but OK :-)
BrianH
13-Feb-2009
[11268x2]
CureCode is documentation of the new functions. We need the bureaucracy 
for the users' sake.
If we don't have a record of why the function was added we won't 
know where to puut it when we modularize R3.
Henrik
13-Feb-2009
[11270]
Posted.
Steeve
13-Feb-2009
[11271]
Henrik, don't forget to add: "Approved by the politburo"
Henrik
13-Feb-2009
[11272x2]
:-)
And 10 lines for signatures.
BrianH
13-Feb-2009
[11274]
That's my job (read the ticket comments :)
Henrik
13-Feb-2009
[11275]
Curecode needs a trigger for rebdev links.
BrianH
13-Feb-2009
[11276x5]
It will get one, but for now I say something like "R3 chat 1436".
That is the /into option message, so I remember it :)
Here's the R2 version of GATHER:

gather: func [

 "Get the values of a given field from all objects in a block that 
 have it."
	block [block!] "A block which may contain objects"
	word [word!] "The field to look for"

 /into "Insert into a buffer instead (returns position after insert)"
	output [series!] "The buffer series (modified)"
][
	unless output [output: make block length? block]
	foreach item block [all [
		object? get/any 'item
		in item word
		output: insert/only output get/any in item word
	]]
	either into [output] [head output]
]
Do you want a /deep option?
That will require switching to PARSE for speed.