Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

main

(defun combination (l n k pos last)
    (if (eq pos k)
     	(list (copy-list l))
    
        (if (AND (< last n) (< pos k) ) 
	    (append (combination (cons last l) n k (+ pos 1) last) (combination l n k pos (+ last 1))   )
            	    
	    (combination (cons last l) n k (+ pos 1) last )	    	  
        )
    )
)

(defun generator (n k)
    (combination '() n k 0 1 )       
)

(generator 5 3)

Execute LISP Online

(write-line "Hello World")

TestLisp

(write-line "Hello World")

teste

(car '((a b c d)))

Execute LISP Online

(write-line "Hello World")

Execute LISP Online

;; Подсчет вхождения атома в список
 
(defun counter (y x) (cond ((null x) 0)
                           ((eq y (car x)) (+ 1 (counter y (cdr x))))
                           (t  (counter y (cdr x)))))
 
;; Построение списка пар
 
(defun mkpair (x) (cond ((null x) nil)
                                 (t (append (list (list (car x) (counter (car x) x))) (mkpair (remove (car x) x))))))
 
 
;; Решение:
 
(defun task (x) (mkpair (collect (flatten x))))
 
==> task
(task '(((2) -3 (4) 0 -2)
          ( -4 0 2)
         ((-3) (3)-4 3) ))
 
==> ((2 2) (-3 2) (4 1) (0 2) (-2 1) (-4 2) (3 2))

permalink

(setq l1 &#39;(a s d f g h))
(setq l2 &#39;(1 2 3 5 6 a))

(defun verify (list1 list2)
(cond
((null list1) nil)
((not (eq(find (car list1) list2) nil)) (verify (cdr list1) list2) t)
))
(verify l1 l2)

Execute LISP Online

(write-line "Enter List:")

Execute LISP Online

(DEFUN EXAMPLE ()
  (MAIN '(2 -3 (4 3 0 2) (4 -4) (2 (2 0 2)) -3))
)

(DEFUN MAIN (L)
  (COND
    ((ATOM L)
      "Tika ievadits atoms"
    )
    (T
      (FILTER (FILTERLIST (GETLIST L)) L)
    )
  )
)

(DEFUN FILTER (X L)
  (COND
    ((NULL L) NIL)
    ((ATOM (CAR L))
      (COND
        ((OR (AND (ATOM X) (EQUAL X (CAR L)))
        (AND (NOT (ATOM X)) (NOT (NULL (MEMBER (CAR L) X)))))
          (FILTER X (CDR L)))
        (T
          (CONS (CAR L) (FILTER X (CDR L)))
        )
      )
    )
    (T
      (CONS (FILTER X (CAR L)) (FILTER X (CDR L)))
    )
  )
)

(DEFUN FILTERLIST (L)
  (COND
    ((NULL L) NIL)
    (T
      (CONS (CAR L) (FILTERLIST (FILTER (LIST (CAR L) (- 0 (CAR L))) (CDR L))))
    )
  )
)

(DEFUN GETLIST (L)
  (COND
    ((NULL L) NIL)
    ((ATOM (CAR L))
      (COND
        ((OR (NOT (NUMBERP (CAR L))) (ZEROP (CAR L)))
          (GETLIST (CDR L))
        )
        (T
          (CONS (- 0 (CAR L)) (GETLIST (CDR L))))
        )
      )
    (T
      (APPEND (GETLIST (CAR L)) (GETLIST (CDR L)))
    )
  )
)

kiki

(write-line "Hello World")

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.