Timeline for How to avoid returning a Null if there is no "else" condition in an If construct
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 21, 2018 at 10:36 | comment | added | NeverMind |
Stumbled over the same problem with Compile . Is there now a better solution available than your workarounds. It's kind of a pity. :(
|
|
Sep 22, 2013 at 5:15 | comment | added | RunnyKine | @Mr.Wizard. That's what I did, I was just hoping there was a way to avoid that extra step. Thanks for the response though. | |
Sep 22, 2013 at 4:18 | comment | added | Mr.Wizard |
Without trying it I expect that it won't work with Compile because the possible return types must match. A work-around would be to use something like -1 (for a list of otherwise positive integers) or perhaps Developer`$MaxMachineInteger for the "sequence" return and then DeleteCases at the end. This can create edge cases but I don't know of a better way off-hand.
|
|
Sep 22, 2013 at 1:28 | comment | added | RunnyKine |
@Mr.Wizard. Do you know why none of those methods work with Compile ? Is there a way to get around it?
|
|
Sep 22, 2013 at 1:09 | comment | added | Mr.Wizard | Okay. Completeness is good, so +1. (I also included this in my answer which I am attempting to make complete itself.) | |
Sep 22, 2013 at 1:05 | comment | added | RunnyKine |
@Mr.Wizard, I didn't know about it until recently I needed to do a time consuming computation and found it in Michael Trott's Programming guidebook. I came across this post but realized it wasn't posted so decided to post it for completeness. I actually liked your ##&[] trick better.
|
|
Sep 21, 2013 at 23:30 | comment | added | Mr.Wizard |
This does work, and was recommended by Leonid at one time but isn't it better to use ##&[] now? Do you prefer Sequence @@ {} or are you just posting it for completeness?
|
|
Sep 21, 2013 at 22:15 | history | answered | RunnyKine | CC BY-SA 3.0 |