Re: [q-lang-users] where
Brought to you by:
agraef
From: Eddie R. <ed...@bm...> - 2006-10-09 21:13:13
|
Dr. Graef and (Mr? Dr?) Hubbard, Of all of the functions in mathematics that I've ever seen, if a "where clause" is given at the end of a piecewise function, the variables and/or functions denoted by "where" are global to all of the "pieces." In Q's case it is very similar to f x = cond (Condition1, Expression1 with A; Condition2, Expression2 with A; Condition3, Expression3 with A; ... ConditionN, ExpressionN) where A = ...; However, a local "where clause" for each equation is a handy feature of Q. In math books and papers, symbols are usually defined with "Assume ..." or "Let ..." and then go on to define a function based on the those symbols. That is why I put a "letting" statement where I did (Although Mr. Hubbard's use of where looks better). Perhaps maybe: let N = #S - 1; strip C S = strip C $ sub S 0 (N-1) if (S!N = C); = ... or This might mess things up since "let N" looks like any other equation. Making "let" a keyword might be a solution, but, then again, since "let N" looks like any other equation, it doesn't stand out and might get lost in larger definitions. Another idea, so that wheres are nested: f X Y Z where A = ... ; // global to all equations belonging to f = ...; = ...; where B = ... ; // global to all equations below this and belonging to f = ...; = ...; where C = ... where D = ...; = ...; Eddie > Rob Hubbard wrote: >> Perhaps the "where" (and even "if" for a common conditional) keywords >> could be used for the "letting" clauses (assuming the grammar doesn't >> then become ambiguous, and assuming the language can be extended >> consistently in this way). > > Yes, this could be done. Looks a bit weird, though: > > strip C S where N = #S-1 > = strip C $ sub S 0 (N-1) if (S!N = C); > = strip C $ sub S 1 N if (S!0 = C); > = S otherwise; > > Maybe we can invent a syntax that better mimics the way that > mathematicians actually write these things? > > Also, you might then want to nest those shared definitions. E.g., have > another shared variable which is only defined for the second and third > equation. I don't see how this can be done in a free-format language > without introducing some form of bulky begin ... end brackets. > > Of course there's an existing solution to this, namely Haskell's guarded > equation syntax, but that also looks fairly messy IMHO. Oh well, I guess > I'll have to take another look at Miranda to see if Turner already > solved that problem. > > -- > 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 > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > q-lang-users mailing list > q-l...@li... > https://lists.sourceforge.net/lists/listinfo/q-lang-users > |