call, call(), .call, and captures

From S06:

       sub bar ($a,$b,$c,:$mice) { say $mice }
       sub foo (\$args) { say $args.perl; &bar.call($args); }

   The C<.call> method of C<Code> objects accepts a single C<Capture>
   object, and calls it without introducing a C<CALLER> frame.

And from S12:

   In addition to C<next METHOD>, the special function C<call> dispatches
   to the next candidate, possibly with a new argument list:

       call;           # calls with the original arguments
       call();         # calls with no arguments
       call(1,2,3);    # calls with a different set of arguments

And back in S06:

   The entire argument list may be captured by the C<\$args> parameter.
   It can then be passed to C<call> as C<[,] =$args>:

       # Double the return value for &thermo
       &thermo.wrap( -> \$args { call([,] =$args) * 2 } );

The inconsistency between these three things called "call" is vexing to 
me.  One is a method and takes a capture and only a capture. The second is 
a special function and takes an argument list, but also has a special 
arglistless form that passes on the original arguments.  The third is a 
function that takes only a function list, but apparently lacks a 
arglistless form (otherwise, why bother with capturing an arglist in the 
example?).

I believe the current spec works.  I just think the inconsistency is 
bad--the three things called "call" do very similar things, but take 
completely different arguments.  I suspect this is just historical smear 
and we just need to back up and normalize.

(Let me quickly note here that I don't think it's possible to write a 
subroutine or method that can take either a bare argument list or a 
Capture and treat them the same, because of the intractable ambiguity that 
would arise in the case of an argument list that actually contains a 
single capture as its only positional element.  If I'm mistaken, then 
other avenues open up.  But I don't think I am.)

Audrey confirmed to me on IRC that the motivation for the arglistless form 
was that passing on the original arguments will likely be one of the most 
common uses of call.  And I certainly can't argue with that, I agree.

But why, then, does .call not have an argumentless form?  (Because we 
can't write user-defined methods, short of C<is parsed> tricks, that 
differentiate between .meth and .meth()?  We can't write user-defined subs 
that do that either, AFAIK...)

Might I propose the following normalization:

1. .call, method definition call(), and .wrap call all take captures. 
2. .call() and both types of call() all pass on the arguments of the
    current subroutine.
3. To call with no arguments, use .call(\()) and call(\()).
4. Introduce some syntax for getting a capture of the current argument
    list explicitly.  Perhaps $?ARGS or $?_ or $?CAPTURE.  One shouldn't
    have to choose between repeating your 20 parameters in order to take a
    capture of them, and eliminating your nice self-documenting 20
    parameter names so you can use the easy \$arglist trick.

Trey
0
trey
9/20/2006 10:41:39 AM
perl.perl6.language 6843 articles. 0 followers. Follow

4 Replies
1461 Views

Similar Articles

[PageSpeed] 16

Trey Harris wrote:
> Might I propose the following normalization:
> 
> 1. .call, method definition call(), and .wrap call all take captures.

> 2. .call() and both types of call() all pass on the arguments of the
>    current subroutine.

 > 3. To call with no arguments, use .call(\()) and call(\()).

I have no problem with that, but the original form should probably exist 
too. I don't know if that's called invoke or what, but something that 
takes an arglist and constructs the capture to pass on would be very 
helpful to most users.

> 4. Introduce some syntax for getting a capture of the current argument
>    list explicitly.  Perhaps $?ARGS or $?_ or $?CAPTURE.  One shouldn't
>    have to choose between repeating your 20 parameters in order to take a
>    capture of them, and eliminating your nice self-documenting 20
>    parameter names so you can use the easy \$arglist trick.

I like the idea in 4, even though I'm not sure that I follow the rest of 
your logic. Having access to a variable that contains the current 
argument list called $?ARGS seems to be in line with the rest of the $? 
state variables that are provided.

So, in general, I think the only thing missing is something like invoke 
so that:

	invoke(1,2,3);

is identical to:

	call(\(1,2,3));

and:

	invoke([,] =$?ARGS);

is identical to:

	call($?ARGS);

is identical to:

	call();

Certainly a distinction on call vs call() is not what Perl 6 programmers 
will come to expect from the rest of the language, and I see no pressing 
reason to introduce it here.
0
ajs
9/20/2006 3:18:09 PM
On Wed, Sep 20, 2006 at 11:18:09AM -0400, Aaron Sherman wrote:
: Trey Harris wrote:
: >Might I propose the following normalization:
: >
: >1. .call, method definition call(), and .wrap call all take captures.
: 
: >2. .call() and both types of call() all pass on the arguments of the
: >   current subroutine.
: 
: > 3. To call with no arguments, use .call(\()) and call(\()).
: 
: I have no problem with that, but the original form should probably exist 
: too. I don't know if that's called invoke or what, but something that 
: takes an arglist and constructs the capture to pass on would be very 
: helpful to most users.

It would be suboptimal to give something so related a name that is
completely unrelated.  If we had such a thing it should "callv" or
"callargs" or some such.  But it's not yet clear to me that this is
frequent enough to deserve the sugar over call(\(...)).

By the way, call() is just short for nextroutine().call() or some such,
where nextroutine() is a mystical call that retrieves the next candidate
based on what kind of dispatcher we're in.

: >4. Introduce some syntax for getting a capture of the current argument
: >   list explicitly.  Perhaps $?ARGS or $?_ or $?CAPTURE.  One shouldn't
: >   have to choose between repeating your 20 parameters in order to take a
: >   capture of them, and eliminating your nice self-documenting 20
: >   parameter names so you can use the easy \$arglist trick.
: 
: I like the idea in 4, even though I'm not sure that I follow the rest of 
: your logic. Having access to a variable that contains the current 
: argument list called $?ARGS seems to be in line with the rest of the $? 
: state variables that are provided.

Uh, no, $? variables are supposed to be compile-time constants.  That's why
there's no $?SELF anymore.

Since individual constraints within the siglet are considered to be
"anded", it might be possible to declare both a capture and the rest of
the parameters like this::

    sub foo (\$args $a, $b, $c)

In other words we relax the constraint that \$x has to come at the
end, so \$x would just take a snapshot of the rest of the args and
keep processing the binding to any remaining parameters.

: So, in general, I think the only thing missing is something like invoke 
: so that:
: 
: 	invoke(1,2,3);
: 
: is identical to:
: 
: 	call(\(1,2,3));
: 
: and:
: 
: 	invoke([,] =$?ARGS);
: 
: is identical to:
: 
: 	call($?ARGS);
: 
: is identical to:
: 
: 	call();

We might prefer a three-way distinction just to avoid user confusion:

    call;			no args allowed, always uses existing parameters
    callcap($capture)		one arg, must be capture (plus named?)
    callargs($a: $b, $c)	same as callcap(\($a: $b, $c));

(plus the corresponding dot forms).  Alternately, just keep callargs and
force callcap to be written callargs([,] =$capture).  After all, if you're
going to do anything with the args, you're usually not interested in the
whole original capture by itself.

What we really need is a unary operator that is sugar for [,](=(...)).  Just
don't anyone suggest *.  :-)

Candidates:

    callargs(`$foo)
    callargs(_$foo)
    callargs(|$foo)
    callargs(�$foo)

Another approach would be to give captures a sigil that autoinserts, and
you'd have to \ it to suppress that, much like @foo always interpolates
into list context.  Then we just get something like

    callargs(�x)

and the mixed declaration above would be

    sub foo (�args $a, $b, $c)

: Certainly a distinction on call vs call() is not what Perl 6 programmers 
: will come to expect from the rest of the language, and I see no pressing 
: reason to introduce it here.

Yes, that would be a mistake.  Macros that abuse () are a design smell.

Larry
0
larry
9/20/2006 6:03:52 PM
Larry Wall wrote:
> On Wed, Sep 20, 2006 at 11:18:09AM -0400, Aaron Sherman wrote:
> : Trey Harris wrote:
> : >Might I propose the following normalization:
> : >
> : >1. .call, method definition call(), and .wrap call all take captures.
> : 
> : >2. .call() and both types of call() all pass on the arguments of the
> : >   current subroutine.
> : 
> : > 3. To call with no arguments, use .call(\()) and call(\()).
> : 
> : I have no problem with that, but the original form should probably exist 
> : too. I don't know if that's called invoke or what, but something that 
> : takes an arglist and constructs the capture to pass on would be very 
> : helpful to most users.
> 
> It would be suboptimal to give something so related a name that is
> completely unrelated.  If we had such a thing it should "callv" or
> "callargs" or some such.  But it's not yet clear to me that this is
> frequent enough to deserve the sugar over call(\(...)).

invoke is just a very commonly used name in places like parrot and XS, 
so I thought of it right off the bat.

I think your call, callargs and callcap are fine looking things.

As for $?ARGS, you're right, I was forgetting that it's not compile-time 
constant.

Would $?ROUTINE have access to its current invocation? In other words, 
could $?ROUTINE.args or $?ROUTINE.invocation.args find the current 
invocation and ask for its capture? Why do I ask for that when you've 
already said that signatures could include a capture? Macros. A macro 
might want to do something with its caller's arguments, but doesn't know 
what localized name it will have been given. If it can ask for its 
$?ROUTINE, then it's always going to work.

     macro debug() {
	if $*ENV<DEBUG> {
             q:code{
                 say("DEBUG: ", $?ROUTINE.name,
                     " called with: ",
                     Dumper($?ROUTINE.args))
             };
	} else {
             q:code{1};
         }
     }

> What we really need is a unary operator that is sugar for [,](=(...)).  Just
> don't anyone suggest *.  :-)

I was thinking about that. I wonder if [\] would make sense, or is that 
just begging to have in-editor parsers fall over screaming ;)

Other options might be (in decreasing order of my fondness for them):

	callargs(<-- $foo)   -- a nice inverse to ->
	callargs($\ $foo)    -- mnemonic: Dereference this capture
	callargs(.* $foo)    -- Ok, only to be passive-aggressive ;)
	callargs(*\ $foo)    -- kind of the same idea as $\

> 
> Candidates:
> 
>     callargs(`$foo)
>     callargs(_$foo)
>     callargs(|$foo)
>     callargs(�$foo)

None of these LOOK like capture-expansion to me other than _ which I'm 
always hesitant to mess with. | seems too confusing.

> Another approach would be to give captures a sigil that autoinserts, and
> you'd have to \ it to suppress that, much like @foo always interpolates
> into list context.  Then we just get something like
> 
>     callargs(�x)
> 
> and the mixed declaration above would be
> 
>     sub foo (�args $a, $b, $c)

I've been a Perl programmer for 15 years, so I don't know why adding a 
sigil would bother me, but it does... Can't give you a good reason, 
though, so perhaps it's moot. Unicode sigils might have a valid ickiness 
factor, though. I can't figure out what the ascii form of � would be... 
Certainly most expansions involving c and/or | are going to have 
ambiguity problems.

0
ajs
9/20/2006 7:03:30 PM
On 9/20/06, Aaron Sherman <ajs@ajs.com> wrote:
> Larry Wall wrote:
> > What we really need is a unary operator that is sugar for [,](=(...)).  Just
> > don't anyone suggest *.  :-)
>
> I was thinking about that. I wonder if [\] would make sense, or is that
> just begging to have in-editor parsers fall over screaming ;)

That would be quite close to [\+] [\,] etc.. from S03:

S03> say [\+] 1..*  #  (1, 3, 6, 10, 15, ...)

-- 
Markus Laire
0
malaire
9/21/2006 1:17:40 PM
Reply:

Similar Artilces:

Do-Not-Call Called to Court
Do-Not-Call Called to Court Associated Press Page 1 of 1 02:06 PM Nov. 11, 2003 PT The public's frustration with telemarketers and its right to privacy justifies the national do-not-call list, government lawyers argued before a federal appeals court Monday. Telemarketers, however, told the three-judge panel of the 10th U.S. Circuit Court of Appeals that the list inhibits competition and violates their right to free speech by barring calls from businesses but not charities or politicians. Full Story: http://www.wired.com/news/privacy/0,1848,61190,00.html?tw=wn_to...

Tell CALLED form who CALLED
I am opening a form (from my main form) with application.createform(TmyForm, myForm) myForm.ShowModal and I would like the form myForm know which form opened it (was it MainForm or Form2 or Form3, etc..) How do I pass this info onto the called form myForm? I could stored it in a GlobalVariable but there must be a nicer way ThankYou tom clancy a écrit : > I am opening a form (from my main form) with > > application.createform(TmyForm, myForm) > myForm.ShowModal > > and I would like the form myForm know which form opened it (was it MainForm or Fo...

function calling and object calling
Hello, When I create a package, and call its methods by both object way and function (exported) way, how to avoid the conflict in arguments passing? for exmaple, package myclass; require Exporter; our @ISA = qw/Exporter/; our @EXPORT = qw/my_method/; sub new { ... } sub my_method { my $self = shift; my @arg = @_; ... } __END__ But for function calling, "my $self = shift;" shouldn't be used. So how to make both function calling and object calling work together? Thanks. >>>>> "JG" == Jenn G <...

Why Page_Load is called before Button_Click is called?
I need to update my related database through a button click. What I want is, after I update the database, a message is postbacked and my page is freshed based on the updated database. However, what I get is, after I click the control, a message is sent back to the server, and the page get refreshed before my database get updated. Therefore, the change in the database does not show up in my page. I put break point in both Page_Load and Button_Click methods, the program stopped first at Page_Load and then at Button_Click. Do I have to manually ask the page to refresh i...

Calling FreeAndNil or calling Destroy?
I have a class in which I create a couple of (other) class object instances. These must of course be destroyed before the class object instance is destroyed. Presently I have a destructor containing the following statements: FreeAndNil(Object1); FreeAndNil(Object2) inherited Destroy; and I call MainObject.Destroy. This works perfectly, so there is really not any big problem. But when I try to instead call FreeAndNil(MainObject) it seems as if this Destroy method inside the class definition is not invoked? I had hoped that Free invoked the destructor Destroy automatical...

On each Ajax call Session_End is called
Hi there,  I need help! ;( I develop a little Ajax Timer call with Jquery based on the following tutorial. http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/07/29/asp-net-podcast-show-121-phil-haack-with-an-asp-net-mvc-demo-video.aspx   Everything works great, BUT, now I want to implement something on Session_End and on my debugging I mentiond that Session_End is now called every 10 seconds, what means with each Ajax call and I have no idea why. And on each Session_End call the SessionId is the same, what means the Session is not realy destroyed, but why is tha...

Call URL and call Session
I am creating an application that is authenticated with facebook. (see http://developers.facebook.com/documentation.php?doc=login_desktop ). I want to know like calling from PB to a URL (Example http://www.facebook.com/login.php?api_key=YOUR_API_KEY&v=1.0&auth_token=abc123) and I must take the session y the information of the session. In VisualBasic.NET call functions callRemoteMethod and GetXMLData and more As I can do it? Inet object? ideas, regards, Oscar Tobar Rios You can use GetURL. Check out the sample at http://www.rgagnon.com/pbdetails/pb-0128.h...

call
Name: sailingbonyko Email: sailing93atgmaildotcomdotmy Product: Firefox Summary: call Comments: ok Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1) Gecko/20090616 Firefox/3.5 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

CALL
This is a multi-part message in MIME format. ------=_NextPart_000_0012_01C2E327.F3DA87D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable is it possible to call a function in another window that is not a parent = of the current window? windowA (parent) windowB (ancestor) windowC (new window - parent)=20 -CALL a function in A here? thank you, ----------------------- Richard Parke, Technical Consultant: Buchanan Family Medical Center webmaster@buchananfamilymed.com 269.695.0262 ------=_NextPart_000_00...

Call
Hi how can I call this attribute Dim mybtn As ImageButton = CType(e.Item.FindControl("ImageButton2"), ImageButton) mybtn.Attributes.Add("OnClick", "showwindow()") I want to call mybtn_onclick or something I don't know how to call that when I add that attribute ! I want to call it bymyself in Code ! what do you mean 'call'? it's an onclick event. to call it, you click it ?!?!RTFM - straight talk for web developers. Unmoderated, uncensored, occasionally unreadableJason Brown - MVP, IIS but it's not like this I have that control in a DataList...

pageLoad() Called For Every AJAX Call
I am adding some event handlers during the pageLoad() client method that I'd like to either clear and readd or only execute once upon the initial pageLoad().  Unfortunately, for each AJAX request I do via an update panel the pageLoad() function is fired.  I am sure that I am missing something core to the way ASP.NET AJAX works but any help would be greatly appreciated.  The code below is my pageLoad() method and as you can see I am clearing all event handlers for the events that I add vis $addHandlers, but have not found a good way of clearing the events added to my collap...

How to enforce number of calling
Example: One team Quote: create proc sp_get_dates( @date1 datetime, @date2, datetime ) as .... .... BODY of stored proc .... return 0 Another team is creating stored proc that call sp_get_dates But they expect 3 params!!! Quote: .... .... exec sp_get_dates @ld_date1, @ld_date2, @ld_date3 if ( @@error !=3d 0 ) return @error .... .... Problem: During completing and funkcionally test phase we don t get any error info! Code proceed and there is no message that number of calling-called don=b4t match! What to do to enforce error if params number do...

How to call a remote call of DPB client
My DPB client application sends a very big blob to DPB server by call a remote object function like this: remoteobj.SendBlob(blobdata) Before SendBlob function returns, if I plug out the network cable, sometime my client is frozen, sometime it returns after a long time waiting. Can anybody tell me how to avoid SendBlob being frozen or let it returns error msg earlier? Thank you so much. ...

Calling C++ DLL call from Delphi
Hi All I have C++ DLL setup that exports the following function: bool ApplyRule(HANDLE DriverDevice, std::string *Path, PROTECTION_TYPE Type, PROTECTION_ACTION Action, bool Architecture64, bool AddRule) I am not sure how to convert it properly to delphi, inparticular the std::string parameter. ApplyRule : function (DriverDevice : THandle; Path : ????; Kind : PROTECTION_TYPE; Action : PROTECTION_ACTION; Architecture64 : Boolean; AddRule : Boolean) : boolean; stdcall; Thanks for the help. Chris Nillissen wrote: > I am not sure how to convert it properly to delphi,...

Web resources about - call, call(), .call, and captures - perl.perl6.language

Capture - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Report: Facebook Search Engine Would Immediately Capture 25 Percent Of Market
If Facebook were to launch its own search engine right now, it would immediately attract nearly one-quarter of that sector and become the second-most-used ...

Early Look: RootMusic Adds Like-Gating, Email Capture and More to BandPage
RootMusic’s BandPage, the most popular musician profile Facebook Page tab application, has just announced an update with new features for both ...

TimeShutter - Capture changes in aligned snaps everyday! on the App Store on iTunes
Get TimeShutter - Capture changes in aligned snaps everyday! on the App Store. See screenshots and ratings, and read customer reviews.

Google Street View captures dead body on Melbourne street
... fleet of Street View cars have become the 21st century's roving historians, freezing strips of suburbia in time. Their lenses have captured ...

US skydiver captures moment plane crashed into field
WE’VE all seen disaster movies like Airport and Alive, but this is what it’s truly like to be in a plane crash.

Paul Fletcher's plan to 'capture' property values to pay for infrastructure
The Turnbull government is looking at tapping the value generated via rising property values to pay for new infrastructure.

Local Coast Guard crews assist with panga capture - CBS News 8 - San Diego, CA News Station - KFMB Channel ...
U.S. Coast Guard crews transferred 10 suspected undocumented migrants this weekend to San Diego when they were intercepted aboard a panga near ...

Two Brothers Capture a Glorious Selfie With a Bald Eagle They Rescued From a Trap
Michael and Neil Fletcher were hunting in Ontario's Windy Lake when they spotted a bald eagle caught in a claw trap. However, freeing the bird ...

Astronaut captures Cygnus spacecraft launch from space
The Cygnus cargo spacecraft is on its way to the International Space Station and astronaut Scott Kelly captured a spectacular image of it in ...

Resources last updated: 12/12/2015 9:37:59 AM