What Is Y

Y recursive your life without stop

length

evens-only and its collector

(define evens-only*
  (lambda (l)
    (letrec ((atom? (lambda (a)
                      (and (not (pair? a)) (not (null? a)))))
            ;; error definition of even
            ;; (even? (lambda (n)
            ;;          (= (* (/ n 2) 2) n)))
             )
      (cond
        ((null? l) (quote ()))
        ((atom? (car l))
         (let ((evencdr (evens-only* (cdr l))))
           (cond
             ((even? (car l))
              (cons (car l) evencdr))
             (else evencdr))))
        (else (cons (evens-only* (car l))
                    (evens-only* (cdr l))))))))
 (evens-only* '(1 3 4 6 3 (3 6 3 (3 6 21 3))))



(define evens-only*col
  (lambda (l col)
    (letrec ((atom? (lambda (a)
                      (and (not (pair? a)) (not (null? a))))))
      (cond
        ((null? l) (col (quote ()) 1 0))
        ((atom? (car l))
           (cond
             ((even? (car l))
              (evens-only*col (cdr l)
                              (lambda (newl p s)
                                (col (cons (car l) newl)
                                     (* (car l) p)
                                     s))))
             (else
              (evens-only*col (cdr l)
                              (lambda (newl p s)
                                (col newl p
                                     (+  (car l) s)))))))
        (else
         (evens-only*col (car l)
                         (lambda (al ap as)
                           (evens-only*col (cdr l)
                                           (lambda (dl dp ds)
                                             (col (cons al dl)
                                                  (* ap dp)
                                                  (+ as ds)))))))))))

(define the-last-friend
  (lambda (newl product sum)
    (cons sum
          (cons product
               (cons newl '())))))

 (evens-only*col '(1 3 4 6 3 (3 6 3 (3 6 21 3))) the-last-friend)


last forever and will stop?

;; will you become 隽永 forever?
;; will the program run always?

;; the function eternity we wan't execute it, because it will not stop, it don't know how to stop it
;; just like the life in the earth
(define eternity
  (lambda (x)
    (eternity x)))
;; what does shift do? the function shift takes a pair whose first component is a pair and builds a pair
;; by shifting the second part of the first component into the second componnent
(define shift
  (lambda (pair)
    (let ((first car)
          (second cdr)
          (build cons))
      (build (first (first pair))
             (build (second (first pair))
                    (second pair))))))
(shift '((a b) c))
(shift '((a b) (c d)))
(define weight*
  (lambda (para)
    (letrec ((atom? (lambda (a)
                      (and (not (null? a)) (not (pair? a)))))
             (first car)
             (second cdr))
      (cond
        ((atom? para) 1)
        (else (+ (* (weight* (first para)) 2)
                 (weight* (second para))))))))
;;(weight* '((a b) c))
;;(weight* '(q (c d)))

;;length0
((lambda (l)
   (cond
     ((null? l) 0)
     (else
      (add1 (eternity (cdr l))))))
 '())

many length first type(repeted)

;;length0
((lambda (l)
   (cond
     ((null? l) 0)
     (else
      (add1 (eternity (cdr l))))))
 '())
;;length1
((lambda (l)
   (cond
     ((null? l) 0)
     (else
      (add1
       ((lambda (l)
          (cond
            ((null? l) 0)
            (else (add1 (eternity (cdr l))))))
        (cdr l))))))
 '(1))


;;length2
((lambda (l)
   (cond
     ((null? l) 0)
     (else
      (add1
       ((lambda (l)
          (cond
            ((null? l) 0)
            (else (add1
                   ((lambda (l)
                           (cond
                             ((null? l) 0)
                             (else (add1 (eternity (cdr l))))))
                         (cdr l))))))
        (cdr l))))))
 '(1 2))



;;; length3
((lambda (l)
   (cond
     ((null? l) 0)
     (else
      (add1
       ((lambda (l)
          (cond
            ((null? l) 0)
            (else (add1
                   ((lambda (l)
                           (cond
                             ((null? l) 0)
                             (else (add1
                                    ((lambda (l)
                                       (cond
                                         ((null? l) 0)
                                         (else (add1 (eternity (cdr l))))))
                                     (cdr l))))))
                         (cdr l))))))
        (cdr l))))))
 '(1 2 3))



;;; length4
((lambda (l)
   (cond
     ((null? l) 0)
     (else
      (add1
       ((lambda (l)
          (cond
            ((null? l) 0)
            (else (add1
                   ((lambda (l)
                           (cond
                             ((null? l) 0)
                             (else (add1
                                    ((lambda (l)
                                       (cond
                                         ((null? l) 0)
                                         (else (add1
                                                ((lambda (l)
                                                   (cond
                                                     ((null? l) 0)
                                                     (else (add1 (eternity (cdr l))))));; we don't want to execute eternity function
                                                 (cdr l))))))
                                     (cdr l))))))
                         (cdr l))))))
        (cdr l))))))
 '(1 2 3 4))


many length second type(repeated)

识别你的模式 recognize the pattern!!! All the function or programs contain a function looks just like length but start with (lambda (length …)

;;length0
(((lambda (length)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else (add1
               (length (cdr l)))))))
  eternity)
 '())

;;;length1

(((lambda (f)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else (add1
               (f (cdr l)))))))
  ((lambda (g)
     (lambda (l)
       (cond
         ((null? l) 0)
         (else
          (add1 (g (cdr l)))))))
   eternity))
 '(1))


;;;length2

(((lambda (f)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else (add1
               (f (cdr l)))))))
  ((lambda (g)
     (lambda (l)
       (cond
         ((null? l) 0)
         (else
          (add1 (g (cdr l)))))))
   ((lambda (h)
      (lambda (l)
        (cond
          ((null? l) 0)
          (else
           (add1 (h (cdr l)))))))
   eternity)))
 '(1 2))


;;;length3

(((lambda (f)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else (add1
               (f (cdr l)))))))
  ((lambda (g)
     (lambda (l)
       (cond
         ((null? l) 0)
         (else
          (add1 (g (cdr l)))))))
   ((lambda (h)
      (lambda (l)
        (cond
          ((null? l) 0)
          (else
           (add1 (h (cdr l)))))))
    ((lambda (k)
       (lambda (l)
         (cond
           ((null? l) 0)
           (else (add1 (k (cdr l)))))))
     eternity))))
 '(1 2 3))

more better length(With less repeated part)

(((lambda (mk-length)
    (mk-length eternity))
  (lambda (length)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else (add1 (length (cdr l))))))))
 '())


;; length1
(((lambda (mk-length)
    (mk-length
     (mk-length eternity)))
  (lambda (length)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else (add1 (length (cdr l))))))))
 '(1))



;; length2
(((lambda (mk-length)
    (mk-length
     (mk-length
      (mk-length eternity))))
  (lambda (length)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else (add1 (length (cdr l))))))))
 '(1 2))

;; length3

(((lambda (mk-length)
    (mk-length 
     (mk-length
      (mk-length
       (mk-length eternity)))))
  (lambda (length)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else (add1 (length (cdr l))))))))
 '(1 2 3))


we don’t care eternity, just use mk-length or others instead ,

;;; We don't care what eternity does, so let's use mk-length instead eternity

;;length0
((lambda (mk-length)
   (mk-length mk-length))
 (lambda (length)
   (lambda (l)
     (cond
       ((null? l) 0)
       (else
        (add1 (length (cdr l))))))))

;;length0  instead length with mk-length
(((lambda (mk-length)
   (mk-length mk-length))
 (lambda (mk-length)
   (lambda (l)
     (cond
       ((null? l) 0)
       (else
        (add1 (mk-length (cdr l))))))))
 '())

;; we could use (mk-length eternity) to make them run once

(((lambda (mk-length)
    (mk-length mk-length))
  (lambda (mk-length)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else
         (add1 ((mk-length eternity) (cdr l))))))))
 '(1))


;;; function we could use mk-length instead eternity , to let them execute one by one
;;; just length

(((lambda (mk-length)
    (mk-length mk-length))
  (lambda (mk-length)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else
         (add1 ((mk-length mk-length) (cdr l))))))))
 '(1 3 5 2))

;; funny (lambda (x) ((f f) x) =(f x)

(((lambda (mk-length)
    (mk-length mk-length))
  (lambda (mk-length)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else
         (add1 ((lambda (x)
                  ((mk-length mk-length) x))
                  (cdr l))))))))
 '(1 3 5 2))

;;; give the pattern (lambda (x) ((mk-length mk-length) x))  a name , le or length
(((lambda (mk-length)
    (mk-length mk-length))
  (lambda (mk-length)
    ((lambda (length)
       (lambda (l)
         (cond
           ((null? l) 0)
           (else (add1 (length (cdr l)))))))
     (lambda (x)
       ((mk-length mk-length) x)))))
 '(1 2 3 3))
;; move length pattern behind

funny Y

what is Y! Hard to figure out!

(((lambda (le)
   ((lambda (mk-length)
      (mk-length mk-length))
    (lambda (mk-length)
      (le (lambda (x)
            ((mk-length mk-length) x))))))
  (lambda (length)
    (lambda (l)
      (cond
        ((null? l) 0)
        (else (add1 (length (cdr l))))))))
 '(1 2 3 4 5 7 8))

(define Y
  (lambda (le)
    ((lambda (mk-length)
       (mk-length mk-length))
     (lambda (mk-length)
       (le (lambda (x)
             ((mk-length mk-length) x)))))))

((Y (lambda (length)
      (lambda (l)
        (cond
          ((null? l) 0)
          (else (add1 (length (cdr l))))))))
 '(1 3 6 5))

(define Y2
  (lambda (fun)
    ((lambda (f)
       (f f))
     (lambda (f)
       (fun (lambda (x)
              ((f f) x)))))))

((Y2 (lambda (length)
       (lambda (l)
         (cond
           ((null? l) 0)
           (else (add1 (length (cdr l))))))))
 '(3 6 8 3 20 94 ))
Related
叶昭良
叶昭良
Engineer of offshore wind turbine technique research

My research interests include distributed energy, wind turbine power generation technique , Computational fluid dynamic and programmable matter.