;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "reader.ss" "plai" "lang") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Some literals 1 "Hello" 'Williams true '(1 A B "Hello") '((a b) (c d)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Calling a function (list 1 2) (+ 1 2) (> 7 4) (eq? 'x 'y) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; The IF expression (if true 1 2) (if false 1 2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Factorial ;; defining a function: (define (factorial n) (if (<= n 1) 1 (* (factorial (- n 1))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Find the largest element of a list ;; Defining a variable (define minInt -10000) ; Takes a list and returns the largest value in the list ; or minInt if the list is empty (null) (define (largest L) (if (null? L) minInt (max (first L) (largest (rest L))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Compute the absolute value of the argument (define (absolute x) (if (< x 0) (- x) x))