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 Function Definitions and Sorting Algorithms, Exercises of Computer Programming

Lisp function definitions for cons, car, cdr, min, min-list, without-n, sort-list, and insert. The cons function is a pair constructor, while car and cdr are used to extract the first and rest of a pair, respectively. The min and min-list functions find the minimum element in a list, and without-n removes an element from a list. The sort-list function sorts a list in ascending order using insert-sort, which inserts an element into a sorted list. The document also includes nonsensical function definitions for demonstration purposes.

Typology: Exercises

2012/2013

Uploaded on 04/26/2013

sharad_984
sharad_984 🇮🇳

4.5

(13)

149 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download Lisp Function Definitions and Sorting Algorithms and more Exercises Computer Programming in PDF only on Docsity! Hypothetical “Implementation” of pairs (define cons (lambda (a b) (lambda (x) (if x a b)))) (define (car p) (p #t)) Do type analysis on the above. p is located inside a single open paren and is followed by a Boolean. It must therefore be a procedure which takes in a Boolean and returns something (we don’t know what). (define (cdr p) (p #f)) (car (cons 1 2)) => 1 (cdr (cons 1 2)) => 2 ((lambda (p) (p #t)) ((lambda (a b) (lambda (x) (if x a b)))) 1 (2)) ((lambda (p) (p #t)) (lambda (x) (if x 1 2))) ((lambda (x) (if x 1 2)) #t) (if #t 1 2) => 1 Three arguments of cons (define cons3 (lambda (a b c) (lambda (x) (if (= x 0) a (if (= x 4 2) b c))))) (define (car p) (p 0)) (define (cdr p) (p 42)) (define (cgr p) (p 7)) Docsity.com
Docsity logo



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