help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: if vs. when vs. and: style question


From: Rusi
Subject: Re: if vs. when vs. and: style question
Date: Tue, 24 Mar 2015 19:35:53 -0700 (PDT)
User-agent: G2/1.0

On Wednesday, March 25, 2015 at 5:47:31 AM UTC+5:30, Emanuel Berg wrote:
> Rusi  writes:
> 
> > In general weaker is better
> > http://www.w3.org/2001/tag/doc/leastPower.html
> >
> > (when a b) ... (if a b) However (if a b c) ... (when ??)
> 
> What do you mean by "weaker"?

[At the risk of being over-simplistic...]
Weaker means less flexible

Maybe this link is more programmer-oriented than the earlier (web-oriented) one
http://blog.higher-order.com/blog/2014/12/21/maximally-powerful/

> 
> `if' can do three arguments, on the other hand it
> needs a `progn' to do several forms. `when' comes with
> implicit progn but cannot do the three way
> if-else if-else branch.
> 
> What I can see `if' is more flexible and you can
> change things without having to change the outermost
> `if', which is practical. Yes, with the use of `not'
> and `progn' if necessary, but I don't see a problem
> with that.
> 
> > Other example:
> >
> > destructuring-bind is strictly weaker than if/cond
> > and so better when usable
> 
> What is "destructuring-bind"?

I guess not a very good example.

Pattern-matching in modern FPLs would be more appropriate

foo [] = bla
foo (x:xs) = ble

Can always be translated into

foo l = if null l then bla else ble

The reverse is of course not always possible
But when pattern matching works its preferable to 'all-powerful' if-then-else

Notice also that pattern matching is a mix of 3 features that are usually 
separate -- 1. if 2. let 3. car/cdr ie selectors
Separately those 3 are strictly more powerful than pattern matching
And thats what makes pattern matching preferable (when it applies)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]