Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

LISP Functions and Control Structures, Slides of Programming Languages

An introduction to lisp functions, predicates, set operations, and control structures. It covers topics such as defining functions, using conditional statements, and performing set operations on lists. The document also includes examples and explanations of various lisp functions and operators.

Typology: Slides

2011/2012

Uploaded on 11/10/2012

omni
omni 🇮🇳

4.6

(9)

47 documents

1 / 9

Toggle sidebar

Related documents


Partial preview of the text

Download LISP Functions and Control Structures and more Slides Programming Languages in PDF only on Docsity! Functions > (reverse L) ; reverses a list (C B A) > (length L) ; returns the length of list L 3 List has elements (A B C) Docsity.com Predicates • A special function which returns NIL if the predicate is false, T or anything other than NIL, otherwise • We can use the following operators to build the predicates – =, >, <, >=, <= for numeric values – eq or equal for others – atom: test if x is an atom – listp: test if x is a list – Also number, symbolp, null Docsity.com > (setf operation ‘area L 100 W 50) > 50 > (cond ((eq operation ‘perimeter) (* 2 (+ L W))) (eq operation ‘area) (* L W)) (t ‘i-do-not-understand-this) ) ) > 5000 Docsity.com • A list can be viewed as a set whose members are the top elements of the list > (member 'b L) (B C) > (member ‘b (cons 'b L)) (B A B C) > (member x L) NIL ; if no, returns NIL > (union L1 L2) ; returns the union of the two lists > (intersection L1 L2) ; returns the intersection of the two lists > (set-difference L1 L2) ; returns the difference of the two lists Set Operations Test if symbol b is a member (a top element) of L; if yes, returns the sublist of L starting at the first occurrence of symbol b List L has elements (A B C) Docsity.com Defining LISP functions (defun func-name (arg-1 ... Arg-n) func-body) Example: > (defun y-plus (x) (+ x y)) ;definition of y-plus > (setq y 2) > (y-plus 23) 25 • Local and global variables: local variables are defined in function body • Function returns the value of last expression in its body Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved