; trying out some more Scheme ; compound expressions: (and true false false true) (+ 4 5 45 (- 10 8) (* 3 3) 5 5 5) (exp 1) ; uncomment this to see that exp ; can ONLY accept 1 argument ; (exp 1 2) ; uncomment these to see that + ; can ONLY accept number ; arguments ; (+ true 7) ; (+ "37" 1) (+ 34 34.1 (string-length "moo")) ; 5 * 4 + 3 * 2 ; let's say that we MEAN multiply ; first, add second (+ (* 5 4) (* 3 2)) ; 5 * (4 + 3) * 2 (* 5 (+ 4 3) 2) ; Scheme supports a version of ; the DrRacket image library ; you can get an image value ; (yes, Scheme supports an ; image type, also!) ; for a circle? there's a circle ; function, that expects a ; circle's radius in pixels ; (a pixel is one dot on the ; screen), a string saying ; "outline" or "solid", ; and a color (one way to ; give a color is to give its ; name as a string), and it ; returns an image of such a ; circle (circle 30 "solid" "green") ; Scheme supports bitmap/url, ; which expects a complete ; web address of an image ; written as a string ; and it returns that image (bitmap/url "https://cdn2-www.dogtime.com/assets/uploads/gallery/dachshund-dog-breed-pictures/side-5_680-453.jpg") ; there are image operations too... ; overlay lets you stack images ; on top of each other (overlay (star 20 "outline" "yellow") (circle 40 "solid" "blue")) ; click the Documentation link above ; (at the top of the WeScheme window) ; to read more about these image ; operations AND other WeScheme ; goodies! ; how about something from propositional ; logic, like (p ^ q) v (p v ~q)? ; ; (or (and p q) ; (or p (not q))) ; quick aside: ; boolean? can accept an expression of ; any type and tell you IF it is ; of type boolean ; number? can accept an expression of ; any type and tell you IF it is ; of type number ; string? can accept an expression of ; any type and tell you IF it is ; of type string ; image? can accept an expression of ; any type and tell you IF it is ; of type image (image? (circle 30 "outline" "black")) (number? "30") (< 3 5) (boolean? (< 3 5)) ;====== ; let's write our own operations, ; our own functions! ; here's the basic WeScheme syntax ; for a function: ; (define (new-funct-name param-name ; param-name ...) ; body-expression ; ) ; here's what is BUILT for you by ; FILLING IN the form you get ; by clicking "Recipe" near the ; top of the WeScheme window! ; add5 ; add5: number -> number ; purpose: expects a number, and returns the sum of ; 5 and that number (EXAMPLE (add5 5) 10) (EXAMPLE (add5 10) 15) (define (add5 num) (+ num 5) ) ; I can now use add5 as one of my functions ; for the rest of THIS window/file! (add5 104) (circle (add5 50) "solid" "purple")