Skip to content

Commit

Permalink
- Code clean-up; removed some useless operators, such as ^^, $$ a…
Browse files Browse the repository at this point in the history
…nd `??`.

- Removed the Sidef::Tidy module -- broken beyond repair.
- Replaced the Switch/Given operators aliases.

Changes:
	`>` means `when`
	`?` means `case`
	`:` means `default`

Example:
	given(42)
	  > 42    {...}
	  ? true  {...}
          :       {...};
  • Loading branch information
trizen committed Jul 3, 2015
1 parent 502a5ec commit dad6bd3
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 1,133 deletions.
2 changes: 0 additions & 2 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,12 @@ utils/Experiments/struct_optimizer.pl
utils/find_invalid_types.pl
utils/grep_errors.sh
utils/pod_generator.pl
utils/Sidef/Tidy.pm
utils/sidef_concept.jl
utils/sidef_concept.pl
utils/sidef_executor.jl
utils/sidef_executor.lua
utils/sidef_in_perl.pl
utils/test_deparser.pl
utils/tidy.pl
'utils/Web interface/css/main.css'
'utils/Web interface/index.cgi'
'utils/Web interface/js/jquery-2.1.3.min.js'
Expand Down
5 changes: 1 addition & 4 deletions lib/Sidef/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package Sidef::Parser {
postfix_ops => { # postfix operators
'--' => 1,
'++' => 1,
'??' => 1,
'...' => 1,
'!' => 1,
},
Expand Down Expand Up @@ -252,7 +251,6 @@ package Sidef::Parser {
&= &
== =~
:= =
^^ $$
<= >= < >
++ --
+= +
Expand All @@ -265,8 +263,7 @@ package Sidef::Parser {
...
!= ..
\\\\= \\\\
?? ?
! \\
? ! \\
: « » ~
);

Expand Down
52 changes: 26 additions & 26 deletions lib/Sidef/Types/Array/Array.pod
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,32 @@ Aliases: I<groupBy>

=cut

=head2 reduce

=over 2

=item * Array.reduce(I<Block>) -> I<Bool>

Reduces array by calling I<Block>, multiple times, setting C<_[0]> and C<_[1]> each time. The first call will be with C<_[0]> and C<_[1]> set to the first two elements of the list, subsequent calls will be done by setting C<_[0]> to the result of the previous call and C<_[1]> to the next element in the list.

[1,2,3,4].reduce { _[0] + _[1] }; # returns the sum of array's elements (1+2+3+4 = 10)

=back

=over 2

=item * Array.reduce(I<String>) -> I<Bool>

Almost the same as when it takes a block argument, but much more limited.

[1,2,3,4].reduce('*'); # returns the product of array's elements (1*2*3*4 = 24)

=back

Returns an object of the same type as the elements of the array.

=cut

=head2 insert

Array.insert(I<Number>, I<Obj1>, I<Obj2>, I<...>) -> I<Array>
Expand Down Expand Up @@ -831,32 +857,6 @@ This method always returns an object of type: C<Sidef::Types::Array::Array>

=cut

=head2 reduce

=over 2

=item * Array.reduce(I<Block>) -> I<Bool>

Reduces array by calling I<Block>, multiple times, setting C<_[0]> and C<_[1]> each time. The first call will be with C<_[0]> and C<_[1]> set to the first two elements of the list, subsequent calls will be done by setting C<_[0]> to the result of the previous call and C<_[1]> to the next element in the list.

[1,2,3,4].reduce { _[0] + _[1] }; # returns the sum of array's elements (1+2+3+4 = 10)

=back

=over 2

=item * Array.reduce(I<String>) -> I<Bool>

Almost the same as when it takes a block argument, but much more limited.

[1,2,3,4].reduce('*'); # returns the product of array's elements (1*2*3*4 = 24)

=back

Returns an object of the same type as the elements of the array.

=cut

=head2 reduce_operator

Array.reduce_operator() -> I<Obj>
Expand Down
6 changes: 3 additions & 3 deletions lib/Sidef/Types/Block/Switch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ package Sidef::Types::Block::Switch {

{
no strict 'refs';
*{__PACKAGE__ . '::' . '~~'} = \&when;
*{__PACKAGE__ . '::' . '??'} = \&case;
*{__PACKAGE__ . '::' . '..'} = \&default;
*{__PACKAGE__ . '::' . '>'} = \&when;
*{__PACKAGE__ . '::' . '?'} = \&case;
*{__PACKAGE__ . '::' . ':'} = \&default;
}

};
Expand Down
26 changes: 13 additions & 13 deletions lib/Sidef/Types/Block/Switch.pod
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,48 @@ Inherits methods from:
=head1 METHODS


=head2 ..
=head2 :

I<Obj> B<..> I<Obj> -> I<Obj>
I<Obj> B<:> I<Obj> -> I<Obj>

Return the

Aliases: I<else>, I<default>

=cut

=head2 ??
=head2 >

I<Obj> B<??> I<Obj> -> I<Obj>
I<Obj> B<E<gt>> I<Obj> -> I<Obj>

Return the

Aliases: I<case>
Aliases: I<when>

=cut

=head2 end
=head2 ?

Switch.end() -> I<Obj>
I<Obj> B<?> I<Obj> -> I<Obj>

Return the

Aliases: I<case>

=cut

=head2 value
=head2 end

Switch.value() -> I<Obj>
Switch.end() -> I<Obj>

Return the

=cut

=head2 ~~
=head2 value

I<Obj> B<~~> I<Obj> -> I<Obj>
Switch.value() -> I<Obj>

Return the

Aliases: I<when>

=cut
5 changes: 0 additions & 5 deletions lib/Sidef/Types/Regex/Matches.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ package Sidef::Types::Regex::Matches {

*ncap = \&named_captures;
*ncaps = \&named_captures;

{
no strict 'refs';
*{__PACKAGE__ . '::' . '??'} = \&matched;
}
};

1
20 changes: 10 additions & 10 deletions lib/Sidef/Types/Regex/Matches.pod
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ Inherits methods from:
=head1 METHODS


=head2 ??

I<Obj> B<??> I<Obj> -> I<Obj>

Return the

Aliases: I<to_bool>, I<toBool>, I<matched>, I<is_successful>, I<isSuccessful>

=cut

=head2 cap

Matches.cap() -> I<Obj>
Expand Down Expand Up @@ -60,3 +50,13 @@ Matches.pos() -> I<Obj>
Return the

=cut

=head2 to_bool

Matches.to_bool() -> I<Obj>

Return the

Aliases: I<toBool>, I<matched>, I<is_successful>, I<isSuccessful>

=cut
2 changes: 0 additions & 2 deletions lib/Sidef/Types/String/String.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1138,8 +1138,6 @@ package Sidef::Types::String::String {
*{__PACKAGE__ . '::' . '^'} = \&xor;
*{__PACKAGE__ . '::' . '|'} = \&or;
*{__PACKAGE__ . '::' . '&'} = \&and;
*{__PACKAGE__ . '::' . '^^'} = \&begins_with;
*{__PACKAGE__ . '::' . '$$'} = \&ends_with;
*{__PACKAGE__ . '::' . '<<'} = \&shift_left;
*{__PACKAGE__ . '::' . '>>'} = \&shift_right;
*{__PACKAGE__ . '::' . '%'} = \&sprintf;
Expand Down
40 changes: 20 additions & 20 deletions lib/Sidef/Types/String/String.pod
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ Inherits methods from:
=head1 METHODS


=head2 $$

I<Obj> B<$$> I<Obj> -> I<Obj>

Return the

Aliases: I<ends_with>, I<endsWith>

=cut

=head2 %

I<Obj> B<%> I<Obj> -> I<Obj>
Expand Down Expand Up @@ -213,16 +203,6 @@ Aliases: I<downto>, I<downTo>

=cut

=head2 ^^

I<Obj> B<^^> I<Obj> -> I<Obj>

Return the

Aliases: I<begins_with>, I<beginsWith>, I<starts_with>, I<startsWith>

=cut

=head2 apply_escapes

String.apply_escapes() -> I<Obj>
Expand Down Expand Up @@ -251,6 +231,16 @@ Return the

=cut

=head2 begins_with

String.begins_with() -> I<Obj>

Return the

Aliases: I<beginsWith>, I<starts_with>, I<startsWith>

=cut

=head2 bytes

String.bytes() -> I<Obj>
Expand Down Expand Up @@ -387,6 +377,16 @@ Return the

=cut

=head2 ends_with

String.ends_with() -> I<Obj>

Return the

Aliases: I<endsWith>

=cut

=head2 escape

String.escape() -> I<Obj>
Expand Down
2 changes: 1 addition & 1 deletion scripts/Applications/Gift match/giftmatch.sf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func parse_table(file) {
var table = [fh.readline.trim_end.split("\t")];

while (fh.readline(\var line)) {
line =~ /\S/ ?? || next;
line ~~ /\S/ || next;
table.append(line.trim_end.split("\t"));
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/Games/asciiplanes.sf
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ while (count > 0) {
var input = Sys.scanln(text).lc;
input ~~ ['q', 'quit'] && break;

input =~ /^\h*([a-z]+)\D*([0-9]+)/ ?? || next;
$1 ~~ letters || next;
input ~~ /^\h*([a-z]+)\D*([0-9]+)/ || next;
$1 ~~ letters || next;

var x = letters[$1];
var y = $2.to_num.dec;
Expand Down
32 changes: 16 additions & 16 deletions scripts/Games/snake_game.sf
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ func display {
cell[0] !~ s && (
i = (
given(cell[1])
when (UP) { 0 }
when (DOWN) { 1 }
when (LEFT) { 2 }
when (RIGHT) { 3 }
> UP { 0 }
> DOWN { 1 }
> LEFT { 2 }
> RIGHT { 3 }
)
);

given(cell[0])
when (VOID) { A_VOID }
when (FOOD) { A_FOOD }
when (BODY) { [U_BODY, D_BODY, L_BODY, R_BODY][i] }
when (HEAD) { [U_HEAD, D_HEAD, L_HEAD, R_HEAD][i] }
when (TAIL) { [U_TAIL, D_TAIL, L_TAIL, R_TAIL][i] }
> VOID { A_VOID }
> FOOD { A_FOOD }
> BODY { [U_BODY, D_BODY, L_BODY, R_BODY][i] }
> HEAD { [U_HEAD, D_HEAD, L_HEAD, R_HEAD][i] }
> TAIL { [U_TAIL, D_TAIL, L_TAIL, R_TAIL][i] }

}.join('')
}.join("\n")
Expand All @@ -114,9 +114,9 @@ func move {
var cell = grid[new_y][new_x];

given (cell[0])
when (BODY) { die "\nYou just bit your own body!\n" }
when (TAIL) { die "\nYou just bit your own tail!\n" }
when (FOOD) { grew = true; make_food() };
> BODY { die "\nYou just bit your own body!\n" }
> TAIL { die "\nYou just bit your own tail!\n" }
> FOOD { grew = true; make_food() };

# Create a new head
grid[new_y][new_x] = [HEAD, dir];
Expand Down Expand Up @@ -153,8 +153,8 @@ loop {
}

given(key)
when ("\e[A") { dir = UP }
when ("\e[B") { dir = DOWN }
when ("\e[C") { dir = RIGHT }
when ("\e[D") { dir = LEFT };
> "\e[A" { dir = UP }
> "\e[B" { dir = DOWN }
> "\e[C" { dir = RIGHT }
> "\e[D" { dir = LEFT };
}
2 changes: 1 addition & 1 deletion scripts/Rosettacode/hickerson_series_of_almost_integers.sf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ func h(n) {

17.times { |n|
"h(%2d) = %22s is%s almost an integer.\n".printf(
n, var hn = h(n).roundf(-3), hn.to_s =~ /\.[09]/ ?? ? '' : ' NOT');
n, var hn = h(n).roundf(-3), hn.to_s ~~ /\.[09]/ ? '' : ' NOT');
}
4 changes: 2 additions & 2 deletions scripts/amb.sf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ var w = [
];

for (w.map{'{'+_+'}'}->join.glob) {
_.gsub!('|', ' ') =~
/\w+?(\w) \1\w+?(\w) \2\w+?(\w) \3\w+/ ?? && (_.say);
_.gsub!('|', ' ') ~~
/\w+?(\w) \1\w+?(\w) \2\w+?(\w) \3\w+/ && (_.say);
}
Loading

0 comments on commit dad6bd3

Please sign in to comment.