Advertisement
MarkUa

get Last Element of list

Sep 21st, 2019
3,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (define (not_ item)
  2.    (
  3.       cond ((EQ? item #f) #t)
  4.             ( #t #f)
  5.      
  6.  
  7.     )
  8. )
  9.  
  10. (define (and_  item1 item2)
  11.      
  12.      (cond ((EQ? item1 #f) #f)
  13.            ((EQ? item2 #f) #f)
  14.      (#t #t)
  15.      )
  16.  
  17. )
  18.  
  19. (define (or_ item1 item2)
  20.         ( not_ (and_ (not_ item1) (not_ item2) ) )
  21.  
  22. )
  23.  
  24. (define (count_ lst len)
  25.  
  26.  (cond ((EQV? lst '() ) len  )
  27.         ((not_ (PAIR? lst)) len )
  28.         ( (= 1 1)  (
  29.                     count_ (cdr lst  ) (+ len 1)
  30.  
  31.                            ))))
  32.  
  33.  
  34. (define (get_by_index  array index)
  35.     (cond ((= index 1)
  36.  
  37.                        (cond (( and_  (PAIR?  (car array))   (not_ (LIST? (car array))) )
  38.                              
  39.                               array
  40.  
  41.                               )
  42.                               ((LIST? array)  (car array) )
  43.                               ((= 1 1) array)
  44.                              )
  45.                        )
  46.           ((= 1 1) (get_by_index  (cdr array)  (  - index 1) ) )
  47.     )      
  48. )
  49.  
  50.  
  51. (define (calculete my_list)
  52.    
  53.      (cond ((and_  (not_ (LIST? my_list)) (not_ (PAIR? my_list))) "atom" )
  54.            (( = 1 1)   (get_by_index my_list (count_ my_list 0))  )
  55.      
  56.       )
  57.   )
  58.  
  59.  (calculete  "ff")
  60. ;(get_by_index '(3 4 5 3  44 5  6  ) (count_ '(3 4 5 3 5 6 5) 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement