Advertisement
MarkUa

GET LAST LIST ITEM

Sep 23rd, 2019
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.43 KB | None | 0 0
  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.            (( EQ? my_list '() ) '() )
  55.            (( = 1 1)   (get_by_index my_list (count_ my_list 0))  )
  56.      
  57.       )
  58.   )
  59.  
  60.  (calculete  "ff")
  61.   (calculete  '())
  62.    (calculete  '(4 53 5345435 555))
  63.     (calculete  '(3 5 53 6 7 4 3 . 5))
  64.       (calculete  '(3 5 53 6 7 (4 3  5 6 . 6) ))
  65.       (calculete  '( 3 . 5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement