Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define s '"")
- (define (count lst len)
- (cond ((null? lst) 0)
- ((PAIR? lst) len)
- (else (+ 1 (
- ;(cond (( EQUAL? '() (cdr '( 4 )) ) "hello" ) )
- count (cdr s (+ len 1) )
- )))))
- (define (count1 lst len)
- ;(display lst)
- ;(display (not (PAIR? lst)) )
- ;(display "\n")
- (cond ((null? lst) len )
- ((not (PAIR? lst)) len )
- (else (
- count1 (cdr lst ) (+ len 1)
- ))))
- (define (cc c)
- c
- )
- (define (check li copy possible_pair_position)
- ; (display (PAIR? (cdr li)))
- ; (display (LIST? (cdr li)))
- #|(display "\n")
- (display (PAIR? li))
- (display (LIST? li))
- (display (PAIR? (cdr li)))
- (display (cdr li) )
- (display possible_pair_position)
- (display copy)
- (display "\n")|#
- #| (display "\n")
- (display (PAIR? (cdr li)))
- (display li)
- (display (cdr li))
- (display "\n")|#
- (cond ((null? li) copy )
- ( (and (= possible_pair_position 1 ) (PAIR? li) (LIST? li) )
- ;;(display copy) (display li)
- ;;(display (car li))
- ;;(display (cdr li))
- (cons (car li) copy ) )
- ( (and (= possible_pair_position 1 ) (PAIR? li) (not (LIST? li)) )
- ;;(display copy) (display li)
- ;;(display (car li))
- ;;(display (cdr li))
- ;; (display li)
- (cons li copy ) )
- ( (= possible_pair_position 1 )
- (display (cdr li)) (cons (car li) copy ) )
- (else
- #| (display "\n")
- (display (null? li))
- (display li)
- (display copy)
- (display "\n")
- (display (car li))|#
- (check (cdr li ) (cons (car li) copy ) (- possible_pair_position 1) )
- )
- )
- )
- (define (second my_list)
- (define len ( count1 my_list 0) )
- (cond ((< len 2) "less than 2")
- ((= len 2) '() )
- (else ( check (cddr my_list) '() (- len 2) )
- )
- )
- )
- (define r '() )
- (define (first my_list)
- (cond ((< ( count1 my_list 0) 2) '("less than 2" "fff") )
- ((> ( count1 my_list 0) 1)
- (cond ((PAIR? (cdr my_list))
- (set! r (cons ( cdr my_list) r))
- (set! r (cons (car my_list) r))
- ;(display (cdr my_list))
- r
- )
- (else (
- (set! r (cons (car (cdr my_list)) r))
- ;(display r)
- (set! r (cons (car my_list) r))
- )
- )
- )
- r )
- (else '(car my_list)
- )
- )
- )
- (define (parse_pair t)
- (cond ((null? t) 0)
- (else (+ 1
- (parse_pair (cdr t))
- ))))
- (define (parse_not_right_list my_list)
- (cond ((LIST? my_list) "LIST")
- ((PAIR? my_list) (parse_pair my_list))
- )
- )
- ;(count1 '( 4 5 5 5 5 . 6) 0)
- ;(first '(5 6 . 2 ) )
- (define x '(5 4 6 5 (1 . 5) (5 . 2) ) )
- (display x)
- (PAIR? '(2 . 22))
- (second x)
- ;(define x '(3 5 5 6 5 6 2 4 (5 . 4) 7))
- ;(LIST? x)
- ;(check x '())
- ;(second '(5 (6 . 2) 5 53))
- #|(cond ((null? '() ) "HH"))
- (PAIR? '( 4 . 8) )
- (cond (ATOM? cdr '( 4 . 8 )) )
- (cond (( EQUAL? '() (cdr '( 4 . 8 )) ) "hello" ) )|#
- #|( cdr '( 4 . (6 5 5 4)) )
- (parse_not_right_list '(4 5
- 6 2 5 4))
- (define x '( 4 5 6 2 5 5 6 4 6 3 ))
- (first x)
- (second x)|#
- ;(parse_pair x)
- #|(count '(4 5 4 2 5 3 5))
- (define sec (second '(2 3 5 4)))
- (define fir (first '(2 3 5 4)))
- (define re '() )
- (set! re (cons sec '()))
- (set! re (cons fir re))|#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement