pyper 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ module Pyper
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/pyper/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["boris"]
6
+ gem.email = ["\"boris@iis.sinica.edu.tw\""]
7
+ gem.description = %q{Ruby extension of Lispy #car/#cdr methods.}
8
+ gem.summary = %q{Methods car, cdr, caar, cadr, cdar, caaar, caadr, ... are well known from Lisp.
9
+ Here, 'a' means first element of a collection, 'd' means rest of the collection. Now, imagine that there
10
+ would also be 'b' and 'c', meaning 2nd and 3rd element, 'e', 'f', meaning rest minus first 2, resp. first
11
+ 3 elements. Imagine that instead of starting 'c' and ending 'r', Greek letter τ would be used: τaτ, τdτ, ...
12
+ to distinguish Pyper methods in the namespace. Imagine more more letters for more methods, imagine that
13
+ these methods can have arity higher than 0, imagine double-barrel pipeline instead of just single-barrel,
14
+ and you are getting to the spirit of Pyper (and APL).}
15
+ gem.homepage = ""
16
+
17
+ gem.files = `git ls-files`.split($\)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.name = "pyper"
21
+ gem.require_paths = ["lib"]
22
+ gem.version = Pyper::VERSION
23
+
24
+ gem.add_development_dependency "shoulda"
25
+ end
@@ -0,0 +1,109 @@
1
+ #! /usr/bin/ruby
2
+ #encoding: utf-8
3
+
4
+ require 'test/unit'
5
+ require 'shoulda'
6
+ # require_relative './../lib/pyper'
7
+ require 'pyper'
8
+
9
+ include Pyper
10
+
11
+ class YPiperTest < ::Test::Unit::TestCase
12
+ should "define basic methods" do
13
+
14
+ assert_equal 1, [1, 2, 3].car
15
+ assert_equal [2, 3], [1, 2, 3].cdr
16
+ assert_equal :a, {a: 1}.caar
17
+ assert_equal [1], {a: 1}.cdar
18
+ assert_equal [:b, 2], {a: 1, b: 2}.cadr
19
+ assert_equal [[:c, 3]], {a: 1, b: 2, c: 3}.cddr
20
+ assert_equal 1, [1, 2].τaτ
21
+ assert_equal 2, [*(1..10)].τbτ
22
+ assert_equal 3, [*(1..10)].τcτ
23
+ assert_equal [*(2..10)], [*(1..10)].τdτ
24
+ assert_equal [*(3..10)], [*(1..10)].τeτ
25
+ assert_equal [*(4..10)], [*(1..10)].τfτ
26
+
27
+ assert_equal [:a, :b, :c], [[:a, 1], [:b, 2], [:c, 3]].τmaτ
28
+ assert_equal ["a", "b", "c"], [[:a, 1], [:b, 2], [:c, 3]].τmaςτ
29
+
30
+ assert_equal [*(1..7)], [*(1..10)].τuτ
31
+ assert_equal [*(1..8)], [*(1..10)].τvτ
32
+ assert_equal [*(1..9)], [*(1..10)].τwτ
33
+ assert_equal 8, [*(1..10)].τxτ
34
+ assert_equal 9, [*(1..10)].τyτ
35
+ assert_equal 10, [*(1..10)].τzτ
36
+
37
+
38
+ assert_equal 7, 7.τCτ
39
+ assert_equal 7, 7.τχτ( 8 )
40
+ assert_equal 8, [7, 8].χCτ
41
+ assert_equal 8, 7.τ«τ( 8 )
42
+
43
+ assert_equal [0, 1, 6, 9], [:x.τ∅₀τ, 0.τ∅₁τ, Object.new.τ∅₆τ, "a".τ∅₉τ]
44
+
45
+ assert_equal [:hello], :hello.τAτ
46
+ assert_equal [[:a, 1], [:b, 2]], ( {a: 1, b: 2}.τAτ )
47
+ assert_equal [1, 2], [1, 2].τAτ
48
+
49
+ assert_equal 1, "+1.000000".τ›iτ
50
+ assert_equal "hello", [:h, ?e, :l, :l, :o].τjτ
51
+
52
+ assert_equal "la", :la.τςτ
53
+
54
+ assert_equal :hello, "hello".τßτ
55
+
56
+ assert_equal [[1, 2]], [1, 2].τ›Aτ
57
+
58
+ assert_equal [1], [*(1..10)].τ0τ
59
+ assert_equal [1, 2], [*(1..10)].τ1τ
60
+ assert_equal [1, 2, 3], [*(1..10)].τ2τ
61
+ assert_equal [1, 2, 3, 4], [*(1..10)].τ3τ
62
+ assert_equal [1, 2, 3, 4, 5], [*(1..10)].τ4τ
63
+ assert_equal [6, 7, 8, 9, 10], [*(1..10)].τ5τ
64
+ assert_equal [7, 8, 9, 10], [*(1..10)].τ6τ
65
+ assert_equal [8, 9, 10], [*(1..10)].τ7τ
66
+ assert_equal [9, 10], [*(1..10)].τ8τ
67
+ assert_equal [10], [*(1..10)].τ9τ
68
+
69
+ assert_equal "lligator", ["See", "you", "later", "alligator"].τdeadτ
70
+ assert_equal ?g, ["See", "you", "later", "alligator"].τdeafbτ
71
+
72
+ assert_equal 7, 4.τ₊τ( 3 )
73
+ assert_equal 15, 3.τ★τ( 5 )
74
+ assert_equal 2, 17.τ﹪τ( 5 )
75
+ assert_equal 17 / 5, 17.τ÷τ( 5 )
76
+ assert_equal true, 7.τᴇτ( 7 )
77
+ assert_equal [true, false, false], [-1, 0, 1].τm﹤τ( 0, 0, 0 )
78
+ assert_equal [false, false, true], [-1, 0, 1].τm﹥τ( 0, 0, 0 )
79
+ assert_equal [true, true, false], [-1, 0, 1].τm≤τ( 0, 0, 0 )
80
+ assert_equal [false, true, true], [-1, 0, 1].τm≥τ( 0, 0, 0 )
81
+ assert_equal [5, 10, 15], (1..3).τm★τ( 5 )
82
+ assert_equal [1, 4, 9], [*(1..3)].τ»Dσm★τ
83
+ assert_equal [1, 4, 9], (1..3).τm﹡﹡τ( 2 )
84
+ assert_equal [1, 4, 9], (1..3).τM★τ
85
+ assert_equal [?a, nil, ?a, nil], (1..4).τm﹪ᴇτ( 2, 1 ).τm⁇τ( ?a, nil )
86
+ assert_equal ["a", nil, "a", nil], (1..4).τm﹪ᴇ⁇τ( 2, 1, ?a, nil )
87
+ assert_equal [nil, "b", "b", nil], nil.τ«mᴇ⁇τ( [0, 1, 1, 0], 1, ?b, nil )
88
+ assert_equal [["a", nil], [nil, "b"], ["a", "b"], [nil, nil]],
89
+ (1..4).τm﹪ᴇ⁇χ( 2, 1, ?a, nil ).π«mᴇ⁇π( [0, 1, 1, 0], 1, ?b, nil ).χγZτ
90
+ assert_equal true, [:a, :b, :c].τ¿iτ( :b )
91
+ assert_equal( [[:c], [:a]], [[:b, :c, :d], [:a, :b, :d]].
92
+ χ»βm«ε¿i‹﹗ε⁈﹕n_●χm«ε¿i‹﹗ε⁈﹕n_●π )
93
+ assert_equal( "d yada yada, a, c blah blah",
94
+ "%s yada yada, %s blah blah" %
95
+ [[:d], [:a, :c]].χJχJπ( ", " ) )
96
+ assert_equal "fizzbuzz", (1..100).τm﹪ᴇ⁇χ( 3, 0, "fizz", nil ).πm﹪ᴇ⁇χ( 5, 0, "buzz", nil ).πZmjτ[14]
97
+ assert_equal ["ax", "bx"], ["a", "b"].τmτ { |o| o + "x" }
98
+ assert_equal ["ax", "bx"], ["a", "b"].τBmτ { |o| o + "x" }
99
+ assert_equal [-1, -2], [[1, 1], [2, 3]].πM₋τ
100
+ assert_equal [1, 2], [[1, 1], [2, 3]].πW₋τ
101
+ a, b = [Object.new, Object.new].each { |o| o.define_singleton_method :xxx do "xxx" end }
102
+ hsh = { a => "xxx", b => "xxx" }
103
+ assert_equal hsh, [a, b].τBmχHτ( &:xxx )
104
+ assert_equal [:x], 'x'.τABmτ( &:to_sym )
105
+ assert_equal ['x'], ['x'].τmß_mςτ
106
+ assert_equal [[['y']]], [[[:y]]].τmmmςτ
107
+ assert_equal [[:x, :y], [:v, :w]], [[?x, ?y], [?v, ?w]].τmmßτ
108
+ end
109
+ end # class
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pyper
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - boris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shoulda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: 'Ruby extension of Lispy #car/#cdr methods.'
28
+ email:
29
+ - '"boris@iis.sinica.edu.tw"'
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - lib/pyper.rb
40
+ - lib/pyper/version.rb
41
+ - pyper.gemspec
42
+ - test/pyper_test.rb
43
+ homepage: ''
44
+ licenses: []
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.0.0
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: 'Methods car, cdr, caar, cadr, cdar, caaar, caadr, ... are well known from
66
+ Lisp. Here, ''a'' means first element of a collection, ''d'' means rest of the collection.
67
+ Now, imagine that there would also be ''b'' and ''c'', meaning 2nd and 3rd element,
68
+ ''e'', ''f'', meaning rest minus first 2, resp. first 3 elements. Imagine that instead
69
+ of starting ''c'' and ending ''r'', Greek letter τ would be used: τaτ, τdτ, ...
70
+ to distinguish Pyper methods in the namespace. Imagine more more letters for more
71
+ methods, imagine that these methods can have arity higher than 0, imagine double-barrel
72
+ pipeline instead of just single-barrel, and you are getting to the spirit of Pyper
73
+ (and APL).'
74
+ test_files:
75
+ - test/pyper_test.rb