On 03/07/2011 09:26 AM, Russel Winder wrote:
On Sun, 2011-03-06 at 20:23 -0500, bearophile wrote:
[ . . . ]
I wonder if you may have misunderstood the reason for the where clause
in functional languages such as Haskell and ML (usually OCaml). In
these languages the body of a function must be a single value-returning
expression. This means there has to be a separate clause for all the
declarations of the single-assignment variables -- caveat the use of
monads
I know about nothing of Haskel and ML languages, but in Lisp-like ones there
are explicite forms for statement sequences (eg 'begin' form in Scheme). Also,
numerous special forms are implicitely sequential (eg func def or cond in Lisp
& Scheme), but not all (eg if). Thus, one can construct super-expressions in
imperative-like style. But this is not considered good style, indeed.
do {
auto r = map!(sqr)(items);
} where {
int sqr(int x) pure nothrow {
return x * x;
}
}
What's wrong with:
{
auto sqr = function int ( int ) { return x * x ; } ;
auto r = map ! ( sqr ) ( items ) ;
}
Seems idiomatic and straightforward with less noise?
Right. But this does not make any distinction between logical sequence and
construction sequence. A construction sequence can always, conceptually, be
(re)composed into a single complex expression. Hope I'm clear ;-)
Logically, the above indeed reads: "r is a mapping of sqr on items, where sqr
is...". Compare with:
this.update(); // effect on state
return this.filter(pred);
[...]
[OT]
PS I have begun to dislike languages that use semi-colon as a statement
terminator! (It took me 4 attempts to get my two line example to
compile :-((
(Why 4? There are only 2 ';' there.)
Lol! You're not the only one. 66% of my syntax errors are missing ';' (33% are
using '=' instead of '==' in unittest asserts, even after years of python & Lua
who inherited the same stupid operators).
See also: http://www.dwheeler.com/readable/sweet-expressions.html for an
example of trying to get rid of () noise in Lisp.
Indented D would be a great language, visually: no more {} and ';'. Then, we
could reuse {} for something else (eg set & aa literals, or template params).
We would certainly find a nice use for ';'. Using '=' for equality and eg ':='
for assignment, D would then be close to perfect in terms of base syntax ;-).
[/OT]
Denis
--
_________________
vita es estrany
spir.wikidot.com