Type | Wish | Status | reviewed | Date | 25-Apr-2009 16:04 |
---|---|---|---|---|---|
Version | alpha 49 | Category | Native | Submitted by | BrianH |
Platform | All | Severity | minor | Priority | normal |
Summary | COLLECT-WORDS /as type [datatype!] option |
---|---|
Description | This would let you specify the datatype of the words in the returned block. Any word type should be acceptable (including refinement!), and perhaps the string types as well. This is probably more efficient than the alternative (FORALL x [x/1: TO type x]), and would be common in other uses of COLLECT-WORDS. |
Example code |
>> collect-words/set/as [a: b] refinement! == [/a] >> collect-words/as [a: b] string! == ["a" "b"] |
Assigned to | n/a | Fixed in | - | Last Update | 22-Jun-2014 02:38 |
---|
Comments | |
---|---|
(0000556)
Gregg 25-Apr-2009 20:00 |
Per the related discussion about FUNCT, which mentions COLLECT-WORDS/set/deep/ignore, is COLLECT-WORDS getting overloaded? Would it be better to have more general transformation and filtering funcs we combine?
I don't know what /set and /ignore do, but my first reaction is that a 'collect-values func that takes a typeset! would be more widely applicable. Then collect-words is just a mezz wrapper, which shows people how to do that for themselves, perhaps currying and APPLYing transformations as well (e.g. mapping an /as refinement to a general AS func. I often start out with specific funcs, and generalize them over time as patterns emerge. e.g. I started with a 'collect-set-words mezz, which begat 'collect-values, which begat 'collect. 'As begat 'change-all which begat 'change-each. |
(0000558)
BrianH 26-Apr-2009 12:12 |
The linear, non-hashing algorithm of COLLECT-WORDS likely only work on any-word! types. The /set option only collects set-word! values, and the /ignore option lets you provide a collection of words to exclude from the result.
There are two problems that can arise from generalizing functions: - You lose out on optimizations that can come with more specialized code. - Making your generalized functions do the specific things you need them to do can add overhead, particularly extra code. In compiled languages you can have the optimizer remove the overhead of function application, currying and such. In interpreted languages like REBOL *you* are the optimizer, so you need to remove that overhead yourself. |
(0000559)
Carl 26-Apr-2009 18:15 |
Correct. Note that we've referred to this as "an internal function" because it is a special purpose, tuned, high-speed action - non-generalized.
Its primary purpose is in use with context constructors, which can be high frequency, hence benefit from linear method. On refinement, is /as the right name? Or is it more like /of ? Do we have existing usage pattern on it? Also, it can only be done efficiently for words (as you've noted). |
(0000560)
BrianH 27-Apr-2009 01:51 |
The name /as is right, similar to request #546 or the AS type conversion operator in many other programming languages. The /as option would be an output conversion, regardless of the type of the input words. The name /of would imply an input filter, the same way /set restricts the input to set-words.
You would use /as if you needed the resulting block to contain words of another type than word!. For instance, imagine that you wanted to create an object! out of the resulting words, but didn't have BIND/set - you would want the words to be of the set-word! type. Or maybe a dialect needs get-words, or refinements. Who knows? |
Date | User | Field | Action | Change |
---|---|---|---|---|
22-Jun-2014 02:38 | BrianH | Category | Modified | => Native |
27-Apr-2009 01:52 | BrianH | Comment : 0000558 | Modified | - |
27-Apr-2009 01:51 | BrianH | Comment : 0000560 | Modified | - |
27-Apr-2009 01:51 | BrianH | Comment : 0000560 | Added | - |
26-Apr-2009 18:16 | Carl | Comment : 0000559 | Modified | - |
26-Apr-2009 18:16 | Carl | Comment : 0000559 | Modified | - |
26-Apr-2009 18:15 | Carl | Comment : 0000559 | Added | - |
26-Apr-2009 12:12 | BrianH | Comment : 0000558 | Added | - |
25-Apr-2009 20:00 | gregg | Comment : 0000556 | Added | - |
25-Apr-2009 16:07 | BrianH | Description | Modified | - |
25-Apr-2009 16:07 | BrianH | Code | Modified | - |
25-Apr-2009 16:07 | BrianH | Status | Modified | submitted => reviewed |
25-Apr-2009 16:04 | BrianH | Ticket | Added | - |