cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to combine til with a variable?

don
New Contributor
For example the following codedouble:{x*2}til (double 5)prints 0...9Suppose I wish to dotil zUntil double z > 20How would I express this in Q?
4 REPLIES 4

trieder
New Contributor
charset=us-ascii
X-Mailer: iPhone Mail (9A334)
In-Reply-To:
Message-Id: <6841E33F-48E3-4389-8619-D1778AC13F88@gmail.com>
Date: Wed, 26 Oct 2011 05:37:35 -0400
To: "personal-kdbplus@googlegroups.com"

Mime-Version: 1.0 (1.0)

You can't combine til with an expression like that. I think you can do somet=
hing like that with Haskell though.

The closest thing I can think of would be something like:

a@:where(a:double til 1000)>20

You could also use a loop and dynamically build an expression, but that woul=
d be "illegal," slow and ugly.

don
New Contributor

Thanks Tim, is there a way to do lazy evaluations of lists? The
following crashes the system which indicates it is unnecessarily
iterating over everything (i.e. it wold be nice to break on the first
false)

double:{x*2}
a@:where(a:double til 1000000000)<20
a

charlie
New Contributor II
New Contributor II
could cook your own til

q)mytil:{-1_(1+)\[{x>y z}[x;y];0]}
q)mytil[20;double]
0 1 2 3 4 5 6 7 8 9

doesn't scale well though. 🙂

trieder
New Contributor
charset=us-ascii
X-Mailer: iPhone Mail (9A334)
In-Reply-To:
Message-Id: <9DF06676-36E3-475C-A51F-551A19F21AA4@gmail.com>
Date: Wed, 26 Oct 2011 06:49:38 -0400
To: "personal-kdbplus@googlegroups.com"

Mime-Version: 1.0 (1.0)

No lazy eval in q except on file reads (mmap) as far as I'm aware.

Take a look at this for a conditional break:

https://code.kx.com/trac/wiki/Reference/BackSlash#iterate