-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added support for class attributes
In addition to class paraterms, which are also instance class attributes, a new way of declaring attributes has been added, using the `has (attr1, attr2, ...)` syntax. Example: class Foo { has value = 42 } var a = Foo() var b = Foo() a.value = 99 # changes value of `a` to 99 say a.value; # prints: 99 say b.value; # prints: 42 - Minor fixed for Array.first(n) when array has less than n elements. Example: var arr = [1,2,3]; say arr.first(10); # returns: [1,2,3]
- Loading branch information
trizen
committed
Nov 25, 2015
1 parent
3da1dbc
commit 7de49f0
Showing
13 changed files
with
267 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package Sidef::Variable::ClassAttr { | ||
|
||
sub new { | ||
my (undef, %opt) = @_; | ||
bless \%opt, __PACKAGE__; | ||
} | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/ruby | ||
|
||
# | ||
## http://rosettacode.org/wiki/Move-to-front_algorithm#Sidef | ||
# | ||
|
||
func encode(str) { | ||
var table = ('a'..'z' -> join); | ||
str.chars.map { |c| | ||
var s = ''; | ||
table.sub!(Regex('(.*?)' + c), {|s1| s=s1; c + s1}); | ||
s.len; | ||
} | ||
} | ||
|
||
func decode(nums) { | ||
var table = ('a'..'z' -> join); | ||
nums.map { |n| | ||
var s = ''; | ||
table.sub!(Regex('(.{' + n + '})(.)'), {|s1, s2| s=s2; s2 + s1}); | ||
s; | ||
}.join; | ||
} | ||
|
||
%w(broood bananaaa hiphophiphop).each { |test| | ||
var encoded = encode($test); | ||
say "#{test}: #{encoded}"; | ||
var decoded = decode(encoded); | ||
print "in" if (decoded != test); | ||
say "correctly decoded to #{decoded}"; | ||
assert_eq(test, decoded); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/ruby | ||
|
||
# | ||
## http://rosettacode.org/wiki/Move-to-front_algorithm#Sidef | ||
# | ||
|
||
module MoveToFront { | ||
|
||
define ABC = "a".."z" | ||
|
||
func m2f(ar,i) { | ||
[ar.delete_index(i)] + ar | ||
} | ||
|
||
func encode(str) { | ||
var ar = ABC+[] | ||
gather { | ||
str.each_char { |char| | ||
take(var i = ar.index(char)) | ||
ar = m2f(ar, i); | ||
} | ||
} | ||
} | ||
|
||
func decode(indices) { | ||
var ar = ABC+[] | ||
gather { | ||
indices.each { |i| | ||
take ar[i]; | ||
ar = m2f(ar, i) | ||
} | ||
}.join | ||
} | ||
} | ||
|
||
%w(broood bananaaa hiphophiphop).each { |test| | ||
var encoded = MoveToFront::encode($test); | ||
say "#{test}: #{encoded}"; | ||
var decoded = MoveToFront::decode(encoded); | ||
print "in" if (decoded != test); | ||
say "correctly decoded to #{decoded}"; | ||
assert_eq(test, decoded); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/ruby | ||
|
||
var methods = %w(== != > >= < <= <=>); | ||
|
||
[%w(YUP YUP),%w(YUP Yup),%w(bot bat),%w(aaa zz)].each {|arr| | ||
var (s1, s2) = arr...; | ||
methods.each{|m| "%s %s %s\t%s\n".printf(s1, m, s2, s1.(m)(s2))}; | ||
print "\n"; | ||
} |
Oops, something went wrong.