Re: [q-lang-users] Special values or failing functions
Brought to you by:
agraef
From: Alexander N. <AN...@sp...> - 2007-05-17 17:00:24
|
Hello Tim, Thursday, May 17, 2007, 12:19:18 PM, you wrote: TH> Might () be appropriate? Great idea. While [] could be a 'proper' answer sometimes, empty tuple is never a value. TH> As a bonus idea, can you seek to work with lists more, thereby allowing a TH> filter (<>()) expression as a tidy-up phase (before or after getmax-ing)? In fact, I already changed the dist. Now it returns list of distances, the whole path from A to B and [] is a valid failure designator - it means 'no path found' AG> but IMHO it just doesn't AG> seem to fit the rewriting model very well, where each equation is AG> considered a separate entity. Well, for me it's just a shortcut and it is always clear where it belongs to. The only problem is existing code which may use global variables with the same name. AG> I was talking about an operation which AG> bails out of the current reduction, not a general-purpose sentinel value AG> to be returned by a function. AG> Alexander, I think that this is what you wanted, right? Well, maybe. Here's how I see it : length [] = 0; length [H|T] = _FAIL_ if (islist H); = 1+length T otherwise; but also look at : len [] = 0; len [[H|Hs]|T] = _FAIL_; len [H|T] = 1+len T; so semantics of _FAIL_ would be : rewrite the current match with itself and return. So, 'fail' applies to the left side, but _FAIL_ applies to the right side. no matter how you call it - reject, normal, agree, refuse - which strangely means the same. Each time I am learning a new language I am thinking about how I would implement it. It helps understanding and in fact it is the only time when I can think about it. When I am already used to a language I just use it. For example (X+Y)*Z = X*Z+Y*Z; X*(Y+Z) = X*Y+X*Z; is good, but X+Y = Y+X; // commutative rule will not work. -- Best regards, Alexander mailto:AN...@sp... |