
((wrap (vau root_env (quote)
((wrap (vau (let1)
(let1 lambda (vau se (p b1) (wrap (eval (array vau p b1) se)))
(let1 current-env (vau de () de)
(let1 cons (lambda (h t) (concat (array h) t))
(let1 Y (lambda (f3)
    ((lambda (x1) (x1 x1))
     (lambda (x2) (f3 (lambda (& y) (lapply (x2 x2) y))))))
(let1 vY (lambda (f)
    ((lambda (x3) (x3 x3))
     (lambda (x4) (f (vau de1 (& y) (vapply (x4 x4) y de1))))))
(let1 let (vY (lambda (recurse) (vau de2 (vs b) (cond (= (len vs) 0) (eval b de2)
                                                     true           (vapply let1 (array (idx vs 0) (idx vs 1) (array recurse (slice vs 2 -1) b)) de2)))))
 (let (
         rec-lambda (vau se (n p b) (eval (array Y (array lambda (array n) (array lambda p b))) se))
         cdr (lambda (x) (slice x 1 -1))
         if (vau de (con than & else) (eval (array cond con  than
                                                        true (cond (> (len else) 0) (idx else 0)
                                                        true             false)) de))
         and (let (macro_helper (rec-lambda recurse (bs i) (cond (= i       (len bs)) true
                                                                 (= (+ 1 i) (len bs)) (idx bs i)
                                                                 true       (array let (array 'tmp (idx bs i)) (array if 'tmp (recurse bs (+ i 1)) 'tmp)))))
                  (vau se (& bs) (eval (macro_helper bs 0) se)))

        ; if len(s1) > 0 && len(sub) > 0:
        ;   char1 = s1[0]
        ;   rest1 = s1[1:]
        ;   char2 = sub[0]
        ;   rest2 = sub[1:]
        ;   if char1 == char2:
        ;       return recurse(rest1, rest2)
        ;   else
        ;       return false
        ; else if len(s1) > 0 && len(sub) == 0:
        ;   return true
        ; else if len(s1) == 0:
        ;   return false
        ; else:
        ;   return false
        ;
        ;
         compare_substr (rec-lambda cmp (str1 str2) (let (
                                                         str1_len (len str1)
                                                         str2_len (len str2))
                                                               ; len(s1) > 0 && len(sub) > 0
                                                         (cond (and (> str1_len 0) (> str2_len 0))
                                                                 (let (
                                                                    char1 (idx str1 0)
                                                                    rest1 (cdr str1)
                                                                    char2 (idx str2 0)
                                                                    rest2 (cdr str2)
                                                                    same_char (= char1 char2)
                                                                    ; if char1 == char2: return recurse(str, sub)
                                                                    ; else: return false
                                                                 ) (cond same_char (cmp rest1 rest2)
                                                                         true false
                                                                    ))
                                                               ; len(s1) > 0 && len(sub) == 0
                                                               (and (> str1_len 0) (= str2_len 0)) true
                                                               ; else
                                                               true false
                                                         )
                                                        ))
         ; i = index of current match start, passed in
         ; len1 = len(str)
         ; len2 = len(sub)
         ;
         ; if len2 > len1:
         ;   return -1
         ; else if len1 > 0 && len2 == 0:
         ;   // No more substr, we matched?
         ;   return i
         ; else if len1 > 0 && len2 > 0:
         ;   if compare(str, sub):
         ;      return i
         ;   else:
         ;      rest1 = str[1:]
         ;      return recurse(rest1, sub, i+1)
         ; else
         ;   return -1
         ;
         _find (rec-lambda _find (str sub i) (let (
                                                  len1 (len str)
                                                  len2 (len sub)
                                                 ) (cond (> len2 len1)               -1
                                                         (= len2 0)                  i
                                                         (and (> len1 0) (> len2 0)) (cond (compare_substr str sub) i
                                                                                           true                     (_find (cdr str) sub (+ i 1)))
                                                         true                        -1
                                                  )))
         ; find the index of a substr in a str
         ; check if a substr is in a str
         find (lambda (str sub) (_find str sub 0))
         contains (lambda (str sub) (!= (find str sub) -1))

         monad  (array 'write  1 "testing find funcs: \n" (vau (written code)
                    (array 'write 1 "find in \"foobar\" the string \"oba\"\n" (vau (written code) 
                        (array 'write 1 (concat (str (contains "foobar" "oba")) "\n") (vau (written code)
                            (array 'exit 0)))
                            ))
                ))

 ) monad)
; end of all lets
))))))
; impl of let1
)) (vau de (s v b) (eval (array (array wrap (array vau (array s) b)) v) de)))
; impl of quote
)) (vau (x5) x5))
