소스 검색

Implement cons

master
Dylan Baker 5 년 전
부모
커밋
c5189a5c87
2개의 변경된 파일16개의 추가작업 그리고 0개의 파일을 삭제
  1. 10
    0
      lib/chervil/core.rb
  2. 6
    0
      spec/core_spec.rb

+ 10
- 0
lib/chervil/core.rb 파일 보기

92
         else
92
         else
93
           error
93
           error
94
         end
94
         end
95
+      end,
96
+      "cons" => Proc.new do |args|
97
+        error = arity_check(args, 2)
98
+        if error.nil?
99
+          el, els = args
100
+          error = type_check([els], Array)
101
+          if error.nil?
102
+            els.prepend(el)
103
+          end
104
+        end
95
       end
105
       end
96
     }
106
     }
97
   end
107
   end

+ 6
- 0
spec/core_spec.rb 파일 보기

57
         Error.new("`car` expects a non-empty list")
57
         Error.new("`car` expects a non-empty list")
58
       )
58
       )
59
     end
59
     end
60
+
61
+    it 'implements cons' do
62
+      expect(Core::CORE['cons'].call([1.0, [2.0, 3.0]])).to eq(
63
+        [1.0, 2.0, 3.0]
64
+      )
65
+    end
60
   end
66
   end
61
 end
67
 end

Loading…
취소
저장