« first day (1933 days earlier)      last day (2552 days later) » 

4:29 AM
Here is a quicky before I sprint into my bed:
Is there a function similar to Lookup for associations that does not only return the values, but returns a new association or list of rules containing both, keys and values. I know I can write this down myself easily, but maybe there is something built-in I haven't seen. In particular I want:
Lookup2[<|a -> 1, b -> 2, c -> 3|>, {a, c}]
that returns
<| a->1, c->3 |>
or
{a->1, c->3}
I'm sure I can misuse FilterRules for this but has someone a better solution?
Good night, later.
 
 
2 hours later…
6:05 AM
@halirutan This is close KeySelect[<|a -> 1, b -> 2, c -> 3|>, # == a || # == c &]
 
6:19 AM
@halirutan <|a -> 1, b -> 2, c -> 3|> // Query[{Key[a], Key[c]}]
when your keys are strings you can even leave out Key
 
6:58 AM
@Sascha @halirutan even part will do <|a -> 1, b -> 2, c -> 3|>[[Key /@ {a, b}]] but what do you mean by similar to Lookup, is that about the default value?
@halirutan I'm curious what is your daily schedule that you sprint to bed around 6:30 a.m.
 
@Kuba The main reason I would prefer Query over Part in this case is that Query has an operator form and combines nicely with postfix syntax
i.e. <|a -> 1, b -> 2, c -> 3|> // Part[#, {Key[a], Key[c]}] & vs <|"a" -> 1, "b" -> 2, "c" -> 3|> // Query[{"a", "c"}]
 
@Sascha yep, that's reasonable
 
@Sascha assoc[[{Key[a], Key[c]}]] is already a postfix syntax though.
In the sense that the function comes after the variable (if we think of [[{Key[a], Key[c]]}] as an operator form.)
 
7:27 AM
@C. E. You are right [[...]] already is postfix but I never use this form because it looks messy.
 
7:50 AM
I'm confused
What on earth is True doing there?
 
8:06 AM
@numbermaniac Check out
D[x, {x, n}]
% // FullForm
It is not clear from the way that it is displayed, but it is actually returning a Piecewise function. Read about Piecewise in the documentation, and it should become clear why True is there.
It is there in the sense of also e.g. the Switch function. It means that that last case is a catch all.
 
Ahh I see
0 is the default value
That makes much more sense
Thanks
 
np
 
 
2 hours later…
10:43 AM
Why does Refine[EvenQ[2 k], k [Element] Integers] evaluate to False?
 
11:42 AM
Okay I got it, because EvenQ[2 k] evaluates to False before Refine does anything.
 
@Kiro Q functions always return true or false, I think. (?)
How about something like Mod[2 k, 2] == 0 ?
 
Yeah, that or Divisible[2 k,2] will work.
 
EvenQ documentation is quite expicit on the fact it does evaluate to False even when numerical value would be even, but the form of it is not simply an integer.
 
 
1 hour later…
12:58 PM
@C.E. @Sascha @Kuba Thanks guys. You did understand it completely correct. I mentioned Lookup because I want to supply a list of keys I want to extract and the Query solution is perfect.
 
1:19 PM
@Kuba I don't really have a daily schedule. I like to work at night because it is quiet. I love to sleep when I'm really tired and not when mommy says that it's time for bed. And I try to have a good deal of time with my kids and with things that reset your brain. That's when I'm most productive.
 
1:33 PM
 
@Kuba Meets exactly my expectation in the Wolfram row :)
 
@halirutan I see. I have my desk in a room where my wife sleeps so that doesn't always work for me :)
 
@Kuba While we're at it, I read a lot about quality work or getting into the flow and when you do a bit of research on this matter, you find that you are in good company. There is a nice post of Joel Spolsky about Fire and Motion and while I wouldn't recommend this book, I have read Deep Work. But even if the book is not great, you can take out the key points.
 
@halirutan will certainly take a look, thanks.
@halirutan how's mvc framework going?
 
@Kuba I have used it in 4 medium sized GUIs and I really like it. I wanted to write about it, but then again I really do want to have experience with it and see that it works better.
 
1:45 PM
@halirutan I see, I'm looking forward to reading about it.
 
Currently, I have two projects where I wrote packages with > 500 lines of code and then all functions are nicely called by the controller and connected to the GUI. What I like the most is that you can test your package functions and since the code part in the GUI is minimal, there is not much room for bugs that happen in the GUI.
 
@halirutan send me some samples in a free time, I will try to find problems :)
To help you understand it better of course :)
 
2:23 PM
@halirutan You could also use one of:
KeyTake[<|a->1,b->2,c->3|>,{a,c}]
<|a->1,b->2,c->3|> // KeyTake[{a,c}]
KeyTake does not support the default value option of Lookup however.
 
2:40 PM
@WReach I don't really need the default key. The data needs to consistent either way or I'm screwed.
@WReach Thanks!
 

« first day (1933 days earlier)      last day (2552 days later) »