mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 18:58:30 +00:00
refactor!: rename Array
-> List
This commit is contained in:
parent
41bf14629b
commit
c6eb78a44d
248 changed files with 1948 additions and 1985 deletions
|
@ -1,13 +0,0 @@
|
|||
arr = [0, 1, 2]
|
||||
zeros = [0; 3]
|
||||
|
||||
assert arr[0] == 0
|
||||
assert zeros[2] == 0
|
||||
|
||||
print! arr[3] # This will result in a compile-time error!
|
||||
|
||||
mut_arr = ![]
|
||||
for! 0..<10, i =>
|
||||
mut_arr.push! i
|
||||
|
||||
assert sum(mut_arr) == 45
|
|
@ -1,16 +1,16 @@
|
|||
arr as [Nat; 3] = [1, 2, 3]
|
||||
a2 = arr.map(x -> x + 1).filter(x -> x <= 3).into_array()
|
||||
a2 = arr.map(x -> x + 1).filter(x -> x <= 3).to_list()
|
||||
assert a2 == [2, 3]
|
||||
a3 = arr.skip(1).into_array()
|
||||
a3 = arr.skip(1).to_list()
|
||||
assert a3 == [2, 3]
|
||||
assert arr.nth(0) == 1
|
||||
a4 = arr.enumerate().map(((i, x),) -> x + i).into_array()
|
||||
a4 = arr.enumerate().map(((i, x),) -> x + i).to_list()
|
||||
assert a4 == [1, 3, 5]
|
||||
a5 = arr.reduce 0, (acc, x) -> acc + x
|
||||
assert a5 == 6
|
||||
assert arr.all x -> x <= 3
|
||||
assert arr.any x -> x == 2
|
||||
a6 = arr.chain(arr).into_array()
|
||||
a6 = arr.chain(arr).to_list()
|
||||
assert a6 == [1, 2, 3, 1, 2, 3]
|
||||
idx = arr.position i -> i == 2
|
||||
assert idx == 1
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
IntList = Class NoneType or { .node = Int; .next = IntList }
|
||||
IntList.
|
||||
null = IntList None
|
||||
insert self, node = IntList { .node; .next = self }
|
||||
fst self =
|
||||
match self::base:
|
||||
{ node; next = _ } => node
|
||||
None => None
|
||||
arr = [0, 1, 2]
|
||||
zeros = [0; 3]
|
||||
|
||||
l = IntList.null.insert 1
|
||||
assert l.fst() == 1
|
||||
assert arr[0] == 0
|
||||
assert zeros[2] == 0
|
||||
|
||||
print! arr[3] # This will result in a compile-time error!
|
||||
|
||||
mut_arr = ![]
|
||||
for! 0..<10, i =>
|
||||
mut_arr.push! i
|
||||
|
||||
assert sum(mut_arr) == 45
|
||||
|
|
|
@ -5,7 +5,7 @@ w = v
|
|||
print! w
|
||||
print! v # this should cause a MoveError
|
||||
|
||||
push! |T| a: RefMut(Array!(T, _)), value: T =
|
||||
push! |T| a: RefMut(List!(T, _)), value: T =
|
||||
a.push! value
|
||||
|
||||
push! w, 2
|
||||
|
|
11
examples/mylist.er
Normal file
11
examples/mylist.er
Normal file
|
@ -0,0 +1,11 @@
|
|||
IntList = Class NoneType or { .node = Int; .next = IntList }
|
||||
IntList.
|
||||
null = IntList None
|
||||
insert self, node = IntList { .node; .next = self }
|
||||
fst self =
|
||||
match self::base:
|
||||
{ node; next = _ } => node
|
||||
None => None
|
||||
|
||||
l = IntList.null.insert 1
|
||||
assert l.fst() == 1
|
Loading…
Add table
Add a link
Reference in a new issue