Folks more knowledgable than me, correct me if I'm wrong but

$seq[n] is shorthand for $seq[posn() = n]

which is why something like

(1 to 10)[xdmp:random(9) + 1] can yield counter-inituitive results.

The above would imply that short-circuiting as described is therefore not 
consistent with required behavior.

How about

fn:head((1,xdmp:sleep(1)))

to solve this though?

The sleep doesn't show up when I profile.

fn:head(((),2))

Yields expected results.

fn:head new at 6.0

From: [email protected] 
[mailto:[email protected]] On Behalf Of Jakob Fix
Sent: 11 April 2013 08:07
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] (foo(), bar())[1]: is bar() evaluated if 
foo() exists?

Hi, I was kind of hoping that this might be an occasion to use xdmp:eager() but 
wrapping Michael's test case in it doesn't change the time spent at all.
BTW, what's the use case for xdmp:eager(), the documentation is a bit 
"xdmp:lazy()" about it ;-)

cheers,
Jakob.

On Wed, Apr 10, 2013 at 11:40 PM, Geert Josten 
<[email protected]<mailto:[email protected]>> wrote:
Hi Tim,

I think it is like it is, because MarkLogic will probably attempt to
evaluate both functions in parallel, which makes short circuiting
difficult. But I would think that the optimizer should be able to detect
such (.., ..)[1] tricks very easily, and be able to prevent that. Perhaps
file an RFE at support?

Cheers from Vegas,
Geert

> -----Oorspronkelijk bericht-----
> Van: 
> [email protected]<mailto:[email protected]>
>  [mailto:general-<mailto:general->
> [email protected]<mailto:[email protected]>] 
> Namens Tim Finney
> Verzonden: donderdag 11 april 2013 5:42
> Aan: MarkLogic Developer Discussion
> Onderwerp: Re: [MarkLogic Dev General] (foo(), bar())[1]: is bar()
evaluated
> if foo() exists?
>
> Hi Michael,
>
> Thanks for that succinct demonstration.
>
> It would be a Good Thing if we could use the [1] trick knowing that it
> would shortcircuit.
>
> Best,
>
> Tim Finney
>
> On 04/11/2013 11:38 AM, Michael Blakeley wrote:
> > Not in my 6.0-2.3 environment.
> >
> > declare function local:foo() {
> >    1
> > };
> >
> > declare function local:bar() {
> >    xdmp:sleep(1000),
> >    2
> > };
> >
> > (local:foo(), local:bar())[1],
> > xdmp:elapsed-time()
> > =>
> > 1
> > PT1.001195S
> >
> > The profiler shows the xdmp:sleep too. So I only use the [1] trick
when I
> don't care about performance.
> >
> > -- Mike
> >
> > On 10 Apr 2013, at 20:08 , Jason Hunter 
> > <[email protected]<mailto:[email protected]>>
> wrote:
> >
> >> It shortcuts out like you want.
> >>
> >> Sent from my iPhone
> >>
> >> On Apr 10, 2013, at 7:53 PM, Tim Finney 
> >> <[email protected]<mailto:[email protected]>> wrote:
> >>
> >>> Hi All,
> >>>
> >>> (foo(), bar())[1]
> >>>
> >>> can be used instead of
> >>>
> >>> if (exists(foo())) then foo() else bar().
> >>>
> >>> But does MarkLogic evaluate bar() if I use the (foo(), bar())[1]
> >>> construct and foo() exists? I'm interested to know because bar()
could
> >>> take a long time to evaluate.
> >>>
> >>> Best,
> >>>
> >>> Tim Finney
> >>> _______________________________________________
> >>> General mailing list
> >>> [email protected]<mailto:[email protected]>
> >>> http://developer.marklogic.com/mailman/listinfo/general
> >> _______________________________________________
> >> General mailing list
> >> [email protected]<mailto:[email protected]>
> >> http://developer.marklogic.com/mailman/listinfo/general
> >>
> > _______________________________________________
> > General mailing list
> > [email protected]<mailto:[email protected]>
> > http://developer.marklogic.com/mailman/listinfo/general
>
> _______________________________________________
> General mailing list
> [email protected]<mailto:[email protected]>
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to