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

poke4i

(setq s (read))
(setq e (read))
(setq r (read))
(setq h (read))
(case (read)
(1 (setq m (*(/ e (/ 40 3))(/ (+ (* r 8) h) 9)s))(format t "~f" m))
(2 (setq m (*(/ e (/ 40 3))(/ (+ (* r 5) h) 6)s)) (write (float m)))
(3 (setq m (*(/ e (/ 40 3))(/ (+ (* r 3) h) 4)s))(write (float m))))

Execute LISP Online

(write-line "Hello World")
;get the list of all atoms
;(((A B) C) (D E)) ==> (A B C D E)

(DEFUN fct(L)
    (COND
        ((NULL L) NIL)
        ((ATOM (CAR L)) (CONS (CAR L) (fct (CDR L))))
        ((LISTP (CAR L)) (APPEND (fct (CAR L)) (fct (CDR L))))
    )
)

(write(fct '(((A B) C) (D E) F) ))

Execute LISP Online

;a)
;sum of two vectors

(DEFUN sum(V)
    (COND
        ((NULL V) 0)
        (T (+ (CAR V) (sum (CDR V))))
    )
    
)

(DEFUN add(A B)
    (+ (sum A) (sum B))
)

(write(add '(1 2 3 4) '(1 1 1 1 1)))
(terpri)

;b)
;get the list of all atoms

;(((A B) C) (D E)) ==> (A B C D E)


(DEFUN fct(L)

    (COND

        ((NULL L) NIL)

        ((ATOM (CAR L)) (CONS (CAR L) (fct (CDR L))))

        ((LISTP (CAR L)) (APPEND (fct (CAR L)) (fct (CDR L))))

    )

)


(write(fct '(((A B) C) (D E) F) ))
(terpri)

;c)
(DEFUN inv(L C)

    (COND

        ((NULL L) C)

        ((ATOM (CAR L)) (SETQ C (CONS (CAR L) C)) (inv (CDR L) C))

        ((LISTP (CAR L)) (APPEND C (CONS (inv (CAR L) ()) (inv (CDR L) ()))))

    )

)



(WRITE(inv '(A B C (D (E F)) G H I) '()))
(terpri)

;d)
;max at superficial level
(DEFUN maxi(A B)

    (COND

        ((< A B) B)

        (T A)

    )

)



(DEFUN supmax(L)

    (COND

        ((NULL L) (SETQ M -1000))

        ((NUMBERP (CAR L)) (SETQ M (maxi (CAR L) (supmax (CDR L)))))

        (T (supmax (CDR L)))

    )

)

(write(supmax '(A 2 (6 B) 1 (5))))



















Execute LISP Online

(print (merge 'string (reverse " olleH") (string-trim "other" "theotherWorld!") (lambda (a b) NIL)))

Execute LISP Online

( DEFUN eLiniara(Lista)
        ( COND
         ( (NULL Lista) T)
         ( (ATOM (CAR Lista) ) (eLiniara(CDR Lista) ))
         ( (NUMBERP (CAR Lista) ) (eLiniara(CDR Lista)))
        )
)
         

( write ( eLiniara '( 1 3 5 7 9 ) ) )

( write ( eLiniara '( 1 (3 5) 7 9 ) ) )

Textbook1

(print (cons 'a '(b c d)))

(cond ((> 1 6) (print 5))
        (t  (print 6))
)

(let* ((x 2) 
    (y (+ 2 x)))
    (print (+ x y))
)

(let ((x 1))
    (let ((y (+ x 1)))
    (print (+ y x))
    )
)

(defun absdiff(x y)
    (if (> x y)
        (- x y)
        (- y x)
    )
)

(print "Absolute value:") 
(print (absdiff 5 8))

(print (third '(a b c d)))
(print (sort (list 5 0 7 3 9 1 4 13 23) #'<))

(print (mapcar #'- '(8 12) '(4 5)))

(print (funcall #'+ 1 5 6))
(print (apply #'+ '(5 5 6)))

(defun make-quote (thing &optional arg)
    (list thing arg)
)

(print (make-quote 'all))
(defun fn (x)
    (cond   
        ((numberp x) #'+)
        ((listp x) #'append)
    )
)

(defun combine(&rest args)
    (apply (fn (car args)) args)
)
(print (combine '(a b)))

(defun consr (lst elt)
    (if (null lst)
        (list elt) 
        (cons (car lst) (consr (cdr lst) elt))
    )
)

(print (consr '(a b c e) 'd))

(print (mapcar #'* '(2 3) '(2 5 6)))
(defparameter *pi* 3.14)
(print *pi*)
(print (boundp '*pi*))

(defconstant limit 100)
(print limit)


mikes

(write-line "Hello World")
(write-line "My name is Mike")
(write-line "I am a good person")

dynamic scoping madness

(defun fun ()
    (write x)
)

(defun fun1 ()
    (defvar x 20)
    (fun)
)


(defun fun2 ()
    (defvar x 10)
    (fun)
)

; try reversing the order of the function calls below
(fun2)
(fun1)

Execute LISP Online

; Assignment 5
; Sophia Reed
; Working in Lisp 

; #2 
; The program subtracts the values passed to varibales x and y and prints the result. Output: 1 10 3
;-----------C++ equivilent-------------------
;#include <iostream>
; using namespace std;
;int foo(int x, int y)
;{ 
;   return (x - y);
;}
; //main method
;int main(){
;   cout<<foo(4,3)<< endl;
;   cout<<foo(20,10)<< endl;
;   cout<<foo(8,5)<< endl;
;}

; #3
;  The program checks string and the prints values using recurrsive function
;   output: a b c d e 1 2 3 4 5 x y z 
;-----------C++ equivilent-------------------
;#include <iostream>
;using namespace std;
;#include <string>
;void myPrint(string l)
;{
;    if (!l.empty())
;    {
;       cout<<l[0]<<endl;
;       myPrint(l.erase (0,1));
;    }
; }
;//main method
;int main(){
;   myPrint(" 1 2 3 4 5");
;   myPrint("a b c d e");
;   myPrint("x""y""z");
;}
;-------#4------------  
(defun factorial1 (n)
    (let ((sum 1))
        (dotimes (i n)
            (setf sum (* sum (1+ i)))
     )
        sum
   )
)
;--------#5----------------
(defun factorial2 (n)
 (if(= n 1)
    1
    (* n (factorial2(- n 1)))))
;------------#6--------------
;
;----------#7------------------
(defun fib (n)
  (if (< n 2) n
     (+ (fib (1- n)) (fib (- n 2)))
    )
)
;------------#8---------------
(defun small(x y)
    (if (< x y )
        x
     y))
;------------#9---------------
(defun sum(n)
    (if(= n 0)
    0
 (+ n (sum (- n 1)))))
;------------#10---------------
;1. setq sets the value of the variable x to the list (a b)
;2. setq sets the value of the variable y to the list (a b c)
;3. prints the first element in list x = A
;4. prints the first element in list y = A
;5. prints the remainding elements in list x with parenthesis. Results in list = (B) 
;6. prints the remainding elements in list y with parenthesis. Results in list = (B C) 
;7. prints the first element from the rest of the list x without parenthesis. Results in a symbol = B
;8. prints the first element from the rest of the list y without parenthesis. Results in a symbol = B
;9. prints the first element from the rest of the list x without parenthesis. Results in a symbol = B
;10.prints the first element from the rest of the list y without parenthesis. Results in a symbol = B
;11. prints both x and y lists together in one list 
;
    

(setq x '(a b ))
(setq y '(a b c))
(print (car x))
(print (car y))
(print (cdr x))
(print (cdr y))
(print (car(cdr x)))
(print (car (cdr y)))
(print (cadr x))
(print (cadr y))
(print (append x y))

Execute LISP Online

(write-line "Hello World")

Previous 1 ... 3 4 5 6 7 8 9 ... 35 Next
Advertisements
Loading...

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