PSPP

Funktional Praktikum 1

Funktional Teil 1 ;;load lisp files (load "more-functional.lisp") 1. Iteration (defun range (a &optional (b nil) (c 1)) (cond ((null b) (funcall 'range 0 a c)) (t (cond ((< (* a c) (* b c)) ;;mit c multiplizieren um Bedingung umzukehren wenn c negativ (cons a (funcall 'range (+ a c) b c))) (t nil))))) (defun repeat (times value) (mapcar (lambda (n) value) (range times))) * (repeat 5 'hello) (HELLO HELLO HELLO HELLO HELLO) (defun repeatedly (times fun) (mapcar fun (range times))) Lösung

Lisp Praktikum 2

Praktikum 2 Aufgabe 1 (defun reduce-list (f init seq) (cond ((null seq) init) (t(funcall f (car seq) (reduce-list f init (cdr seq)))))) (reduce-list #'+ 0 '(1 2 3 4)) 10 ;; Filter a sequence by the function f ;;if f(list-entry) == true then add to list (defun filter (f seq) (cond ((null seq) nil) ((funcall f (car seq)) (cons (car seq) (filter f (cdr seq)))) (t (filter f (cdr seq))))) Aufgabe 2 Erstelle eine Funktion “Range”:

Lisp Cheat Sheet

Lisp Cheat Sheet * (car '(A B (C))) A * (cdr '(A (C))) ((C)) #‘fun ist eine Abkürzung von (function fun) Reihenfolge: (- 5 2) -> 3 (>= 5 2) -> T (defmacro setfun (symb fun) `(prog1 ',symb (setf (symbol-function ',symb) ,fun))) ;; Makro um einen Lambda-Ausdruck als Funktion an ein Symbol zu binden. (apply #'+ 1 2 3 '(4 5 6)) ;; => 21 (let (a b (c 3) (d (+ 1 2))) (list a b c d)) ;; (NIL NIL 3 3) ;;LET is special form for variable binding.

Lisp Praktikum 1

Lisp Praktikum 1 1. First Steps a. ;; 10 * (4 + 3 + 3 + 1) - 20 = 90 * (- (* 10 (+ 4 3 3 1)) 20) 90 * 42 42 ;;evalueates to itself * pi 3.141592653589793d0 * (/4 3) 4/3 * (/ 12 3) 4 * (/ 4 3.0) 1.3333334 * (+ 0.5 1/2) 1.0 * (+ 0.5 1/4) 0.75 * (+ 1/2 1/4) 3/4 * (* 35 1.

PSPP Python

Python For Loops really comfortable with range function: for n in range(2,10): for x in range(2, n): if n% x == 0: print(n, 'equals', x, '*', n//x) break else: #Loop fell through without finding a factor print(n, 'is a prime number') Scope Rules different Scopes local inside function(method,…) global in the surrounding modul built-in pre defined names(open, len,…) function call creates a local scope search order when reading local > global > built-in

Lisp Part Two

History Lisp Machines with Emacs Clojure Is a dialect of Lisp lisp-journey.gitlab.io Hirachical Structures JavaScript vs. Lisp [ "copy", { "todir" : "../new/dir" "fileset" : [ { "dir" : "src_dir" } ] } ] (copy (todir "../new/dir") (fileset (dir "src_dir")))i Functions cadr car cdr ’ everything after not evaluated specialities of Common Lisp Symbols can have multiple bindings (set '= 42) (symbol-function '=) (symbol-value '=) (symbol-plist '=) (= = =) Macros evaluation of arguments is not always desired

Lisp Part One

Lisp Part One Using SBCL (Steel Bank common Lisp) on Debian simple stuff * (quote (was ist den hier los)) (WAS IST DEN HIER LOS) ;;Das ist einen Liste * '(was ist den hier los) (WAS IST DEN HIER LOS) ;;Auch eine Liste * '(was ist (denn hier) los) ;;Verschachtelte Liste (WAS IST (DENN HIER) LOS) * '(die "Antwort" ist 42) (DIE "Antwort" IST 42) * '(+ 1 2 3 4 5) (+ 1 2 3 4 5) ;;Liste * (+ 1 2 3 4 5) ;;Addition 15 * (defun dbl (n) (* 2 n) DBL Usefull Stuff * (mapcar 'dbl '(1 2 3 4)) ;;applies our function to a list (2 4 6 8) (set 'ding '(auto (marke "VW") (baujahr 1981) (gewicht (894 kg)))) (AUTO (MARKE "VW") (BAUJAHR 1981) (GEWICHT (894 KG))) (mapcar 'second (rest ding)) ;;AUTO is not of type list, that's why we remove it with rest ("VW" 1981 (894 KG)) ;;gives the 2nd element of each list entry