[xquery-talk] a conceptual clarification
Michael Rys
mrys at microsoft.com
Fri Mar 4 06:31:27 PST 2005
It is not quite the same. Variables in declarative/functional languages
are different from imperative/procedural languages; especially inside an
iterator.
Whether variables should be redeclarable is kind of a religious issues
among the functional language crowd (well, variables are). I think that
re-assignment is ok if people understand the functional processing
paradigm. But since many currently do not understand it and since the
W3C has not closed the spec yet, I am leaning towards erroring now and
relaxing the error later...
Best regards
Michael
> -----Original Message-----
> From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On
Behalf
> Of Bas de Bakker
> Sent: Friday, March 04, 2005 4:41 AM
> To: Amitabh Ojha
> Cc: talk at xquery.com
> Subject: Re: Re : [xquery-talk] a conceptual clarification
>
> Shadowing a variable with another variable with the same name is
> possible in many languages, including Java. It is also generally
> confusing and therefore considered bad practice (although I do not
agree
> that it should be disallowed). In this respect there is nothing
special
> about XQuery.
>
> I fail to see why you would consider using a let statement within a
for
> statement to be confusing, nor do I see a better alternative. This is
> just like
>
> for (int i = 0; i < n; ++i) {
> Object object = a[i];
> // Use object
> }
>
> in Java, which is an extremely common way of programming in many
> languages.
>
> Regards,
> Bas de Bakker
>
>
> Amitabh Ojha wrote:
> > Dear Sir,
> >
> > It has been a very useful exchange of messages/ replies from
experts on
> > this theme. However, no discussion has taken place as yet on one
point
> > which I had flagged earlier. I elaborate it here.
> >
> > It is evident now that it is a bad practice to have two let
> > statements, one after the other, define a variable with the same
name,
> > as is cited in the following example (even if it is not illegal
as
> > per XQuery Specs)
> >
> > let $x := ......
> > let $x := ......
> >
> > Following from this, will it be correct to assume that the
appearance
> > of a let statement after a for statement be also treated as equally
> > undesirable and error-prone programming technique in XQuery (because
in
> > course of iteration, a let statement is then forced to rebind the
> > same variable name say $x several times, probably forcing it to
bind to
> > a new value each time). I cite two examples here. In case of
my:foo ()
> > the result is same as one would expect in Java i.e 1, 2, 3, 4, 5.
But
> > in case of my:bar () we get 101, 102, 103, 104, 105 - this is not
what
> > a Java programmer will expect (although in XQuery context one knows
why
> > it is so).
> >
> > declare function my:foo ()
> > {
> > for $i in (1 to 5)
> > let $x := $i
> > return $x
> > };
> >
> > declare function my:bar ()
> > {
> > let $x := 100
> > for $i in (1 to 5)
> > let $x := $x + $i
> > return $x
> > };
> >
> > Regards.
> >
> > Amitabh Ojha
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xquery.com/pipermail/talk/attachments/20050304/32f34777/attachment-0001.htm
More information about the talk
mailing list