Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parameterisation has higher priority than postcircumfix:<[ ]> even on non-parameterizable types #4458

Closed
p6rt opened this issue Aug 6, 2015 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 6, 2015

Migrated from rt.perl.org#125762 (status was 'rejected')

Searchable as RT125762$

@p6rt
Copy link
Author

p6rt commented Aug 6, 2015

From @LLFourn

Context​: I am trying to make a fun syntax where Class[@​args] is an alias
for Class.new(@​args)


class C {};
sub postcircumfix​:<[ ]>(C​:U $c, Str $arg){ say 'win' };
my $c = C;
$c['test']; #-> win
C['test']; #!> C cannot be parameterized


I also tried​:


role R { method parameterize(|) { say $*d; } };
class C {};
BEGIN { C.HOW does R };
my $*d = 'win';
C[my $a = 'test']; #-> win
C['test'] #!> Dynamic variable $*d not found


But I can't use dynamic variables because if it's called with a compile
time variable it runs .parameterize at compile time only.

I tentatively suggest that at least one of these is a bug as they together
prevent you using [] on a type to callback to something using $*dynamic
variables consistently.

@p6rt
Copy link
Author

p6rt commented Oct 6, 2015

From @jnthn

On Thu Aug 06 06​:18​:57 2015, lloyd.fourn@​gmail.com wrote​:

Context​: I am trying to make a fun syntax where Class[@​args] is an alias
for Class.new(@​args)

-----
class C {};
sub postcircumfix​:<[ ]>(C​:U $c, Str $arg){ say 'win' };
my $c = C;
$c['test']; #-> win
C['test']; #!> C cannot be parameterized

------

The syntax TypeName[...] is syntactically a type parameterization, by design. If you really want to force interpretation as an array indexing, it'd have to be written as​:

C.['test']; #-> win

I also tried​:
------
role R { method parameterize(|) { say $*d; } };
class C {};
BEGIN { C.HOW does R };
my $*d = 'win';
C[my $a = 'test']; #-> win
C['test'] #!> Dynamic variable $*d not found

------
But I can't use dynamic variables because if it's called with a compile
time variable it runs .parameterize at compile time only.

Yes, and we're allowed to form parametric types at compile time whenever we know we have the parameters available (and if we can't do that, we have a lot of problems; for one it's the very mechanism that allows you to `does` a parametric role on a class declaration!) A parameterize method that isn't prepared to be called at compile time is buggy.

I tentatively suggest that at least one of these is a bug as they together
prevent you using [] on a type to callback to something using $*dynamic
variables consistently.

Both behaviors are as intended. In general, anything of the form `<typename> <postcircumfix>` should be considered a special form. It's a pity we have to overload bracketing chars, but sadly ASCII is a bit limiting!

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Oct 6, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt closed this as completed Oct 6, 2015
@p6rt
Copy link
Author

p6rt commented Oct 6, 2015

@jnthn - Status changed from 'open' to 'rejected'

@p6rt
Copy link
Author

p6rt commented Oct 7, 2015

From @LLFourn

Makes sense. I went with TypeName{'arg'} and TypeName<arg> instead of
TypeName['arg'] which is actually better in some ways. I wanted it to look
like Type​::Tiny a bit but I guess that's what inbuilt types are for :)

On Wed, Oct 7, 2015 at 2​:53 AM, jnthn@​jnthn.net via RT <
perl6-bugs-followup@​perl.org> wrote​:

On Thu Aug 06 06​:18​:57 2015, lloyd.fourn@​gmail.com wrote​:

Context​: I am trying to make a fun syntax where Class[@​args] is an alias
for Class.new(@​args)

-----
class C {};
sub postcircumfix​:<[ ]>(C​:U $c, Str $arg){ say 'win' };
my $c = C;
$c['test']; #-> win
C['test']; #!> C cannot be parameterized

------

The syntax TypeName[...] is syntactically a type parameterization, by
design. If you really want to force interpretation as an array indexing,
it'd have to be written as​:

C.['test']; #-> win

I also tried​:
------
role R { method parameterize(|) { say $*d; } };
class C {};
BEGIN { C.HOW does R };
my $*d = 'win';
C[my $a = 'test']; #-> win
C['test'] #!> Dynamic variable $*d not found

------
But I can't use dynamic variables because if it's called with a compile
time variable it runs .parameterize at compile time only.

Yes, and we're allowed to form parametric types at compile time whenever
we know we have the parameters available (and if we can't do that, we have
a lot of problems; for one it's the very mechanism that allows you to
`does` a parametric role on a class declaration!) A parameterize method
that isn't prepared to be called at compile time is buggy.

I tentatively suggest that at least one of these is a bug as they
together
prevent you using [] on a type to callback to something using $*dynamic
variables consistently.

Both behaviors are as intended. In general, anything of the form
`<typename> <postcircumfix>` should be considered a special form. It's a
pity we have to overload bracketing chars, but sadly ASCII is a bit
limiting!

Thanks,

Jonathan

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant