from stew.core import Sort, generator, operation
from stew.matching import var
from collections.abc import Sequence


class Liste(Sort):

    def __init__(self, *args, **kwargs):
        if(len(args) == 1) and isinstance(args[0], Sequence):
            Sort.__init__(self)

            if len(args[0]) == 0:
                self._generator = Liste.empty
            else:
                self._generator = Liste.cons
                self._generator_args = {'self': Liste(args[0][:-1]), 'other': args[0][-1]}
        else:
            Sort.__init__(self, **kwargs)

    @generator
    def empty() -> Liste:
        pass

    @generator
    def cons(self: Liste, other: Sort) -> Liste:
        pass

    @operation
    def append(self: Liste, other: Liste) -> Liste:
        # x + [] = x
        if other == Liste.empty():
            return self

        #  x + (y,c) = cons(x + y, c)
        if other == Liste.cons(var.y, var.c):
            return Liste.cons(self.append(var.y), var.c)

@@ -121,17 +121,16 @@
 ass List
-e
 (Sort):%0A
@@ -334,25 +334,24 @@
 rator = List
-e
 .empty%0A     
@@ -397,25 +397,24 @@
 rator = List
-e
 .cons%0A      
@@ -452,20 +452,19 @@
 = %7B'
-self
+tail
 ': List
-e
 (arg
@@ -476,21 +476,20 @@
 :-1%5D), '
-other
+head
 ': args%5B
@@ -583,33 +583,32 @@
  empty() -%3E List
-e
 :%0A        pass%0A%0A
@@ -635,34 +635,32 @@
 ef cons(
-self
+tail
 : List
-e
 , 
-other
+head
 : Sort) 
@@ -658,33 +658,32 @@
 d: Sort) -%3E List
-e
 :%0A        pass%0A%0A
@@ -709,40 +709,38 @@
 def 
-append(self
+__add__(tail
 : List
-e
 , 
-other
+head
 : List
-e
 ) -%3E
@@ -744,17 +744,16 @@
  -%3E List
-e
 :%0A      
@@ -778,29 +778,28 @@
      if 
-other
+head
  == List
 e.empty(
@@ -790,17 +790,16 @@
  == List
-e
 .empty()
@@ -823,13 +823,90 @@
 urn 
-self%0A
+tail%0A        # %5B%5D + y = y%0A        if tail == List.empty():%0A            return head
 %0A   
@@ -955,21 +955,20 @@
  if 
-other
+head
  == List
 e.co
@@ -967,22 +967,31 @@
 List
-e
 .cons(
+tail=
 var.y, 
+head=
 var.
@@ -1021,35 +1021,38 @@
 List
-e
 .cons(
-self.append(
+tail=tail + 
 var.y
-)
 , 
+head=
 var.

add working __add__ for list