Message Boards Message Boards

7
|
6191 Views
|
1 Reply
|
8 Total Likes
View groups...
Share
Share this post:
GROUPS:

Creating a list without Null entries

Posted 11 years ago
If you want to generate a list using a If function, the False (or the True) value might create Nulls.

The solution is to use the vanishing function : ##&[] 
testmatch[input_, letter_] :=
If[StringMatchQ[input, StringJoin[letter, "*"]], input, ## &[]]
This is like a very simple grep command.

The idea comes from How to remove the Null symbol in a Table in Mathematica?
POSTED BY: guylhem ...
Posted 11 years ago
I always use `Unevaluated[Sequence[]]` inside If as my "vanishing function". So techinically I just use Sequence[]. That seems straightforward emoticon. But this is nothing new I see, it can be found by following some more links in the linked article above.

Things can be further sped up by giving If (or other functions, in particular Function) attribute SequenceHold temporarily, but I guess that is a hack.
POSTED BY: Jacob Akkerboom
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract