Phobos PR: `call` vs. `bindTo`
Idan Arye via Digitalmars-d
digitalmars-d at puremagic.com
Wed Aug 6 02:55:48 PDT 2014
On Tuesday, 5 August 2014 at 22:25:53 UTC, Daniel Gibson wrote:
> Am 06.08.2014 00:17, schrieb Idan Arye:
>> On Tuesday, 5 August 2014 at 21:10:25 UTC, Tofu Ninja wrote:
>>> Can you explain the utility of both of them? I am not big into
>>> functional programming so I am not seeing it.
>>
>> The purpose of `bindTo` is to emulate the `let` expressions
>> found in
>> many functional languages (see
>> http://en.wikipedia.org/wiki/Let_expression). The idea is to
>> bind a
>> value to a name for the limited scope of a single expression.
>>
>> Note that `bindTo` could be implemented as:
>>
>> alias bindTo = std.functional.unaryFun;
>>
>> and I'll probably change the implementation to this if this PR
>> will be
>> chosen. The reason I think `bindTo` is needed even if it's
>> just an alias
>> to `unaryFun` is that `bindTo` conveys better that the you are
>> binding a
>> name to a value, not just overcomplicating the code.
>
> And my impression (in lisp/clojure) was, that let emulates
> (named) variables of imperative languages :P
>
> Cheers,
> Daniel
That's partially true. While `let` can be used to emulate named
variables, it carries it's own weight - enough for many
functional languages to have both `let` and regular variable
declarations.
Take a look at this Scheme example - http://repl.it/WVU - It
shows both regular variable declaration with `define` and a `let`
expression. `(define x 12)` declares("binds") `x` for the scope
it was written in - the entire scope of `foo`. The `let`
expression creates a new scope and binds `y` in it.
Clojure doesn't have regular variable binding(`def` always uses
the global scope, even if you use it inside a function) so you
have to use `let` to emulate it, though `let` is still used for
it's original purpose - which I think is useful enough for Phobos
to have it.
More information about the Digitalmars-d
mailing list