xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

Just a simple question about Junction:
Could I know which elements matched?
Update:

Sorry for my bad English skill. I will emation my question clear as possible as I could
I've install Perl6::Junction today. and read - "The Wonderful World of Junctions" again and again.
Yes, Junction is a wonderful operator. But It looks to me that example in Exegesis6 is too simple to grasp its essential. For example:
if $dave == any(1,4,9) { print "I'm sorry, Dave, you're just a square." }
pretty good and concise! But how can I know $dave is equal to which element? I can't find answer from that section.Is there a way to find that element? That's why I post.

Any reply are appreciated!


I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Replies are listed 'Best First'.
Re: Juction question
by erroneousBollock (Curate) on Oct 31, 2007 at 03:24 UTC
    Do you mean that you wish to know which element in an any() disjunction has matched in a test (==, >=, etc) or smart match ? Exegesis 6 explains the rules pretty well.

    I can't find any documentation that suggests a trace is left of which element in a disjunction has short-circuited (succeeded). Have a look at the source for Perl6::Junction::Any; it's fairly instructive.

    Update:

    For example:

    if $dave == any(1,4,9) { print "I'm sorry, Dave, you're just a square." }

    pretty good and concise! But how can I know $dave is equal to which element?

    As I said, you probably can't. That's not what it's for.

    I guess you're thinking about the disjunction in terms of a captured set of regexp alternatives where you can figure out which alternative matched while accepting any of the alternatives... Junctions don't really work that way; as I suggested, have a look at the Perl6::Junction::Any code.

    Also, to understand the concept more generally, take a look at Quantum::Superpositions.

    -David

      I guess you're thinking about the disjunction in terms of a captured set of regexp alternatives where you can figure out which alternative matched while accepting any of the alternatives... Junctions don't really work that way; as I suggested, have a look at the Perl6::Junction::Any code. Also, to understand the concept more generally, take a look at Quantum::Superpositions.

      Thanks for your insightful reply! It looks I misunderstood usage of disjunction. Thanks! Researching Quantum seems a good way to understand junction in general.
Re: Juction question
by Gangabass (Vicar) on Oct 31, 2007 at 03:54 UTC

    Hm... What you mean by junction?

    Show your code so we can help you.

        Thanks!