mirror of
https://github.com/kanaka/mal.git
synced 2024-09-20 18:18:51 +03:00
Merge pull request #185 from dubek/ruby-fix-concat
ruby: concat should not modify its argument
This commit is contained in:
commit
f8ce846d63
@ -46,7 +46,7 @@ $core_ns = {
|
||||
|
||||
:sequential? => lambda {|a| sequential?(a)},
|
||||
:cons => lambda {|a,b| List.new(b.clone.insert(0,a))},
|
||||
:concat => lambda {|*a| List.new(a && a.reduce(:concat) || [])},
|
||||
:concat => lambda {|*a| List.new(a && a.reduce(:+) || [])},
|
||||
:nth => lambda {|a,b| raise "nth: index out of range" if b >= a.size; a[b]},
|
||||
:first => lambda {|a| a.nil? ? nil : a[0]},
|
||||
:rest => lambda {|a| List.new(a.nil? || a.size == 0 ? [] : a.drop(1))},
|
||||
|
@ -8,6 +8,12 @@
|
||||
(cons (list 1) (list 2 3))
|
||||
;=>((1) 2 3)
|
||||
|
||||
(def! a (list 2 3))
|
||||
(cons 1 a)
|
||||
;=>(1 2 3)
|
||||
a
|
||||
;=>(2 3)
|
||||
|
||||
;; Testing concat function
|
||||
(concat)
|
||||
;=>()
|
||||
@ -20,6 +26,14 @@
|
||||
(concat (concat))
|
||||
;=>()
|
||||
|
||||
(def! a (list 1 2))
|
||||
(def! b (list 3 4))
|
||||
(concat a b (list 5 6))
|
||||
;=>(1 2 3 4 5 6)
|
||||
a
|
||||
;=>(1 2)
|
||||
b
|
||||
;=>(3 4)
|
||||
|
||||
;; Testing regular quote
|
||||
(quote 7)
|
||||
|
Loading…
Reference in New Issue
Block a user