another smallification

35 views
Skip to first unread message

Jack Andrews

unread,
Apr 19, 2012, 7:08:15 AM4/19/12
to Kdb+ Personal Developers
is there a shorter k expression for:

  k)`a`b {.[x;();{x::y};y]}' 2?10

?  

i'm fussy:     p:2?10;a:*p;b:p 1  doesn't count.  

i'm looking for  a shorter

  k){.[x;();{x::y};y]}


thanks guys  :j

Attila Vrabecz

unread,
Apr 19, 2012, 7:23:44 AM4/19/12
to personal...@googlegroups.com
I don't think you need that at all

q)`a`b set'2?10
k)`a`b .[;();:;]'2?10

Cheers,
Attila

> --
> You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
> To post to this group, send email to personal...@googlegroups.com.
> To unsubscribe from this group, send email to personal-kdbpl...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.

Jack Andrews

unread,
Apr 19, 2012, 7:28:43 AM4/19/12
to personal...@googlegroups.com

q)`a`b set'2?10
k)`a`b .[;();:;]'2?10

i want to use :: coz my expr is in a while loop and I want to set a and b globally
 

Felix Lungu

unread,
Apr 19, 2012, 7:29:57 AM4/19/12
to personal...@googlegroups.com
then qualify `a and `b.

Jack Andrews

unread,
Apr 19, 2012, 7:35:22 AM4/19/12
to personal...@googlegroups.com
no hits on code.kx.com for "qualify"

Attila Vrabecz

unread,
Apr 19, 2012, 7:56:47 AM4/19/12
to personal...@googlegroups.com, personal...@googlegroups.com
set is always global

You cannot refer to a parameter or local by name at all
(as they are on the stack)

Only complication is that set always works in the current namespace
What Felix probably means is that you can do `..a to make sure it is main namespace - however that is only needed if you are working with namespaces

   Attila

Felix Lungu

unread,
Apr 19, 2012, 7:57:04 AM4/19/12
to personal...@googlegroups.com
namespaces. qualify the names in their namespace.
the main one is `.. , so `..a`..b set'2?10 does the trick but set does it globally anyway even inside of a lambda.
`a`b set… is enough.

Jack Andrews

unread,
Apr 19, 2012, 8:53:17 AM4/19/12
to personal...@googlegroups.com
atilla wrote: 
I don't think you need that at all

q)`a`b set'2?10
k)`a`b .[;();:;]'2?10


nice one.  and i see a clever projection here.  and i now see that : operates 
globally in the . (apply) from other messages in the thread

thanks,
jack.

Reply all
Reply to author
Forward
0 new messages