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

World: r3wp

[!REBOL3-OLD1]

PeterWood
13-Feb-2009
[11246x2]
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.
Henrik
13-Feb-2009
[11281x2]
I don't think it's worth it.
for me it makes the most sense to gather values from a particular 
level.
BrianH
13-Feb-2009
[11283x2]
We can always add another CureCode wish for /deep if we need it. 
The current function is fast, so that's nice.
I marked the ticket as pending, with the particular submitted files 
that contain it.
Henrik
13-Feb-2009
[11285]
I think there is merit for a cookbook recipe which briefly describes 
a table of all block manipulation functions, or we have a way in 
HELP to relate these functions, so they become very visible to beginners. 
The problem is that beginners are not likely to be looking for them, 
because they don't expect them to be there. They were created by 
experienced users who have been coding REBOL for years.
BrianH
13-Feb-2009
[11286]
Breaking them up into modules will make it easier to understand - 
digestible chunks.
Janko
13-Feb-2009
[11287]
will there be something like mezz fold/reduce function for r3? I 
would use it a lot
BrianH
13-Feb-2009
[11288x5]
Fold is called ACCUMULATE - only functional languages call it fold.
ACCUMULATE is basically fold-left.
Would you need a /reverse option? ACCUMULATE is already almost as 
fast as we can make it in REBOL, and more options would slow it down. 
The only way we could speed it up more now is to fix an APPLY bug 
with op! functions.
Filter is called REMOVE-EACH in REBOL.
I apologize, ACCUMULATE is whichever version of fold that starts 
at the beginning and ends at the end of series (left? right?).
Janko
13-Feb-2009
[11293]
thanks Brian :) great ! I don't have any use cases where I would 
want accumulate/reverse so far
[unknown: 5]
13-Feb-2009
[11294]
This group needs more abstraction.  The group is turned into mainly 
an R3 mezzanine group.  Should we have a different group for that? 
 Originally, I thought this would be about how R3  is developing 
  more along the native level.
Pekr
13-Feb-2009
[11295]
I agree with Paul. This group served as general R3 info channel for 
those, who were not available to other altme R3 related private worlds. 
Now as we go more into details, I propose to set-up groups as needed: 
R3-mezzanine, R3-plugins, R3-whatever ... what do you think?