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 (reverse_ list_ result position )
- (cond ((null? list_) result )
- ( (and (= position 1 ) (PAIR? list_) (LIST? list_) )
- (cons (car list_) result ) )
- ( (and (= position 1 ) (PAIR? list_) (not (LIST? list_)) )
- (cons list_ result ) )
- (else
- (reverse_ (cdr list_) (cons (car list_) result ) ( - position 1) )
- )
- )
- )
- (define (check li copy possible_pair_position deep)
- (cond ((null? li) copy )
- ( (and (= possible_pair_position 1 ) (PAIR? li) (LIST? li) )
- (reverse_ (cons (car li) copy ) '() deep) )
- ( (and (= possible_pair_position 1 ) (PAIR? li) (not (LIST? li)) )
- (reverse_ (cons li copy ) '() deep) )
- ( (= possible_pair_position 1 )
- ; (display (cdr li))
- (cons (car li) copy ) )
- (else
- (check (cdr li ) (cons (car li) copy ) (- possible_pair_position 1) deep )
- )
- )
- )
- (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) (- len 2) )
- )
- )
- )
- (define r '() )
- (define (first my_list)
- (cond ((and (not (LIST? my_list)) (not (PAIR? my_list))) "atom" )
- ((< ( count1 my_list 0) 2) "list size less than 2" )
- ((= ( count1 my_list 0) 2)
- (cond ((and (not (LIST? my_list)) (PAIR? x) )
- (set! r (cons ( cdr my_list) r))
- (set! r (cons (car my_list) r))
- ;(display (cdr my_list))
- r )
- (else
- ; (display r)
- ;(display (cadr my_list))
- ;(display (car my_list) )
- (set! r (cons ( cadr my_list) r))
- (set! r (cons (car my_list) r))
- ;(display (cdr my_list))
- r )
- ) )
- ((> ( count1 my_list 0) 2)
- (set! r (cons ( cadr my_list) r))
- (set! r (cons (car my_list) r))
- ;(display (cdr my_list))
- 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 '( 2 44 5 . 3 ) )
- (display x)
- (display "\n")
- ;(display x)
- ;(PAIR? '(2 . 22))
- (define first_part (first x))
- (define second_part '() )
- (define result '())
- (cond ( (or (EQ? first_part "atom" ) (EQ? first_part "list size less than 2"))
- (display "could not make oparations because of ")
- (display first_part) )
- (else
- (set! second_part (second x))
- (set! result (cons second_part result))
- (set! result (cons first_part result))
- (display result)
- )
- )
- ;(second x)
- ;(reverse_ (second x) '() 5 )
- ;(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