Advertisement
ldevillez

Sequence

Nov 18th, 2016
2,540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 0.65 KB | None | 0 0
  1. attr a1
  2. meth init a1 := nil end
  3. meth isEmpty($) if @a1 == nil then true else false end end
  4. meth first($) case @a1 of H|T then H else nil end end
  5. meth last($)
  6.     local Last in
  7.         fun{Last L}
  8.             case L
  9.             of H|nil then H
  10.             []H|T then {Last T}
  11.             else L
  12.             end
  13.         end
  14.         {Last @a1}
  15.     end
  16. end
  17. meth insertFirst(X) a1 := X|@a1 end
  18. meth insertLast(X) a1 := {Append @a1 [X]} end
  19. meth removeFirst a1 := @a1.2 end
  20. meth removeLast
  21.     local Last in
  22.         fun{Last L}
  23.             case L
  24.             of H|nil then nil
  25.             [] H|T then H|{Last T}
  26.             else nil
  27.             end
  28.         end
  29.         a1 := {Last @a1}
  30.       end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement