Dwarf has quit [Remote host closed the connection]
nOgAnOo has joined #cinch
nOgAnOo has quit [Excess Flood]
nOgAnOo has joined #cinch
nOgAnOo has quit [Excess Flood]
nOgAnOo has joined #cinch
ayonix has quit [Remote host closed the connection]
ayonix has joined #cinch
Dwarf has joined #cinch
xeviox is now known as xeviox|afk
cloud|nix has joined #cinch
cloud|nix has quit [Read error: Connection reset by peer]
geopet has joined #cinch
<CM-Punk>
If I'm reading from a field in a JSON file and I need the code to see if the contents on the field match one or another like this(I know this is wrong, but that's why I'm asking you and I hope you can figure it out by what I'm doing): if mood == ('happy'|'joy') where mood was earlier defined as the JSON field)
<CM-Punk>
How do I do this?
<CM-Punk>
Bascially I'm trying to match a JSON field with one variable or another
<catepillar>
couple of ways to do it
<catepillar>
the "traditional" would be
<catepillar>
if mood == 'happy' or mood == 'joy'
<CM-Punk>
OH
<CM-Punk>
Okay
<catepillar>
i might do something like
<catepillar>
if ['happy','joy'].include? mood
<catepillar>
makes it easier to maintain if you need to add more
<CM-Punk>
Right
<CM-Punk>
catepillar, that's second method gives me an argument error
<catepillar>
it might be contain? instead of include
<catepillar>
no, it's definitely include
<catepillar>
working just fine for me
<CM-Punk>
Here, I'm actually working on AI for my bot, so let me give you the code that I have here...
<CM-Punk>
[14:07:20] <Victoria> I am a bi female and you are a female...
<CM-Punk>
[14:07:21] <Victoria> We are not compatible.
<leftylink>
found the bug
<leftylink>
2.1.1 :008 > a = 1 => 1
<leftylink>
2.1.1 :009 > puts "TRUE" if ([1, 2].include? a && 3 == 3) => nil
<leftylink>
but what about this?
<leftylink>
2.1.1 :011 > puts "TRUE" if ([1, 2, true].include? a && 3 == 3)
<leftylink>
that prints "TRUE"
<catepillar>
that should print true...
<catepillar>
a=1, right?
<leftylink>
so what?
<leftylink>
oh, yes
<leftylink>
a = 1
<leftylink>
I set that right before
<leftylink>
puts "TRUE" if ([1, 2].include? a && 3 == 3)
<leftylink>
that prints nothing
<leftylink>
see why?
<CM-Punk>
I don't see why, no
<CM-Punk>
But I'm just...you know...new
<CM-Punk>
XD
<leftylink>
what is the difference between [1, 2] and [1, 2, true]?
<CM-Punk>
But isn't that asking it to look for 'true'?
<leftylink>
exactly.
<leftylink>
it's checking if true is in the list
<leftylink>
clearly not what you want.
<catepillar>
ahhhh
<catepillar>
([1, 2].include? a) && 3 == 3
<catepillar>
works
<leftylink>
...
<leftylink>
why not [1, 2].include?(a)
<catepillar>
or that
<leftylink>
this is why I do not favor method calls without parentheses. although I still use puts without parentheses
<catepillar>
also, using 'and' instead of '&&' works
<CM-Punk>
That works
<CM-Punk>
:D
<leftylink>
'and' vs '&&' is an interesting thing. I know rightyrei has been bitten by that very bug. let me see if I can find it
<leftylink>
or it was an 'or' vs '||' bug
<leftylink>
either way, since that happene dI stopped using 'and' and 'or' for boolean checks
<leftylink>
even though, irnoically, using 'and' here would help, not hurt
<CM-Punk>
Updated it to 'and', still works
<catepillar>
i exclusively use and and or
<CM-Punk>
Thanks guys
<CM-Punk>
Hey
<CM-Punk>
Would
<leftylink>
dammit, it is pretty hard to search through commit logs for "and" and "or"
<leftylink>
to see where my bug was
<CM-Punk>
if (['straight','bi'].include?(botSexuality) and sexes == 'different') or (['gay','bi'].include?(botSexuality) and sexes == 'same') or (botSexuality == 'straight' and sexes == 'different')
<CM-Punk>
Would that work?
<CM-Punk>
Instead of having tons of ifs?
<leftylink>
catepillar: my bug would have been related to having something like `a = false or true`
<leftylink>
do that, then see what the value of a is afterward
<leftylink>
that's why I always use && and ||
<CM-Punk>
So would my idea work?
<leftylink>
CM-Punk: isn't the third part of the disjunction subsumed by the first?
<CM-Punk>
Oh yeah
<CM-Punk>
It would be
<CM-Punk>
lul
<leftylink>
my answer to the question that incorporates my laziness and my desire to see people test their code would be "why don't you write tests for it and then you can refactor at will"
<leftylink>
also, related bug using `and` would be `a = true and false`
<leftylink>
guess the value of a after executing that
<cout>
leftylink: Errno::ENOENT: No such file or directory :)
<catepillar>
leftylink, why would you be doing a `a=true and false` to begin with
<catepillar>
but everything i got was a return value of false stored to a
<leftylink>
catepillar:
<leftylink>
wrong
<leftylink>
check a again
<leftylink>
the return value is not the value stored to a.
<leftylink>
and of course I'm not actually doing a = true and false, I'm doing a = complicated_expr1 and complicated_expr2
<leftylink>
where complicated_expr1 evaluates to true and compliated_expr2 evaluates to false
Dwarf has quit [Ping timeout: 264 seconds]
<catepillar>
see i actually prefer the behavior of `a = true and false`
<leftylink>
ok then
<leftylink>
it didn't suit my needs
<leftylink>
I definitely need a to be false and not true when doing this, so I have to use &&
<leftylink>
but there are instances where 'and' is useful, and I guess you found them
<catepillar>
well, i suppose i rarely do assignments like that
<catepillar>
but in actual if statements the and makes more sense to me
<leftylink>
reminds me of python, which is why I used it at first
Dwarf has joined #cinch
postmodern has joined #cinch
<CM-Punk>
Okay, maybe a third mind can help out on this