Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

angle quotes for here-docs ?

9 views
Skip to first unread message

Thomas Seiler

unread,
Nov 25, 2004, 8:52:03 AM11/25/04
to perl6-l...@perl.org
Hi

Is $heredoc = «END; the same as $heredoc = <<END; ?

thomas

Juerd

unread,
Nov 25, 2004, 11:03:36 AM11/25/04
to Thomas Seiler, perl6-l...@perl.org
Thomas Seiler skribis 2004-11-25 14:52 (+0100):

> Is $heredoc = «END; the same as $heredoc = <<END; ?

I certainly hope not.

Quoting the delimiter is needed, by the way.

How is <<'END' disambiguated from <<'qw' list>>, anyway?


Regards,

Juerd

Larry Wall

unread,
Nov 25, 2004, 12:39:31 PM11/25/04
to perl6-l...@perl.org
On Thu, Nov 25, 2004 at 05:03:36PM +0100, Juerd wrote:
: Thomas Seiler skribis 2004-11-25 14:52 (+0100):

To get the qw// parse you must put a space between the << and the
quote. This is no hardship semantically, since qw// has always thrown
away initial and trailing whitespace.

Under one way of looking at it, it's just kind of a longest token
rule, since << as a term only ever means qw, and the heredoc tokens
are actually just long opening quotes: <<', <<", <<q/, etc. that have
to match a trailing quote.

Larry

Rod Adams

unread,
Nov 25, 2004, 12:59:21 PM11/25/04
to perl6-l...@perl.org
Juerd wrote:

Seeing the « in the context of a here-doc made me think "can you do a
»<< here-doc?"

So, something like :

@text = »<<END;
text1
END

text2
END

text3
END

text4
END

for @text { ...}

The hard question about this is: how do you know when you've hit the
last END? especially if the text you're loading looks like Perl code, or
if you have different <<END later in your code?

btw, should it be »<<, <<«, or »<<«?

-- Rod Adams

Larry Wall

unread,
Nov 25, 2004, 1:49:19 PM11/25/04
to perl6-l...@perl.org
On Thu, Nov 25, 2004 at 11:59:21AM -0600, Rod Adams wrote:
: Seeing the « in the context of a here-doc made me think "can you do a
: »<< here-doc?"

Nope, you can only hyper operators, not terms.

: So, something like :


:
: @text = »<<END;
: text1
: END
:
: text2
: END
:
: text3
: END
:
: text4
: END
:
: for @text { ...}
:
:
:
: The hard question about this is: how do you know when you've hit the
: last END? especially if the text you're loading looks like Perl code, or
: if you have different <<END later in your code?

I think you have a really good place for a split there. Then there's
no ambiguity about which is the internal separator and which is the
final delimiter.

: btw, should it be »<<, <<«, or »<<«?

Er, can I pick D?

Larry

Juerd

unread,
Nov 25, 2004, 3:37:21 PM11/25/04
to Larry Wall, perl6-l...@perl.org
Larry Wall skribis 2004-11-25 9:39 (-0800):

> : How is <<'END' disambiguated from <<'qw' list>>, anyway?
> To get the qw// parse you must put a space between the << and the
> quote. This is no hardship semantically, since qw// has always thrown
> away initial and trailing whitespace.
> Under one way of looking at it, it's just kind of a longest token
> rule, since << as a term only ever means qw, and the heredoc tokens
> are actually just long opening quotes: <<', <<", <<q/, etc. that have
> to match a trailing quote.

Is whitespace between q and the delimiters still valid? Would it be
after <<? Would that mean using q as the first element in a qw-list will
hurt?

I hope the first answer is 'no' and all other questions are thus
rendered irrelevant. Not that I think getting rid of alphanumeric
delimiters is a good idea, though. I just fear complex parsing and
seemingly random syntax errors.


Juerd

Larry Wall

unread,
Nov 25, 2004, 6:29:54 PM11/25/04
to perl6-l...@perl.org
On Thu, Nov 25, 2004 at 09:37:21PM +0100, Juerd wrote:
: Larry Wall skribis 2004-11-25 9:39 (-0800):

Whitespace is certainly not allowed after <<q. Whether that means a
bare q should disallow whitespace is another matter. Certainly we've
taken the step of disallowing whitespace between a sub name and its
parentheses, so it's possible we could do it to q// as well, as long as
it's still possible to put whitespace between a two-part quote:

tr[a-z]
[A-Z];

But allowing the first whitespace was just a matter of being consistent.
I don't think it's a consistency we have to be consistent about, though.

Larry

Michele Dondi

unread,
Nov 30, 2004, 6:02:25 AM11/30/04
to Larry Wall, perl6-l...@perl.org
On Thu, 25 Nov 2004, Larry Wall wrote:

> On Thu, Nov 25, 2004 at 11:59:21AM -0600, Rod Adams wrote:
> : Seeing the « in the context of a here-doc made me think "can you do a
> : »<< here-doc?"
>
> Nope, you can only hyper operators, not terms.

Incidentally, just like mathematically (albeit slightly loosely) an
element of a set can be thought of as a function from any singleton, would
it be possible for Perl 6 to provide a fast (under the syntactical point
of view) way to promote a term to a function returning it?


Michele
--
Not really. It was an insider joke. If you need to ask, you won't
get the answer. I never said I was a nice guy.
- David Kastrup in comp.text.tex, "Re: \slash and /"

David Christensen

unread,
Nov 30, 2004, 10:21:06 AM11/30/04
to Michele Dondi, perl6-l...@perl.org, Larry Wall
> Incidentally, just like mathematically (albeit slightly loosely) an
> element of a set can be thought of as a function from any singleton,
> would it be possible for Perl 6 to provide a fast (under the
> syntactical point of view) way to promote a term to a function
> returning it?
>
What's wrong with the perl 5:

sub mysub($x) {
return sub { $x }; # the sub{$x} is the construct
}

?

David

Abhijit Mahabal

unread,
Nov 30, 2004, 11:19:42 AM11/30/04
to David Christensen, Michele Dondi, perl6-l...@perl.org, Larry Wall

or the perl6

$xsub = { $x };

I am a little confused if the following is valid perl6:

our &xsub = { $x };

I believe that would work and install this function in the package global
symbol table because &xsub is the reference to the function xsub.

If you wanted to get a function for each element in an array @a, I suppose
you can say:

sub makefunc($x){{$x}}
@funcarray = @a>>.makefunc;

And that can also be shortened to:

@funcarray = @a>>{my $x=$^x;{$x}};

--abhijit

Michele Dondi

unread,
Nov 30, 2004, 11:48:06 AM11/30/04
to David Christensen, perl6-l...@perl.org, Larry Wall
On Tue, 30 Nov 2004, David Christensen wrote:

>> Incidentally, just like mathematically (albeit slightly loosely) an
>> element of a set can be thought of as a function from any singleton,
>> would it be possible for Perl 6 to provide a fast (under the syntactical

^^^^
^^^^


>> point of view) way to promote a term to a function returning it?
>>
> What's wrong with the perl 5:
>
> sub mysub($x) {
> return sub { $x }; # the sub{$x} is the construct
> }
>
> ?

^^^^
^^^^

Michele
--
The amount of repetition repetition isn't that great.
- Ignacy Sawicki in comp.text.tex
thread "Bug in FeynMF's Queues?"

Michele Dondi

unread,
Nov 30, 2004, 11:50:51 AM11/30/04
to Abhijit Mahabal, David Christensen, perl6-l...@perl.org, Larry Wall
On Tue, 30 Nov 2004, Abhijit Mahabal wrote:

> or the perl6
>
> $xsub = { $x };

Sorry, I was missing the obvious...


Michele
--
> [...] is like requiring to play tennis with a square ball.
Which admittedly makes the game more interesting.
- Giuseppe "Oblomov" Bilotta in comp.text.tex (edited)

Damian Conway

unread,
Nov 30, 2004, 2:16:03 PM11/30/04
to perl6-l...@perl.org, Larry Wall
Abhijit Mahabal wrote:

> I am a little confused if the following is valid perl6:
>
> our &xsub = { $x };

No. Illegal attempt to assign to a reference. You want aliasing/binding instead:

our &xsub := { $x };

(I like to think of := as "assignment to symbol table entry".)


> If you wanted to get a function for each element in an array @a, I
> suppose you can say:
>
> sub makefunc($x){{$x}}
> @funcarray = @a>>.makefunc;

You're attempting to call a sub as a method. You want:

@funcarray = »makefunc« @a;

Damian

Larry Wall

unread,
Nov 30, 2004, 3:27:45 PM11/30/04
to perl6-l...@perl.org
On Wed, Dec 01, 2004 at 06:16:03AM +1100, Damian Conway wrote:
: >If you wanted to get a function for each element in an array @a, I
: >suppose you can say:
: >
: >sub makefunc($x){{$x}}
: >@funcarray = @a>>.makefunc;
:
: You're attempting to call a sub as a method. You want:
:
: @funcarray = »makefunc« @a;

Unaries only take "hyper" on one side, so that would just be:

@funcarray = makefunc« @a;

And if makefunc is declared with a single argument, it can probably be
called as a method anyway, since we try to keep those indistinguishable.
Possibly it would need to be declared multi.

Larry

Luke Palmer

unread,
Nov 30, 2004, 7:57:32 PM11/30/04
to Abhijit Mahabal, Damian Conway, perl6-l...@perl.org, Larry Wall
Abhijit Mahabal writes:

> On Wed, 1 Dec 2004, Damian Conway wrote:
>
> > Abhijit Mahabal wrote:
> >
> > > I am a little confused if the following is valid perl6:
> > >
> > > our &xsub = { $x };
> >
> > No. Illegal attempt to assign to a reference. You want aliasing/binding instead:
> >
> > our &xsub := { $x };
> >
> > (I like to think of := as "assignment to symbol table entry".)
>
> Okay, that makes sense. A question about symbol tables, though: IIRC, only
> packages have symbol tables, and blocks don't: they just have a lexical
> pad. So is the C<our> redundent? Is the following an error?
>
> my &xsub := { $x };
>
> ?

No, not an error. Lexical pads work just like symbol tables in Perl 6.
You can muck around with them, too. Hooray!

In fact, I expect that piece of code to be rather common in Perl 6.

Luke

0 new messages