« first day (1990 days earlier)      last day (2511 days later) » 

6:10 AM
@WReach But why the match with missing `b` is a match? I have a busy week but I surely miss something here: `Cases[
<|"a" -> 1, "b" -> 2, "c" -> 3|>, KeyValuePattern[{"a" -> a_, "b" -> b_, "c" -> c_}] , {0, \[Infinity]} ]` - according to this there is only one match.
@WReach ok, I think I understand. KeyValuePattern is ok, it is just T-S method implication.
@WReach plot twist! no I don't fully get it :) because there is no leak in `f[x_Real] := Echo[x^2];
Hold[{Hold[2.], Hold[3.], Hold["string"]}] /.
n_Real :> With[{eval = f[n]}, eval /; True]`
 
6:31 AM
@xzczd @WReach @MichaelE2 @b3m2a1 Thanks for a feedback, I still don't get it so here is the question
0
Q: KeyValuePattern in matching and replacement in nested associations

KubaThis case revealed I am missing something in understanding pattern matching and evalaution in case of match, or I can't grasp it's due to the busy week I have. Either way, I find this problem interesting for wider audience: asso = <| "key" -> <|"a" -> "1", "b" -> Compress@"test"|> |> We wa...

 
7:09 AM
@WReach @MichaelE2 @b3m2a1 while it does not change the case, I used val /; True in the example instead of eval /; True, sorry for confusion. Still the problem is with evaluation earlier so the core question stays valid.
 
 
8 hours later…
3:22 PM
@Kuba I'm probably not going to reply to the question because my response would be essentially the same as Mr.Wizard's. I'll put some thoughts here because the comment chain on the question is already very long.
The `KeyValuePattern` specifies a list of patterns that are each matched individually. The crux of the matter is whether the condition attached to the whole pattern should be evaluated once for each of those subpatterns or only once at the end. WRI has chosen to apply it for each subpattern.
I hesitate to call it a bug, but rather a design choice with trade-offs. As it stands, each subpattern is guarded by a condition that can reference variables from other subpatterns -- albeit with the complexity that the condition must be aware of repeated evaluation and that some variables may not yet be available.
Under the alternative choice, each subpattern must remain unware of the others. If it had been my choice to make, I would probably have gone with "isolated subpatterns". It feels more consistent with general pattern-matching principles, and the modest loss of expressiveness seems like a good trade-off to avoid strange side-effects like we see here.
 
 
3 hours later…
6:07 PM
@WReach That should be a famous quote! "A design choice with trade-offs" That sounds so awesome and it plays in the same league as "mentally challenged".
2
 
 
3 hours later…
9:34 PM
hi
anybody there
 

« first day (1990 days earlier)      last day (2511 days later) »