cancel
Showing results for 
Search instead for 
Did you mean: 

pj with uj-like semantics?

Flying
New Contributor III
Hi,

I wonder if there is a simpler way to write a pj with uj-like semantics?

The behaviour of pj is more like an lj, keys on the L.H.S. are preserved and matching values from R.H.S. are added. More often than not, though, I need a pj with the semantics of uj, i.e., if a key is present on the R.H.S. but not on the L.H.S., it should be added to the final result. To illustrate this idea better, here is an example:

q)L:([K:`a`b`c]V:100 200 300)
q)R:([K:`
a`d]V:1000 2000)
q)L pj R
K| V
-| ----
a| 1100
b| 200
c| 300
q)L uj R
K| V
-| ----
a| 1000
b| 200
c| 300
d| 2000
q)L puj R    
/The would-be pj-uj combo
K| V
-| ----
a| 1100
b| 200
c| 300
d| 2000


Thanks in advance.
2 REPLIES 2

Nick
New Contributor
how about +
q)L+R
K| V  
-| ----
a| 1100
b| 200
c| 300
d| 2000


Flying
New Contributor III
Cool!  Thanks a lot. This is a lot simpler than I had expected. :^P