Thread: Re: [q-lang-users] New 'where' syntax
Brought to you by:
agraef
From: Keith T. <kaz...@ea...> - 2007-05-25 03:00:21
|
Hello Albert -- --- Albert Graef <Dr....@t-...> writes: - Ok, I've finally given in to popular demand and added a syntax - for shared 'if' and 'where' clauses. ;-) Cool. OTOH, I'm still waiting for syntax to support the new 'when' and 'what if' clauses... ... ... ... Just kidding! ;-D Cheers! Keith |
From: Keith T. <kaz...@ea...> - 2007-05-25 09:42:49
|
Hello Albert -- --- Albert Graef <Dr....@t-...> writes: - In Q this definition can now be written as follows: - clunky ENV VAR1 VAR1 - where just VAL1 = lookup ENV VAR1, - just VAL2 = lookup ENV VAR2: <<<<< Is that colon ':' following 'VAR2' correct? It doesn't look right, but I know that I have probably missed something along the way... (so I'm asking you nicely for clarification =). --- Albert Graef <Dr....@t-...> writes: - Another side note, and request for comments about "qualifier" vs. "guard" [snip!] Wrt. "simple" labels, e.g., "qualifier" and "guard", if "guard" is already established, then why not go with it? Unless, of course, Q has a special use for "guard"; but it means the same, right? Similarly, wrt. "guarded equations" and "conditional equations", the former expression is better for folks coming to Q from Haskell (over on perl6lang, they claim that before Pugs*, that there were only *two* people programming in Haskell... ;-). OTOH, I think that introducing the concept of "conditional equations" is also appropriate, if we first note that this is how term rewriting refers to "guarded equations". Travel and an expanded vocabulary both serve to broaden the mind! Just my two cents! =) Cheers, Keith *Pugs = Perl Users Gofer System (or so I think...) |
From: Albert G. <Dr....@t-...> - 2007-05-25 11:56:46
|
Keith Trenton wrote: > - In Q this definition can now be written as follows: > - clunky ENV VAR1 VAR1 > - where just VAL1 = lookup ENV VAR1, > - just VAL2 = lookup ENV VAR2: <<<<< > > Is that colon ':' following 'VAR2' correct? It doesn't look right, but I know that I have probably missed something along the way... (so I'm asking you nicely for clarification =). Yes it is... Some kind of proper delimiter which terminates the list of lhs qualifiers/guards was needed (both for readability purposes, and to resolve actual ambiguities in the grammar). I first considered ',', but this wasn't possible since ',' also delimits different definitions in a 'where' clause, and ';' looked awful (as if the equation ended prematurely). I think that ':' is a fairly good choice; if properly formatted, it makes the lhs qualifiers stick out like a kind of "case labels", as shown in my revision of Eddie's original 'strip' example in my previous post: strip C S where N = #S-1 if not null S: = strip C $ sub S 0 (N-1) if S!N = C; = strip C $ sub S 1 N if S!0 = C; otherwise: = S; -- 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 |
From: Albert G. <Dr....@t-...> - 2007-05-25 17:12:43
|
Keith Trenton wrote: > Wrt. "simple" labels, e.g., "qualifier" and "guard", if "guard" is already established, then why not go with it? Unless, of course, Q has a special use for "guard"; but it means the same, right? Well, in fact the manual was originally written at the beginning of the 1990s when I wasn't very familiar with the "official" FP jargon. Of course it has been overhauled many times since then, but somehow the term "qualifier" sticked. Maybe it's time to change it now... -- 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 |
From: Albert G. <Dr....@t-...> - 2007-05-25 17:24:56
|
Albert Graef wrote: > [...] the term "qualifier" sticked. s/sticked/stuck/ Where's that spellchecker when you need it? :) -- 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 |
From: John C. <co...@cc...> - 2007-05-25 18:08:10
|
Albert Graef scripsit: > Well, in fact the manual was originally written at the beginning of the > 1990s when I wasn't very familiar with the "official" FP jargon. Of > course it has been overhauled many times since then, but somehow the > term "qualifier" sticked. Maybe it's time to change it now... To me, the term "guard" (which I think is due to Dijkstra ultimately) connotes conditionals but not bindings, so I would prefer to retain "qualifier" as a term for both bindings and conditionals. -- In politics, obedience and support John Cowan <co...@cc...> are the same thing. --Hannah Arendt http://www.ccil.org/~cowan |
From: Albert G. <Dr....@t-...> - 2007-05-25 21:21:02
|
John Cowan wrote: > To me, the term "guard" (which I think is due to Dijkstra ultimately) > connotes conditionals but not bindings, so I would prefer to retain > "qualifier" as a term for both bindings and conditionals. That's my gut feeling, too, and it corresponds to the traditional notion of "guard" that I know. But then there's Peyton-Jones' notion of "pattern guards" [1] which are exactly like Q's 'where' clauses. (Well, I guess that I can say that I reinvented them independently, not knowing PJ's proposal.) Wikipedia also calls them "guards", referring to PJ [2]. I'm not sure, however, how common that usage of "guard" is in the general FP community. [1] http://research.microsoft.com/Users/simonpj/Haskell/guards.html [2] http://en.wikipedia.org/wiki/Guard_(computing) -- 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 |
From: Keith T. <kaz...@ea...> - 2007-05-25 17:00:10
|
Hello Albert -- --- Albert Graef <Dr....@t-...> writes: - - strip C S - where N = #S-1 if not null S: - = strip C $ sub S 0 (N-1) if S!N = C; - = strip C $ sub S 1 N if S!0 = C; - otherwise: <<<<< - = S; Got it! The use of the token 'otherwise' before the colon is a nice touch; the other example did not feature the 'otherwise' and suddenly, the ':' looked "alien" to me. ;-) Thanks for pointing out my oversight! Cheers, Keith |
From: Eddie R. <ed...@bm...> - 2007-05-26 15:09:00
|
I went to the SoureForge Archives and saw this submission that I didn't get via email. Oh well. I copied the subject line so I hope it goes to the write spot. Albert Graef wrote, >But I have to admit that > >foo X where Y = bar X: = Y/2; > >doesn't read very well. I can live with it, since I read it as: "Define >foo X. First case, where Y = bar X: result is Y/2". Maybe you can get >used to it. But for native English speakers it might be too much to bear. To me, a native English speaker (Albeit southern dialect), the "where" and "if" clauses read just fine if the equation part is broken to the next line as foo X where Y = bar X: = Y/2; or even better foo X where Y = bar X: = Y/2; I'm sure the email won't preserve the indention though. I'm seriously considering changing my emacs mode to indent "=" on the lhs differently than than the introductory "=" part of the equation. I'm also considering changing the way nested "if then else" constructs within parenthesis currently indent. I would like them to indent like without ()s. Is this something other Q users would want? Eddie |
From: Albert G. <Dr....@t-...> - 2007-05-26 18:59:55
|
Eddie Rucker wrote: > I went to the SoureForge Archives and saw this submission that I didn't > get via email. Strange. I just looked at the header and I'm sure it was also sent to your pm. > foo X > where Y = bar X: > = Y/2; Right. I'd actually prefer to have the lhs qualifiers stick to the leftmost column, without any indentation, but your format also looks fine. Maybe there could be parameters in q-mode.el for the relative indentation of both lhs and rhs qualifiers (IIRC there already is for the rhs quals). I'm not sure how to do it since you probably have to do a full parse of equations to assign indentation properly. The equation syntax is actually regular so that shouldn't be a problem, but of course the expression syntax isn't and so you'll need to at least keep track of nested if-then-else and parens/brackets/braces to make this work. Also, figuring out where to start the parse without parsing the whole source file might be tricky. ;-) > I'm sure the email won't preserve the indention though. I'm seriously > considering changing my emacs mode to indent "=" on the lhs differently > than than the introductory "=" part of the equation. I'm also considering > changing the way nested "if then else" constructs within parenthesis > currently indent. I would like them to indent like without ()s. Is this > something other Q users would want? Yes, as I already pointed out above, q-mode.el most certainly needs a full overhaul of the indentation code. The current code is a hack which started from a Prolog mode which only needed rudimentary indentation; nevertheless, it worked astonishingly well until if-then-else arrived. ;-) For if-then-else it doesn't really do anything useful right now, and the mode also needs to be adapted for the lhs qualifiers, of course. If you can figure that out I'd be very thankful. I hate elisp hacking. :) Cheers, 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 |
From: Albert G. <Dr....@t-...> - 2007-05-25 09:07:49
|
Keith Trenton wrote: > Cool. OTOH, I'm still waiting for syntax to support the new 'when' and 'what if' clauses... LOL. I guess that we'll get those when the first 64 qubit quantum computers arrive. ;-) More seriously, the Haskell programmers among you probably noted that the new syntax looks almost like Haskell's guarded equations (including Peyton-Jones' pattern guards), except that it's a tad more verbose (and, of course, in Q the qualifiers are processed from right to left rather than from left to right). E.g., here's the example taken from http://research.microsoft.com/~simonpj/Haskell/guards.html: clunky env var1 var1 | Just val1 <- lookup env var1 , Just val2 <- lookup env var2 = val1 + val2 ...other equations for clunky... In Q this definition can now be written as follows: clunky ENV VAR1 VAR1 where just VAL1 = lookup ENV VAR1, just VAL2 = lookup ENV VAR2: = VAL1 + VAL2; ...other equations for clunky... (Of course you could already define 'clunky' that way with a rhs qualifier ever since Q got its 'where' clauses, but the new syntax matches Haskell's more closely.) All in all, I think that the new syntax looks pretty nice, and the ability to mix lhs with rhs qualifiers allows you to handle the most common usage cases without having to resort to some kind of nested "case structures" which tend to be harder to read (YMMV, of course). -- Another side note, and request for comments about "qualifier" vs. "guard": AFAICS, the term "qualifier", which I use as an umbrella term for both 'if' and 'where' clauses, is one of the few remaining original "Q'isms" in the manual. Maybe the term "guard" would be more common/appropriate there? And should I better use "guarded equations" instead of "conditional equations"? (This latter term actually comes from term rewriting theory, so it's not my invention.) Yes, I'm old enough to still remember the fate of Algol 68 whose designers made up all kinds of weird names for common things. ;-) Of course, mathematicians tend to invent their own jargon as they need it, but I realize that if there's a well-established term for a certain notion then it should be used to avoid confusion. Cheers, 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 |