How scan works and the difference between scan and backslash.

https://learninghub.kx.com/forums/topic/how-scan-works-and-the-difference-between-scan-and

What is the difference between scan and \?

show USTour:([]StartCity:`Boston`NewYork`Washington`Miami`Austin`Chicago;EndCity:`NewYork`Washington`Miami`Austin`Chicago`Boston;wp:0 1 1 1 1 0)
show route:USTour[`StartCity]!USTour[`EndCity]
route scan `NewYork //returns `NewYork`Washington`Miami`Austin`Chicago`Boston

In this situation, I can't seem to use the backslash (I get an error). However, if I want a termination condition (a while loop!) then I need to use the backslash:

(`Austin )route\ `NewYork //returns `NewYork`Washington`Miami`Austin

How can I know which one to use? When is the backslash interchangeable with scan?

Hi, 

You can use the keyword scan or the backslash to achieve the same thing here. However the syntax for using the backslash needs to include square brackets []

route scan `NewYork

becomes

route \[`NewYork]

You can read more about Scan here: Accumulators – Reference – kdb+ and q documentation


Hope that helps!

Laura

Thank you! And thank you for editing the question. I rewrote it several times (making sure to use plaintext), but the formatting ended up wonky after I pressed post.