Timeline for How to test if optional argument has been given?
Current License: CC BY-SA 3.0
16 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 20, 2012 at 1:34 | comment | added | Mr.Wizard | @LeonidShifrin and Istvan, alright, thank you. | |
Mar 20, 2012 at 1:12 | comment | added | István Zachar | @Mr.Wizard I think the two answers can live next to each other perfectly well dealing with slightly different aspects of my question (like lhs/rhs testing), so please don't delete your answer under any circumstances as it provides invaluable solutions for my (and presumably others') unposted questions. | |
Mar 20, 2012 at 0:35 | comment | added | Leonid Shifrin | @Mr.Wizard Thanks, but in this case I'd keep things as they are, because we clearly interpreted the problem differently. I happenned to pick the interpretation that apparently was what Istvan was after, but IMO your answer is (as always) valuable. I did not vote for it this time though, since I think it solves a slightly different problem, but it does not mean that I find no value in it. Some people may come to this question having exactly the problem which your answer addresses and mine doesn't. | |
Mar 20, 2012 at 0:28 | comment | added | Mr.Wizard | @Leonid In no way did I mean to disparage your answer. I simply found all of this confusing. If you find any additional value in my answer feel free to include it in yours. If you choose to do this I will delete it; otherwise I will leave it. | |
Mar 20, 2012 at 0:07 | comment | added | Leonid Shifrin |
@Mr.Wizard I did mention the comparison of {} and {arg} as a general suggestion as well, in my answer.
|
|
Mar 19, 2012 at 15:12 | comment | added | István Zachar |
Leonid's answer is correct in the sense that if there is no arg given to f , it evaluates to False , else it also checks whether the given argument equals a certain value. While your solution works as well, I still prefer Leonid's way, as it does the test on the rhs and does not touch the lhs of the function definition (which I implicitly wanted).
|
|
Mar 19, 2012 at 13:12 | comment | added | Mr.Wizard |
Based on your update, I think my recommendation of {} =!= {arg} is correct. You are testing the argument on the LHS already, using a test function. Leonid's {arg} === {"ArgValue"} doesn't make sense in this case, and it also assumes a specific value for the optional argument.
|
|
Mar 19, 2012 at 10:52 | history | edited | István Zachar | CC BY-SA 3.0 |
Added more explanation on problem and target
|
Mar 19, 2012 at 10:43 | history | edited | István Zachar | CC BY-SA 3.0 |
Added more explanation on problem and target
|
Mar 18, 2012 at 6:04 | history | tweeted | twitter.com/#!/StackMma/status/181259673704480770 | ||
Mar 17, 2012 at 14:41 | history | edited | Szabolcs | CC BY-SA 3.0 |
edited title
|
Mar 17, 2012 at 14:35 | history | edited | Szabolcs | CC BY-SA 3.0 |
edited title
|
Mar 17, 2012 at 14:27 | answer | added | Mr.Wizard | timeline score: 7 | |
Mar 16, 2012 at 18:23 | vote | accept | István Zachar | ||
Mar 16, 2012 at 18:12 | answer | added | Leonid Shifrin | timeline score: 14 | |
Mar 16, 2012 at 18:07 | history | asked | István Zachar | CC BY-SA 3.0 |