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

fatagcsere

(setq fa '((1 2(3 4 5)((7 8)(7 8 9)))))
(write fa)
(setq fa2 (subst 7 1 fa))
(terpri)
(write fa2)

Basic

(write-line "Hello World")

(write-line "I am at 'Tutorials Point'! Learning LISP")

member

(write (member 'zara '(ayan abdul zara riyan nuha)) )
(terpri)
(write (member-if #'evenp '(3 5 2 5/6 'a)))
(terpri)
(write (member-if-not #'numberp '(3 5 2 5/6 'a 'b 'c)))
; ezek a #' kezdésűek ilyen &key-ek, valamilyen tulajdonságát határozzák meg az értéknek

Execute LISP Online

(write-line "Mishchenko Alexandr, IP-63, LB3")

;Task 1
(defun fact (n) 
    (if (= n 0) 
        1
        (* n (fact (- n 1)))
    )
)

(print
    (fact 5)
)

;Task 6
(defun rw (text letter stringForChange &aux (e (search letter text)))
  (cond ((null e) (concatenate 'string nil text))
        ((concatenate 'string (subseq text 0 e) stringForChange 
        (rw (subseq text (1+ e)) letter stringForChange))))
)

(print 
    (rw "abrakadabra" "b" "123") 
)


Execute LISP Online

;Course:  CSCI 450
;By:      Eric Frey
;Due:     9/11/2018
;Program: Lab 1

(defun my-rotate (x)(append(cdr x) (list (car x))))

; (write(my-rotate '(a b c)))

(defun my-rotate-n (a tempList)
    (if (< a 1) (return-from my-rotate-n tempList))(
        my-rotate-n (- a 1) (append (cdr tempList) 
        (list (car tempList)))
    )
)
; (write(my-rotate-n 3 '(a b c d)))

(defun first-sat (listA listB foo)
    (if (null listB)()(
        if (null listA)()(
            if (funcall foo(car listA) (car listB))(
              ;if function returns true
              append (list(car listA)) (list(car listB)))(
              ;if function returns false
              first-sat(cdr listA) (cdr listB) foo)
        )
    ))
)
(write(first-sat '() '() (function (lambda (x y) (> x y)))))

(defun my-remove (a myList)
    (if (null myList) (return-from my-remove nil) (
    ;if list is not empty
        if (equal a (car myList))(
        ;if atom equals mylist
            my-remove a (cdr myList)
        )(
        ; if atom does not equal list
            if (atom (car myList)) (
            ;if atom is a list
                append (list (car myList)) (my-remove a (cdr myList))
            
            )(
            ;if atom is not a list
                append (list(my-remove a (car myList))) (my-remove a (cdr myList))
            )
        )
    ))
)
; (write (my-remove 'b '((a b) b (c b d e a) (b) (a) c)))

(defun remove-last (myList)
    ;helper function for palindromep to slice off end atom
    (if ( > (length myList) 1)(
        append (list (car myList)) (remove-last(cdr myList))
    ))
)

(defun palindromep (myList)
    (if ( < (length myList) 2) (
        return-from palindromep t
    )(
        if (equal(list(car myList)) (last myList))()(
            ;first and last atoms are not equal, return false
            return-from palindromep nil
        ))
    )
    (palindromep (remove-last (cdr myList)))
)

vektorvaltoztatas 2

(setq a (make-array 5 :fill-pointer 0))
; a fill-pointer az azt mutatja, hogy mennyi tagja engedett a vektornak\
;csak egydimenziós make-array-nél (?) működik
(write a)
(vector-push 'a a);ez a végére teszi az adott dolgot (az a vektornak)
(vector-push 'b a)
(vector-push 'c a)
(terpri)
(write a)
(terpri)
(vector-push 'd a)
(vector-push 'e a)
(vector-push 'f a); itt ez nem megy be a végére, mivel a vektor csak 5-ös
(write a)
(terpri)
(vector-pop a); ez letöröl egyet a végéről 
(vector-pop a)
(vector-pop a)
(write a)

LISP Programming

(write-line "Hello World")

(write-line "I am sudhanshu kumar! Learning LISP")

setf get mas sorrend

(setf (get 'konyv 'cim)'(iskola a határon))
(setf (get 'konyv 'szerzo)'(ottlik géza))
(setf (get 'konyv 'kiadó)'(mittom))
(write (get 'konyv 'cim))
(terpri)
(write (get 'konyv 'szerzo))
(terpri)
(write (get 'konyv 'kiadó))

setf get

(write (setf (get 'konyv'cim) '(iskola a határon)))
(terpri)
(write (setf (get 'konyv'szerzo)'(ottlik geza)))
(terpri)
(write (setf (get 'konyv 'kiado) '(mittom)))
(terpri)
(write (get 'konyv 'cim))
;szóval a get az meghatároz egy dolgot, annak a tulajdonságát, s a setf meg
;hozzárendel egy értéket

listafunkciok

(write (car '(a b c d e f)))
(terpri)
(write (cdr '(a b c d e f))); minden, kivéve az első
(terpri)
(write (cons 'a '(b c)))
(terpri)
(write (list 'a '(b c) '(e f))); ez itt egy lista sok listáról (?)
;lehet, hogy csak meghagyja a zárójeleket
(terpri)
(write (append '(b c) '(e f) '(p q) '() '(g))); ez meg simán egy lista
(terpri)
(write (last '(a b c d (e f)))); !
(terpri)
(write (reverse '(a b c d (e f))))
; a lista is szekvencia

Advertisements
Loading...

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