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

self-referential declarations. #2105

Open
p6rt opened this issue Aug 27, 2010 · 5 comments
Open

self-referential declarations. #2105

p6rt opened this issue Aug 27, 2010 · 5 comments
Labels
NYI Features not yet implemented

Comments

@p6rt
Copy link

p6rt commented Aug 27, 2010

Migrated from rt.perl.org#77474 (status was 'open')

Searchable as RT77474$

@p6rt
Copy link
Author

p6rt commented Aug 27, 2010

From @masak

<TimToady> I think I've found a binding bug. http://wall.org/~larry/hamming.p6

#!/usr/local/bin/perl6

#hamming = 1 : map (2*) hamming `merge` map (3*) hamming `merge` map
(5*) hamming
# where merge (x​:xs) (y​:ys)
# | x < y = x : xs `merge` (y​:ys)
# | x > y = y : (x​:xs) `merge` ys
# | otherwise = x : xs `merge` ys

sub infix​:<merge> (@​x [$x, *@​xtail], @​y [$y,*@​ytail]) {
  if $x < $y { $x, (@​xtail merge @​y) }
  elsif $x > $y { $y, (@​x merge @​ytail) }
  else { $x, (@​xtail merge @​ytail) }
}

my @​hamming := (1, (@​hamming X* 2) merge (@​hamming X* 3) merge (@​hamming X* 5));

say ~@​hamming[^20];

<masak> ooh, the Hamming sequence!
<TimToady> I would guess that the *@​xtail is not successful in binding
to the conjectural part of the @​hamming array
<masak> TimToady​: any reason why it shouldn't bind?
<TimToady> rakudo​: sub foo (@​x [$xhead, *@​xtail]) { say ~@​xtail };
foo([1,2,3]) [21​:33]
<p6eval> rakudo 18189a​: OUTPUT«2 3␤»
<masak> \o/
<Tene> perl6​: my @​x = 1..5; sub foo(@​a [$a, *@​atail]) { say "head​:
$a\ntail​: {@​atail.perl}"; }; foo(@​x);
<p6eval> rakudo 18189a​: OUTPUT«head​: 1␤tail​: [2, 3, 4, 5]␤»
<TimToady> rakudo​: sub foo (@​x [$xhead, *@​xtail]) { say ~@​xtail };
foo([1, (2...3)])
<p6eval> rakudo 18189a​: OUTPUT«2 3␤»
<TimToady> rakudo​: sub foo (@​x [$xhead, *@​xtail]) { say ~@​xtail[^3] };
foo([1, 'x' xx *])
<p6eval> rakudo 18189a​: OUTPUT«(timeout)»
<TimToady> anyway, hamming is sort of an acid test for laziness, the
way man-or-boy is for scoping
<TimToady> and currently we flunk...
<pmichaud> file a bug report for hamming, please. I know enough of
the binding codenow that I think I might be able to fix it up.
<pmichaud> I'd like to see that one work.
* masak submits rakudobug for hamming

@p6rt
Copy link
Author

p6rt commented Jan 30, 2012

From @moritz

The code as-is will never work, because at some point it'll pass an
empty list to one side of the 'merge' operator, in which case the
subsignature binding fails.

Here is an updated version (see also https://gist.github.com/1704555 )

multi sub infix​:<merge> (@​ [], @​y) is default { @​y };
multi sub infix​:<merge> (@​x, @​ []) { @​x };
multi sub infix​:<merge> (@​x [$x, *@​xtail], @​y [$y,*@​ytail]) {
if $x < $y { $x, (@​xtail merge @​y) }
elsif $x > $y { $y, (@​x merge @​ytail) }
else { $x, (@​xtail merge @​ytail) }
}

my @​hamming := (1, (@​hamming X* 2) merge (@​hamming X* 3) merge (@​hamming
X* 5));

say ~@​hamming[^20];

output on current rakudo​: 1

@p6rt
Copy link
Author

p6rt commented Jan 30, 2012

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

@p6rt
Copy link
Author

p6rt commented Sep 2, 2014

From @coke

On Mon Jan 30 06​:13​:36 2012, moritz wrote​:

The code as-is will never work, because at some point it'll pass an
empty list to one side of the 'merge' operator, in which case the
subsignature binding fails.

Here is an updated version (see also https://gist.github.com/1704555 )

multi sub infix​:<merge> (@​ [], @​y) is default { @​y };
multi sub infix​:<merge> (@​x, @​ []) { @​x };
multi sub infix​:<merge> (@​x [$x, *@​xtail], @​y [$y,*@​ytail]) {
if $x < $y { $x, (@​xtail merge @​y) }
elsif $x > $y { $y, (@​x merge @​ytail) }
else { $x, (@​xtail merge @​ytail) }
}

my @​hamming := (1, (@​hamming X* 2) merge (@​hamming X* 3) merge (@​hamming
X* 5));

say ~@​hamming[^20];

output on current rakudo​: 1

11​:17 < [Coke]> moritz, TimToady​: what is the expected output of the last bit
  of code on https://rt-archive.perl.org/perl6/Ticket/Display.html?id=77474 ?
11​:18 < [Coke]> FYI, the current output is 1 0
11​:19 < TimToady> http://rosettacode.org/wiki/Hamming_numbers
11​:20 < TimToady> but we need the list refactor before that has a hope of
  working
11​:20 < [Coke]> so, "1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 36" is
  the expected output?
11​:21 < TimToady> yes, if Perl 6 were as good as Haskell at recursive
  definitions...
--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Aug 27, 2015

From @coke

On Tue Sep 02 08​:21​:59 2014, coke wrote​:

On Mon Jan 30 06​:13​:36 2012, moritz wrote​:

The code as-is will never work, because at some point it'll pass an
empty list to one side of the 'merge' operator, in which case the
subsignature binding fails.

Here is an updated version (see also https://gist.github.com/1704555
)

multi sub infix​:<merge> (@​ [], @​y) is default { @​y };
multi sub infix​:<merge> (@​x, @​ []) { @​x };
multi sub infix​:<merge> (@​x [$x, *@​xtail], @​y [$y,*@​ytail]) {
if $x < $y { $x, (@​xtail merge @​y) }
elsif $x > $y { $y, (@​x merge @​ytail) }
else { $x, (@​xtail merge @​ytail) }
}

my @​hamming := (1, (@​hamming X* 2) merge (@​hamming X* 3) merge
(@​hamming
X* 5));

say ~@​hamming[^20];

output on current rakudo​: 1

11​:17 < [Coke]> moritz, TimToady​: what is the expected output of the
last bit
of code on
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=77474 ?
11​:18 < [Coke]> FYI, the current output is 1 0
11​:19 < TimToady> http://rosettacode.org/wiki/Hamming_numbers
11​:20 < TimToady> but we need the list refactor before that has a hope
of
working
11​:20 < [Coke]> so, "1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32
36" is
the expected output?
11​:21 < TimToady> yes, if Perl 6 were as good as Haskell at recursive
definitions...

Both GLR & NOM now complain that you can't use @​hamming to declare @​hamming.
--
Will "Coke" Coleda

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

No branches or pull requests

1 participant