On Thu, Dec 13, 2018 at 12:44 PM Roelof Wobben <r.wobben@home.nl> wrote:
there is a method but then I ran into another warning

FindAndDeleteWordsWithForbiddenParts
������ "deletes all the words that contain forbidden parts"

������ | result |
������ result := words
������ ������ select: [ :word |
������ ������ ������ [ (forbiddenWords detect: [ :forbidden | word includesAll: forbidden ]) = true ]
������ ������ ������ ������ on: NotFound
������ ������ ������ ������ do: [ true ] ].

There are a number of things you can do, such as the variations on detect , for example. But, even those keep you from the answer. The question you are trying to answer is which words satisfy the condition that they don't include any forbidden word as a sub-string.

There are other variations than detect for that kind of question. Try examining the API in Collection for any which suggest a correspondence, and if not there, check subclasses in turn down to the classes of the collections you are working with. And don't forget that #select: isn't the only way to extract a subset of a collection. Look around for others.

[I'm deliberately not giving you the answer, because I think you will benefit from learning how to work effectively in the environment.]


������ ^ result

then I see a unnecearry = true but if I deleted that part the code does not what I was intented to do.

Roelof



Op 13-12-2018 om 18:15 schreef Richard Sargent:
It's bad advice in this case, but correctly indicates there is a problem with your code. See below.

On Thu, Dec 13, 2018 at 8:13 AM Roelof Wobben <r.wobben@home.nl> wrote:
Hello, 

I have this code :  

��FindAndDeleteWordsWithForbiddenParts
    "deletes all the words that contain forbidden parts"

    | result |
    result := words
        select: [ :word | 
            [ (forbiddenWords reject: [ :forbidden | '*' , forbidden , '*' match: word ]) isNotEmpty ]
Constructing a pattern and pattern matching is a heavy-handed approach to find out if a word contains a substring.
I'm not familiar with Pharo's methods, but at the least String inherits #indexOfSubCollection:startingAt: and probably a number of others. There is also a good chance String inherits or implements a more specific method that will test for the presence of a sub-string.

A good piece of advice I once received is (paraphrased as): Spend more time reading and less time writing. :-)
The deeper a class hierarchy, the greater the chance that the exact thing you need has already been implemented in the leaf class or its abstraction.

                on: NotFound
                do: [ false ] ].
    ^ result


but I see warnings that I have to use a stream instead of string concentation.

Anyone hints how to do so ? 

Roelof