mirror of
https://github.com/kanaka/mal.git
synced 2024-09-11 13:55:55 +03:00
ruby: concat should not modify its argument
This commit is contained in:
parent
5b207de75e
commit
05ad2bf6cd
@ -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