; Author: Eric Aaron ; Purpose: A little bit of Scheme programming for Colby College CS375 ; Fall 2022 semester ; this code runs on https://inst.eecs.berkeley.edu/~cs61a/fa14/assets/interpreter/scheme.html ; These Scheme definitions are for our LList datatype only ; This file contains some defintions, some small examples, ; and a few starter tips about general Scheme syntax, ; in case you want to try more Scheme programming. ; Author's note / Disclaimer: I am not a Scheme expert, so although I will ; try to help all CS375 students with Scheme questions, ; I may not havethe answers! Please be forewarned! ; Some Scheme definitions for LLists--using our LList datatype. ; cons is just cons--no change needed! (define first car) (define rest cdr) ; just because I like the syntax "empty?" more than "null?" (define empty? null?) ; here's an auxiliary function, computing the max of two numbers ; Input: Two numbers v1, v2 ; Output: The larger of v1 and v2 (define (max v1 v2) (if (> v1 v2) v1 v2)) ; here's an example algo on LLists ; Input: LList L containing only positive integers ; Output: Largest value occurring in L, or 0 if L is empty (define (LLMax L) (if (empty? L) 0 (max (first L) (LLMax(rest L))))) ; here are some test cases--not exhaustive, just illustrative (LLMax (cons 3 (cons 7 (cons 5 ())))) (LLMax (cons 7 (cons 5 (cons 3 ())))) ; Some general Scheme syntax to use: ; in general, the syntax (f x0 x1 ... xn) evaluates to the application of ; function f on arguments x0, x1, ... xn ; use prefix notation for arithmetic operations, e.g., (+ 3 7) and (* 2 5) ; both evaluate to 10 ; use (null? ) to check if T is empty ; use (= v0 v1) to check if integers v0 and v1 are equal ; use (< v0 v1) and (> v0 v1) to check less than / greater than on integers ; use (list? ) to check if L is a list [for the LList remove exercises] ; use #t, #f for boolean values true, false--e.g., (< 3 5) evaluates to #t, ; because 3 is less than 5