Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (not_ item)
- (
- cond ((EQV? item #f) #t)
- ( #t #f)
- )
- )
- (define (and_ item1 item2)
- (cond ((EQV? item1 #f) #f)
- ((EQV? item2 #f) #f)
- (#t #t)
- )
- )
- (define (or_ item1 item2)
- ( not_ (and_ (not_ item1) (not_ item2) ) )
- )
- ; list length
- (define (count_ lst len)
- (cond ((EQV? lst '() ) len )
- ((not_ (PAIR? lst)) len )
- ( (= 1 1) (
- count_ (cdr lst ) (+ len 1)
- ))))
- ; reverse list
- (define (reverse_ list_ result position )
- (define len ( count_ list_ 0) )
- (cond ((= len 0) result )
- ( (and_ (= position 1 ) (and_ (PAIR? list_) (LIST? list_)) )
- (cons (car list_) result ) )
- ( (and_ (= position 1 ) (and_ (PAIR? list_) (not_ (LIST? list_))) )
- (cons list_ result ) )
- ( (= 1 1)
- (reverse_ (cdr list_) (cons (car list_) result ) ( - position 1) )
- )
- )
- )
- ; check second part for different issues
- (define (check li copy possible_pair_position deep)
- (define len ( count_ li 0) )
- ; (display len)
- (cond ((= len 0 ) copy )
- ( (and_ (= possible_pair_position 1 ) (and_ (PAIR? li) (LIST? li)) )
- (reverse_ (cons (car li) copy ) '() deep) )
- ( (and_ (and_ (= possible_pair_position 1 ) (PAIR? li)) (not_ (LIST? li)) )
- (reverse_ (cons li copy ) '() deep) )
- ( (= possible_pair_position 1 )
- (cons (car li) copy ) )
- ((= 1 1)
- (check (cdr li ) (cons (car li) copy ) (- possible_pair_position 1) deep )
- )
- )
- )
- ;second part formatting
- (define (second my_list)
- (define len ( count_ my_list 0) )
- (cond ((< len 2) "less than 2")
- ((= len 2) '() )
- ((= 1 1) ( check (cddr my_list) '() (- len 2) (- len 2) )
- )
- )
- )
- ;first part formatting
- (define (first my_list)
- (cond ((and_ (not_ (LIST? my_list)) (not_ (PAIR? my_list))) "atom" )
- ((< ( count_ my_list 0) 2) "list size less than 2" )
- ((= ( count_ my_list 0) 2)
- (cond ((and_ (not_ (LIST? my_list)) (PAIR? my_list) )
- (cons (car my_list) (cons ( cdr my_list) '()))
- )
- ((= 1 1)
- (cons (car my_list) (cons ( cadr my_list) '() ))
- )
- ) )
- ((> ( count_ my_list 0) 2)
- (cons (car my_list) (cons ( cadr my_list) '() ) )
- )
- ((= 1 1) '(car my_list)
- )
- )
- )
- (define (combine_parts first_part x)
- (cond ( (EQ? first_part "atom" )
- "atom"
- )
- ((EQ? first_part "list size less than 2") "list size less than 2" )
- ((= 1 1)
- (cons first_part (cons (second x) '() ))
- )
- )
- )
- (define object_to_process '( 2 44 5 . 3 ) )
- (display object_to_process)
- (display "\n")
- (combine_parts (first object_to_process) object_to_process)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement