Type | Wish | Status | tested | Date | 26-Oct-2010 20:13 |
---|---|---|---|---|---|
Version | alpha 109 | Category | Mezzanine | Submitted by | Carl |
Platform | All | Severity | minor | Priority | normal |
Summary | Add FIND-ALL |
---|---|
Description | This is a very common idiom that I use all the time and I'm going to add it to the mezzanine. |
Example code |
Idiom: while [series: find series item] [ do-something series series: next series ] Mezz: find-all series item [do-something item] Notes: Intentionally not named FIND-EACH because it's more like FORALL and FORSKIP, including the arg order (series then item). |
Assigned to | n/a | Fixed in | alpha 110 | Last Update | 2-Nov-2010 07:05 |
---|
Comments | |
---|---|
(0002662)
BrianH 26-Oct-2010 22:49 |
Don't forget #539 if you want to make this a mezzanine. |
(0002684)
pekr 27-Oct-2010 17:07 |
Isn't the naming a bit rushed? For me it does not represent the meaning sufficiently. FIND-ALL does not imply, that anything is going to be done with the elements being found. What is more - don't forget you owe us FIND/FIRST :-)
I would probably prefer DO-ALL, but that somehow does not reflect the meaning either. Well, what about FOR-FOUND/FORFOUND? :-) The name sounds a bit weird, so maybe FOR-FIND/FORFIND - that has nice soundex to forskip? Wouldn't it work for us? Or - introducing refinement to FORALL/find, FOREACH/find, where you could add a search phrase? I think if such concept would be used, we would not need remove-each, but we could simply have remove/find, change/find .... REMOVE-EACH would have to have different syntax, in order for you to call your desired function FIND-EACH, to be a bit compatible ... |
(0002687)
Gregg 27-Oct-2010 23:11 |
I'm with Petr about the name being worthy of more consideration. By using 'find as the main part of the name, it seems that it should return a find-like result. e.g.
;!! Uses my COLLECT syntax find-all: func [series [series!] value /local result] [ collect/only val [ while [series: find series value] [ val: series series: next series ] ] ] (I don't know why the pre tag is inserting extra newlines) |
(0002688)
Gregg 27-Oct-2010 23:33 |
Consider also whether the result should always be discarded. If we had the inverse of REMOVE-EACH...
keep-each: func [ "Keeps only values from a series where body block returns TRUE." 'word [get-word! word! block!] "Word or block of words to set each time (will be local)" data [series!] "Series to traverse" body [block!] "Block to evaluate. Return TRUE to collect." ] [ remove-each :word data reduce ['not to paren! body] ] ...wouldn't your FIND-ALL be MAP-EACH + KEEP-EACH? i.e. map+filter. And if you say you're doing it the way you are for performance reasons, rest assured I'll cry "premature optimization" and ask for examples. :) |
(0002693)
BrianH 28-Oct-2010 23:20 |
Gregg, the behavior in the ticket is what is being requested - the name is less important. The name should reflect the behavior, not the behavior reflect the name. |
(0002699)
Gregg 29-Oct-2010 19:15 |
Carl said he named it specifically; he didn't say "here's what I want it to do, come up with a good name". Hence I posted my comment on the name and what behavior I would expect from that name. My second post is strictly about behavior. |
(0002704)
BrianH 30-Oct-2010 21:54 |
Cool. And I'll submit a ticket for KEEP-EACH. |
(0002732)
Gregg 1-Nov-2010 17:31 |
Thanks, and sorry for any confusion. |
(0002753)
BrianH 2-Nov-2010 07:05 |
Implemented in alpha 110. Note that FIND-ALL returns the series at the position of the last thing it finds, or none if it doesn't find anything. |
Date | User | Field | Action | Change |
---|---|---|---|---|
2-Nov-2010 07:05 | BrianH | Comment : 0002753 | Added | - |
2-Nov-2010 07:03 | BrianH | Status | Modified | built => tested |
1-Nov-2010 17:31 | Gregg | Comment : 0002732 | Added | - |
30-Oct-2010 21:54 | BrianH | Comment : 0002704 | Added | - |
29-Oct-2010 19:15 | Gregg | Comment : 0002699 | Added | - |
28-Oct-2010 23:20 | BrianH | Comment : 0002693 | Added | - |
27-Oct-2010 23:33 | Gregg | Comment : 0002688 | Added | - |
27-Oct-2010 23:12 | Gregg | Comment : 0002687 | Modified | - |
27-Oct-2010 23:12 | Gregg | Comment : 0002687 | Modified | - |
27-Oct-2010 23:11 | Gregg | Comment : 0002687 | Modified | - |
27-Oct-2010 23:11 | Gregg | Comment : 0002687 | Added | - |
27-Oct-2010 17:07 | pekr | Comment : 0002684 | Added | - |
27-Oct-2010 06:42 | carl | Status | Modified | reviewed => built |
27-Oct-2010 06:42 | carl | Fixedin | Modified | => alpha 110 |
26-Oct-2010 22:59 | BrianH | Comment : 0002662 | Modified | - |
26-Oct-2010 22:49 | BrianH | Comment : 0002662 | Added | - |
26-Oct-2010 22:45 | BrianH | Category | Modified | Unspecified => Mezzanine |
26-Oct-2010 20:13 | carl | Status | Modified | submitted => reviewed |
26-Oct-2010 20:13 | carl | Code | Modified | - |
26-Oct-2010 20:13 | carl | Ticket | Added | - |