Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some more methods from Bool and Pair converted to Perl 6.
  • Loading branch information
jnthn committed Feb 18, 2009
1 parent 80fd5c5 commit d3cc978
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 78 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -106,6 +106,7 @@ BUILTINS_PIR = \
src/builtins/traits.pir \

SETTING = \
src/setting/Bool.pm \
src/setting/List.pm \
src/setting/Pair.pm \
src/setting/Whatever.pm \
Expand Down
34 changes: 0 additions & 34 deletions src/classes/Bool.pir
Expand Up @@ -39,20 +39,6 @@ symbols for C<Bool::True> and C<Bool::False>.
.end


.sub 'ACCEPTS' :method
.param pmc topic
.return (self)
.end


.sub 'perl' :method
if self goto false
.return ('Bool::False')
false:
.return ('Bool::True')
.end


.sub 'succ' :method :vtable('increment')
self = 1
.end
Expand All @@ -62,26 +48,6 @@ symbols for C<Bool::True> and C<Bool::False>.
self = 0
.end

=item Bool.pick

Returns True or False

=cut

.sub 'pick' :method
.local pmc rand
rand = get_hll_global ['Any'], '$!random'
$N0 = rand
if $N0 < 0.5 goto ret_true
$P0 = get_hll_global ['Bool'], 'False'
goto done
ret_true:
$P0 = get_hll_global ['Bool'], 'True'
done:
.tailcall 'list'($P0)
.end


=back

=cut
Expand Down
43 changes: 0 additions & 43 deletions src/classes/Pair.pir
Expand Up @@ -20,25 +20,6 @@ src/classes/Pair.pir - methods for the Pair class
.end


=item ACCEPTS()

Called from smartmatches '$_ ~~ X'.
Delegates on to a method call '.:Xkey(Xval)'.

=cut

.sub 'ACCEPTS' :method
.param pmc topic

$S0 = self.'key'()
$S0 = concat ':', $S0

$P0 = self.'value'()

.tailcall topic.$S0($P0)
.end


=item get_string() (vtable method)

Stringify the Pair.
Expand All @@ -54,30 +35,6 @@ Stringify the Pair.
.end


=item fmt

our Str multi Pair::fmt ( Str $format )

Returns the invocant pair formatted by an implicit call to C<sprintf> on
the key and value.

=cut

.sub 'fmt' :method
.param pmc format

.local pmc retv
.local pmc key
.local pmc value

key = self.'key'()
value = self.'value'()
retv = 'sprintf'(format, key, value)

.return(retv)
.end


.namespace []

.sub 'infix:=>'
Expand Down
26 changes: 26 additions & 0 deletions src/setting/Bool.pm
@@ -0,0 +1,26 @@
class Bool is also {

=begin item ACCEPTS
=end item
method ACCEPTS($topic) {
return self;
}

=begin item perl
=end item
method perl() {
return self ?? 'Bool::True' !! 'Bool::False';
}

=begin item pick
Returns True or False
=end item
method pick() {
return rand < 0.5 ?? Bool::True !! Bool::False;
}

}
24 changes: 23 additions & 1 deletion src/setting/Pair.pm
@@ -1,5 +1,28 @@
class Pair is also {

=begin item ACCEPTS()
Called from smartmatches '$_ ~~ X'.
Delegates on to a method call '.:Xkey(Xval)'.
=end item
method ACCEPTS($topic) {
my $meth_name = ':' ~ self.key;
return $topic."$meth_name"(self.value);
}

=begin item fmt
our Str multi Pair::fmt ( Str $format )
Returns the invocant pair formatted by an implicit call to C<sprintf> on
the key and value.
=end item
method fmt(Str $format) {
return sprintf($format, self.key, self.value);
}

=begin item key
Gets the key of the pair.
Expand All @@ -18,7 +41,6 @@ Return key and value as a 2-element List.
return list(self.key, self.value);
}


=begin item pairs
=end item
Expand Down

0 comments on commit d3cc978

Please sign in to comment.