lvalue subroutines

2001-02-27 Thread Ian Brayshaw

Hi,

Given the following lvalue subroutine

sub mysub : lvalue {
$value;
}

is there any way for mysub() to be able to determine that it
was called in an lvalue context?


Ian (New face on london-pm: usually wears an over-the-top suit.)
_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.




Re: lvalue subroutines

2001-02-27 Thread Piers Cawley

"Ian Brayshaw" [EMAIL PROTECTED] writes:

 Hi,
 
 Given the following lvalue subroutine
 
   sub mysub : lvalue {
   $value;
   }
 
 is there any way for mysub() to be able to determine that it
 was called in an lvalue context?

No. If you need to know that sort of thing, you kind of have to tie
the $value that you're going to return, and use that as a proxy for
the *actual* value. If you're called in an lvalue context then the
tied object is going to have its STORE method called...

-- 
Piers




Re: lvalue subroutines

2001-02-27 Thread Ian Brayshaw

Ian Brayshaw" [EMAIL PROTECTED] writes:

  Hi,
 
  Given the following lvalue subroutine
 
  sub mysub : lvalue {
  $value;
  }
 
  is there any way for mysub() to be able to determine that it
  was called in an lvalue context?

No. If you need to know that sort of thing, you kind of have to tie
the $value that you're going to return, and use that as a proxy for
the *actual* value. If you're called in an lvalue context then the tied 
object is going to have its STORE method called...

--
Piers

Thanks.

I'm new to the discussion of Perl6, so are there any discussions around 
providing operators such as wantlvalue and wantvoid
to perform similar queries to wantarray?


Ian
_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.




Re: lvalue subroutines

2001-02-27 Thread Robin Houston

On Tue, Feb 27, 2001 at 11:38:40PM +1100, Ian Brayshaw wrote:
 
 I'm new to the discussion of Perl6, so are there any discussions around 
 providing operators such as wantlvalue and wantvoid
 to perform similar queries to wantarray?

Yes. Damian has proposed
 http://dev.perl.org/rfc/21.html

which seems sufficiently generic

 .robin.


PS:  You know that "wantvoid" is just !defined(wantarray())
 ?



Re: lvalue subroutines

2001-02-27 Thread Ian Brayshaw

Robin Houston wrote:
On Tue, Feb 27, 2001 at 11:38:40PM +1100, Ian Brayshaw wrote:
 
  I'm new to the discussion of Perl6, so are there any discussions
  around providing operators such as wantlvalue and wantvoid
  to perform similar queries to wantarray?

Yes. Damian has proposed
   http://dev.perl.org/rfc/21.html

which seems sufficiently generic

Cool.


PS:  You know that "wantvoid" is just !defined(wantarray()) ?

ah, yes, RTFM...


Ian
_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.




Re: lvalue subroutines

2001-02-27 Thread Robin Houston

On Tue, Feb 27, 2001 at 10:50:26PM +1100, Ian Brayshaw wrote:
 Given the following lvalue subroutine
 
   sub mysub : lvalue {
   $value;
   }
 
 is there any way for mysub() to be able to determine that it
 was called in an lvalue context?

Yeah there is, but you're not going to like it :-)

 .robin.

use v5.6;
use Inline C = NOMO;

U8 wantlvalue ()
{
  return cxstack[cxstack_ix].blk_sub.lval;
}

NOMO

sub foo :lvalue {
  print (wantlvalue() ? "lvaluably\n" : "rvaluably\n");
  my $foo
}

foo();
foo() = 23;




Re: lvalue subroutines

2001-02-27 Thread Piers Cawley

Robin Houston [EMAIL PROTECTED] writes:

 On Tue, Feb 27, 2001 at 10:50:26PM +1100, Ian Brayshaw wrote:
  Given the following lvalue subroutine
  
  sub mysub : lvalue {
  $value;
  }
  
  is there any way for mysub() to be able to determine that it
  was called in an lvalue context?
 
 Yeah there is, but you're not going to like it :-)

Oh! Yes! Baby!!! 

That's almost as good as ()^0.5.

-- 
Piers, who confesses that he did find himself wondering what (-)^0.5
would do (that's 'square root of - not' BTW)





Re: lvalue subroutines

2001-02-27 Thread David Cantrell

On Tue, Feb 27, 2001 at 01:46:49PM +, Piers Cawley wrote:

 That's almost as good as ()^0.5.

I was thinking about that on the way to work.

AIUI, square roots apply to numbers, so how can you have a square root of
something that isn't a number, like an operator?  You may as well say that
you can take the square root of anything - like the square root of equals,
or the square root of a pony.

Calling that thing the square root of an operator is a bit misleading to
say the least.  OK, it may appear to have some properties of a square root
operation, but a square root it ain't.

YMMV, cos IANAQM (but it would be helpful in debugging landrovers)

-- 
David Cantrell | [EMAIL PROTECTED] | http://www.cantrell.org.uk/david/

   Any technology distinguishable from magic is insufficiently advanced

** I read encrypted mail first, so encrypt if your message is important **

 PGP signature


Re: lvalue subroutines

2001-02-27 Thread Ian Brayshaw

On Tue, Feb 27, 2001 at 10:50:26PM +1100, Ian Brayshaw wrote:
  Given the following lvalue subroutine
 
  sub mysub : lvalue {
  $value;
  }
 
  is there any way for mysub() to be able to determine that it
  was called in an lvalue context?

Yeah there is, but you're not going to like it :-)

... omitted for sanity ...

Thank goodness for TMTOWTDI (i.e. if in doubt, rewrite the problem)

Cheers.
_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.




Re: lvalue subroutines

2001-02-27 Thread Rob Partington

In message [EMAIL PROTECTED],
David Cantrell [EMAIL PROTECTED] writes:
 AIUI, square roots apply to numbers, so how can you have a square root of
 something that isn't a number, like an operator?  You may as well say that
 you can take the square root of anything - like the square root of equals,
 or the square root of a pony.

I think sqrt(not) only works because it cancels itself out much the same
as sqrt(-1) does.  Other things don't have the toggle-nature, so wouldn't
make sense.
-- 
rob partington % [EMAIL PROTECTED] % http://lynx.browser.org/



Re: lvalue subroutines

2001-02-27 Thread Piers Cawley

David Cantrell [EMAIL PROTECTED] writes:

 On Tue, Feb 27, 2001 at 01:46:49PM +, Piers Cawley wrote:
 
  That's almost as good as ()^0.5.
 
 I was thinking about that on the way to work.
 
 AIUI, square roots apply to numbers, so how can you have a square root of
 something that isn't a number, like an operator?  You may as well say that
 you can take the square root of anything - like the square root of equals,
 or the square root of a pony.
 
 Calling that thing the square root of an operator is a bit misleading to
 say the least.  OK, it may appear to have some properties of a square root
 operation, but a square root it ain't.

I have to disagree. Part of the power of mathematics comes from
looking at something, seeing that it works like something else,
proving that, and then continuing to call it something else because
that then gives you all the stuff you know about the 'something else'.

And 'square root' is just an operation on something. If you can
meaningfully do that operation to something that isn't a number (and
in the maths associated with QM, obviously, you can) then go for it.

(I not that, in the slide, ()^0.5 is refered to as U_SRN. Presumably
because the idea gives the mathematicians headaches too, so they hide
it slightly behind another symbol)

-- 
Piers




SRN (was: lvalue subroutines)

2001-02-27 Thread Robin Houston

On Tue, Feb 27, 2001 at 02:39:35PM +, Piers Cawley wrote:
 (I note that, in the slide, ()^0.5 is refered to as U_SRN. Presumably
 because the idea gives the mathematicians headaches too, so they hide
 it slightly behind another symbol)

Apparently SRN stands for "Square Root of Not", so they're not hiding
it too much.

http://www.qtc.ecs.soton.ac.uk/lecture1/lecture1d.html
is interesting.

I agree about generalisation. I think it's perfectly reasonable
to call such an operator the "square root of not" in context;
as long as you understand that by the same definition, adding
one is the "square root" of adding two ;-)

 .robin.

-- 
"Do nine men interpret?" "Nine men," I nod. 



Re: SRN (was: lvalue subroutines)

2001-02-27 Thread David Cantrell

On Tue, Feb 27, 2001 at 02:50:22PM +, Robin Houston wrote:

 http://www.qtc.ecs.soton.ac.uk/lecture1/lecture1d.html
 is interesting.

My brain just started leaking out of my ears.

-- 
David Cantrell | [EMAIL PROTECTED] | http://www.cantrell.org.uk/david/

   Any technology distinguishable from magic is insufficiently advanced

** I read encrypted mail first, so encrypt if your message is important **

 PGP signature


Re: SRN (was: lvalue subroutines)

2001-02-27 Thread Robin Houston

I've also found
 http://www.sigmaxi.org/amsci/issues/comsci95/compsci95-07.html
 "The Square Root of NOT"

which seems to be a good non-experts introduction to *real* QC.

 .robin.



Re: lvalue subroutines

2001-02-27 Thread Jonathan Stowe

On Tue, 27 Feb 2001, Ian Brayshaw wrote:

 Ian Brayshaw" [EMAIL PROTECTED] writes:
 
   Hi,
  
   Given the following lvalue subroutine
  
 sub mysub : lvalue {
 $value;
 }
  
   is there any way for mysub() to be able to determine that it
   was called in an lvalue context?
 
 No. If you need to know that sort of thing, you kind of have to tie
 the $value that you're going to return, and use that as a proxy for
 the *actual* value. If you're called in an lvalue context then the tied
 object is going to have its STORE method called...
 

 I'm new to the discussion of Perl6, so are there any discussions around
 providing operators such as wantlvalue and wantvoid
 to perform similar queries to wantarray?


wantarray will tell you if you are in a void context - IIRC correctly it
returns undef in void context and 0 in scalar context I also recall there
being a little controversy over this recently in p5p ...

/J\
-- 
Jonathan Stowe   |
http://www.gellyfish.com |   I'm with Grep on this one
http://www.tackleway.co.uk   |