Re: [q-lang-users] This feels like a dumb question, but...
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2006-11-25 05:52:24
|
Andrew Berg wrote: > I (think that I) understand the = vs eq difference. I was surprised > that when I tried to apply either one to an expression where the "open F > 0 0" had failed, all I got was a bigger expression. Well, you're trying to compare a constructor term "open F 0 0" to a tuple "()" which isn't defined. If there's no definition for an expression in Q then it's a normal form. So you get what you asked for. ;-) Of course you could have equations like (X=X) = true; (_=_) = false otherwise; in your program, which would make (=) default to syntactic equality, but I wouldn't recommend that. >>-f F = true where () = close (open F 0 0); >> = false otherwise; > > Aah, that's probably the version I was looking for. So, if the > evaluation fails in a "where" clause, the containing equation fails > also. Not quite. It's the pattern match in the local variable definition, "where () = close (open F 0 0)", which fails (if close fails). Here we don't actually define a variable, of course, but the left-hand side of the definition, (), is matched against the result of the right-hand side "close (open F 0 0)" anyway. If the pattern match in a local variable definition fails then the entire equation fails as well, see Section 7.4 [http://q-lang.sourceforge.net/qdoc/qdoc_7.html#SEC29]. This neat little trick is applicable whenever you expect a certain outcome of a computation and want the equation to fail if you get something else. > It's kind of amusing, I started out trying to write this way, but the > only version of stat that I could find in the manual seemed to take a > FD, which required calling "open" anyhow, so since I only needed "-f" > just then I settled on a really dumb implementation. Yes, we have stat, lstat *and* fstat. Actually, most of the POSIX interface is there. :) I guess that Q can't really compete with Perl on this ground, but most of the stuff you need for everyday scripting should be readily available. Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |