Open the Commutativity and Associativity Starter File, which you will use to investigate four functions:

; string-contains :: String, String -> Boolean ; min :: Number, Number -> Number

; max :: Number, Number -> Number ; blend-images :: Image, Image -> Image

For each function, draw a second Circle of Evaluation that changes the order of the arguments. Translate the Circles of Evaluation to code, then sketch the image that you think your Circle will return. Finally, test your code in Pyret.

Is string-contains Commutative?

Circle of Evaluation

(string-contains "rainbow" "bow")

Code

(string-contains "rainbow" "bow")

Result

true

1 Did both expressions produce the same result in WeScheme? Is string-contains commutative or not?

Is min Commutative?

Circle of Evaluation

(min 200 23)

Code

(min 200 23)

Result

23

23

2 Did both expressions produce the same result in WeScheme? Is the min function commutative or not?

3 Make a prediction. Do you think max is commutative? Test your prediction. Were you right?

Is blend-images Commutative?

Circle of Evaluation

(blend-images purple-square white-dot)

(blend-images white-dot purple-square)

Code

(blend-images purple-square white-dot)

Sketch

a solid white circle blended with a solid purple square, causing the solid white circle to become lavender

4 Did both expressions produce identical images in WeScheme? Is blend-images commutative or not?

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927). CCbadge Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.