develooper Front page | perl.perl6.language | Postings from March 2005

Re: Questions regarding s/// and subst?

Thread Previous | Thread Next
From:
Larry Wall
Date:
March 23, 2005 10:43
Subject:
Re: Questions regarding s/// and subst?
Message ID:
20050323184235.GA1179@wall.org
On Wed, Mar 23, 2005 at 11:14:16AM -0500, Stevan Little wrote:
: Is subst an object/type?
: Or is it a method of the Str object?

I suspect it's just a method, and the ~~ binding of s/// is merely
syntactic sugar for the method call.

: If it is an object ...
: 	
: 	Does s/// produce a subst object?
: 	Does a subst object .hasa rule object(s)?
: 		If so can we extract those rule object(s) from it?
: 	What exactly does a subst object do?
: 	How does a subst object stringify?
: 	Etc. etc. etc.

I think if you want to objectify a subst, you have to put it in a closure.

: If it is a method ...
: 	
: 	How would a method on the right hand side of ~~ work exactly?
: 	Is
: 		~~ s:perl5:g/a/b/
: 	the same as
: 		~~ .subst(rx:perl5/a/, "b")
: 	or
: 		~~ .subst(rx:perl5/a/, {"b"})

This is very much bound up in the meaning of .foo in various contexts,
which we haven't actually nailed down yet.  For the moment I would
recommend writing all code with explicit $self.foo or $_.foo until
we figure that out.  I rather suspect that .foo is going to end up
always meaning the current invocant rather than current topic.

It's also vaguely possible certain kinds of {...} constructs could
be construed as methods rather than subs so that $_ ends up being
the invocant in that scope.  There are problems with that, though.
The solution might turn out to be unary ~~ instead, where ~~subst()
binds the current topic to subst in some kind of topically appropriate
fashion which may or may not involve the first argument depending on
the declaration of subst, which might or might not degenerate to a
method call of the form $_.subst() if there's no other obvious binding
to $_.

[Followups to p6l.]

Please be a little patient--I'm still dripping this whole mess through
my Pooh filter, which clogs easily.

Larry

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About