[Issue 9926] Add the `let` function.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 14 15:28:37 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9926



--- Comment #3 from IdanArye <GenericNPC at gmail.com> 2013-04-14 15:28:32 PDT ---
(In reply to comment #2)
> In Haskell I prefer to use "where". The top-down approach offered by "where"
> feels more clear to me.

Well, it's a matter of both taste and circumstances, but the problem with
`where` is that the name is used *before* it is declared.

Why is that a problem? Because in D(like in many other languages) you need to
declare variables before you use them - unless you go out of the imperative
part and into the declarative part, which is not the case here.

So, lets say we want to bind VALUE to NAME for the duration of BODY. In
Haskell, we could use `let`:
    let NAME = VALUE in BODY
or we could use `where`:
    BODY where NAME = VALUE
Both are elegant.

Now, if we remove the keywords, we get either NAME VALUE BODY or BODY NAME
VALUE. My original goal was to keep the order of NAME VALUE BODY, but I
couldn't do it without changing the language itself. When you write a lambda,
you need to write the NAME and then immediately the BODY, so it must be either
VALUE NAME BODY(which I picked for my function) or NAME BODY VALUE, which would
just look weird:
   where!(NAME => BODY)(VALUE)
(which, BTW, you could also do with `let`, and it will still look weird).

Ofcourse, you could use mixins to implement `where` in the correct order - but
then you will loose the closure...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list