From 029a831fe8d5142d5bcb60830242ab61334a7e5b Mon Sep 17 00:00:00 2001 From: Ziad Arafat Date: Tue, 21 Feb 2023 20:42:08 -0700 Subject: [PATCH] Created report markdown file. --- PA002/report.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 PA002/report.md diff --git a/PA002/report.md b/PA002/report.md new file mode 100644 index 0000000..aca174f --- /dev/null +++ b/PA002/report.md @@ -0,0 +1,14 @@ +# Report +In our code, we utilized a function call after an `AND` operator to determine whether or not short-circuit evaluation is used in a given programming language. If the language uses short-circuit evaluation, the `print_answer()` function will not be executed and the output will be "`If you only see this then we DO have short circuit evaluation`". However, if the language does not use short-circuit evaluation, the `print_answer()` function will be executed and the output will be "`We DO NOT have short-circuit evaluation!`" followed by "`If you only see this then we DO have short circuit evaluation`". By placing `print_answer()` as the second operand in the `AND` expression, we took advantage of the fact that the second operand will only be evaluated if the first operand is true. In this way, we were able to determine whether or not short-circuit evaluation is used in a given programming language. + + +| Language | Short-Circuit? | Output | +| -------- | -------------- | ------------------------------------- | +| Ada | No | We DO NOT have short-circuit evaluation! If you only see this then we DO have short circuit evaluation| | +| Bash | Yes | If you only see this then we DO have short circuit evaluation | +| Perl | Yes | If you only see this then we DO have short circuit evaluation | +| PHP | Yes | If you only see this then we DO have short circuit evaluation| + +In the Ada example, we're using the `AND` operator and `print_answer` function, but it does not demonstrate short-circuit evaluation since the second operand will always be evaluated in Ada. I think it's worth noting that Ada does have an additional operator called `AND then` which does have short circuit evaluation. + +In the Bash, Perl, and PHP examples, we are using the `&&` operator, which demonstrates short-circuit evaluation. The `print_answer` function is only called if the first operand is true, which allows the code to avoid unnecessary evaluations of the second operand if it is not needed to determine the result of the expression. \ No newline at end of file