Re: Google index and subsets (two topics for the price of one!)

2008-06-15 Thread TSa

HaloO,

Ovid wrote:

In other words, I think we could get proper constraint programming if a
subset can mutate its variable.  Otherwise, all assignment would need
to be wrapped inside of an eval and the code would be more bug-prone.


I must admit that I hardly follow that statement. Why are side-effects
essential to achieve constraint programming and why do you think that
the way to get at the constraint programming paradigm are the subset
type definitions? E.g. to get constraint programming as I know it from
Oz, Perl 6 would need a single assignment store first of all. And then
a heavy re-assignment of semantics to things like '$x = $y' which would
become a symmetric assertion instead of asymmetric, imperative
assignment.



Will said mutating work?  If it does, all logic handling constraints
can be encapsulated in one spot.  On the other hand, this could lead to
mysterious action at a distance.  The losses are significant, but the
wins seem absolutely fascinating.


Could you give some hints on these fascinating wins, please. I for
my part would argue the where blocks to be a very constraint form of
block that generally has type :(Object --> Bool) and doesn't alter
the object of concern in any way. Note that the where blocks are
executed from within the type-checker or the dispatcher where no
assumptions of the call environment other then the object should
be made.


Regards, TSa.
--

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan


Re: Google index and subsets (two topics for the price of one!)

2008-06-15 Thread TSa

HaloO,

Daniel Ruoso wrote:

In fact, I doubt that there's a way to completely avoid any possible
side effects on this closures. as the very first line of the closure
shows:
 
   $_.inside_of(...)


This is a plain method call, there's no way to tell if this method will
change anything inside the object or not.


Well, we could use something to the effect of const methods in C++.
That is we have a trait on a method that prevents changes of the
object. And these could be the only ones allowed in where blocks.



It's important to remember that, in Perl 6, something is only guaranteed
to be fully executed before the next statement when using short-circuit
operators, everything else is subject to eventually be made lazy, with
the exception of the feed operators, that explicitly say to assume lazy
behaviour.


So, no C++ sequence points or the like at all in the definition of
Perl 6?


Regards, TSa.
--

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan


Re: assignable mutators (S06/Lvalue subroutines)

2008-06-15 Thread TSa

HaloO,

David Green wrote:
I would expect all of those to work the same way in either case.  That 
is, anywhere the sub is used as an lvalue, it could pass the rvalue as a 
special arg, not just when using "=".


I agree. But I want to stress that the big thing is that a lvalue
sub---and to a lesser degree also postcircumfix .[] and .{}---wants
to see its own parameters *and* the rvalue to be assigned.
This data must in general be woven into the control flow of the
sub invocation. That is, when returning a proxy doesn't cut the
whole intension we need something along my yield statement that
joins the functionality of a declarator for a variable to return
as lvalue and capturing the current invocation for later resumption.


OK; but I think that can be handled by a mutating sub -- assuming the 
issue is that the proxy-sub "sub foo is rw { blah; $proxy }" runs "blah" 
once and returns the proxy that can be assigned to multiple times,


I would prefer to switch back into the sub invocation whenever it is
used in lvalue context. Abandoning control by returning a passive
proxy jumps too short in my eyes.


whereas a mutating sub would run "blah" every time you use it.  But:


Hmm, in a statement like

  foo(1,2) = 3;

the assignment is the operator that sees both sides involved in the
assignment. And I think it will be the one that other assignment forms
like += and ++ dispatch to unless specifically overridden. My idea is
that foo sees the 1 and 2 as args and prepares itself for rvalue or
lvalue use later in the dispatch. For rvalue use the halted invocation
is garbage collected but in lvalue context the invocation is resumed
by the assignment. This is the point in time when foo "knowns" that
it is in lvalue context and the rvalue 3 is available to the sub as
well. This is a bit like the fork system call where the parent and
child branch into different parts of the code.

sub foo is rw($rval) { unless want~~:($ is rw) { blah }; 
$unproxy=$rval; }


In other words, the mutating-sub-way can do everything the proxy-way can 
(and more), as long as we can tell when being used in lvalue-context.


I think my yield proposal handles all that fine. And it is a more
general concept that is used for coros as well.



Incidentally, now that Perl is all OO-y, do we need tying/proxying like
that, or can we just override the "=" method on a class instead?
It's possible that in perl6, 'STORE' could be spelled 'infix:<=>'; but 
then how would 'FETCH' be spelled?  And doing so would require that 
your storage routine return a value, even if you never intend to use 
it.  No; I prefer 'STORE' and 'FETCH' as the basic building blocks of 
anything that's capable of working like a rw item.


How would the syntax for STORE and FETCH look like in a sub
definition and how would it be related to the invocation involved
in the operation? Note that I make the conceptual unifications
of class and sub definition on the one hand and an object and an
invocation on the other. In the object case the self built-in refers
to the object. Would that work in a STORE or FETCH block of a sub
as well?


Regards, TSa.
--

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan