ldevillez

Sequence

Nov 18th, 2016
514
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×