Gidsss / UwUIDE

A compiler made to be cute uwu >~<
6 stars 0 forks source link

more array builtin methods #277

Closed am-cid closed 4 months ago

am-cid commented 4 months ago

definition of terms

  1. unit type
    • it is the type of the element in the array
    • eg: chan[3]'s unit type is chan[2]
  2. array type
    • it is the type of the array it can be an element in
    • eg: chan[3]'s array type is chan[4]

new

  1. dimension()
    • no args
    • returns an Int describing the dimension of the array
  2. replace(arg1, arg2)
    • takes in 2 unit types of the array
    • replaces the arg1 in the array with arg2
      • if it does not exist, this will do nothing
    • edits in place, returns nuww
  3. first(n)
    • takes in an Int
    • gets the first element up to n
      • a-chan[] = {1,2,3,4}~
        pwint(a.first(2))~ >.< prints {1,2}
      • returns empty array if n <= 0
    • returns a copy of the array; eg if chan[3].first(2), it will return a chan[3] with <=2 elements
  4. last(n)
    • takes in an Int
    • gets the last element up to n
      • a-chan[] = {1,2,3,4}~
        pwint(a.last(2))~ >.< prints {3,4}
      • returns empty array if n <= 0
    • returns a copy of the array; eg if chan[3].last(2), it will return a chan[3] with <=2 elements
  5. shift()
    • no args
    • like pop() but for the first element instead of the last element
    • removes the first element from the array and returns it
    • returns unit type of the array; eg if chan[3].shift(), it will return a chan[2]
    • note: you tried to shift() an empty array, it will raise a ShiftError. in uwu terms, it will cause a runtime error

      change

  6. pop()
    • instead of just removing the last item, it will also return the last item
    • returns unit type of the array; eg if chan[3].pop(), it will return a chan[2]
    • note: if you tried to pop() an empty array, it will raise a PopError. in uwu terms, it will cause a runtime error