Logic and Conditionals (논리와 조건문)
원본: Computation Layer 문서(Logic and Conditionals)
CL은 불리언과 논리 연산자(and, or, not)를 써서 구성요소를 보이거나 숨기고("hidden" sink 사용) 그 밖에도 학생의 상호작용에 반응한다.
원문(영어) 보기
CL uses booleans and logical operators (and, or, and not) to show and hide components (using the "hidden" sink) and to otherwise respond to student interactions.
논리 연산자(Logical Operators)
복잡한 조건을 표현해야 할 때는 몇 개의 더 단순한 조건을 합치는 것이 도움이 된다.
원문(영어) 보기
If you need to express a complicated condition, it can be helpful to combine several simpler conditionals.
정의된 값과 정의되지 않은 값(Defined and Undefined Values)
CL에서 어떤 질문에 답할 방법이 없으면 그 값은 "정의되지 않음(undefined)"으로 취급된다. 예를 들어 어떤 직선도 나타내지 않는 방정식이 어떤 직선인지 묻는 경우이다. 이런 상황에서는 보통 다른 처리를 하고 싶을 것이다(예를 들어 학생이 직선을 지정해야 한다는 안내를 덧붙일 수 있다).
원문(영어) 보기
When there's no way to answer a question in CL, the value is treated as "undefined". An example of this is asking what line an equation represents when the equation does not represent any line. In these situations, you will usually want to do something different (for example, you might add special instructions to clarify that the student needs to specify a line).
값 비교하기(Comparing values)
Computation Layer는 숫자 사이의 비교를 지원한다. 숫자배열(numberList)의 최댓값이나 최솟값도 가져올 수 있다.
원문(영어) 보기
Computation Layer supports comparisons between numbers. You can also grab the max or min of a numberList.
not
불리언(참/거짓) 값을 받아 그 반대를 돌려준다. "when not(___)"처럼 쓴다.
원문(영어) 보기
Takes a boolean and returns its opposite. Use like "when not(___)"
# Store a Boolean value that tells us if the input has been submitted. ▷ 입력이 제출되었는지를 알려 주는 참/거짓 값을 저장한다. submitted = numberTyper.submitted ▶ 변수 submitted는numberTyper.submitted로 한다.numberTyper.submitted는 numberTyper 입력이 제출되었는지를 참 또는 거짓으로 알려 준다. # Store the numericValue of the math input as a variable called n. ▷ 수식 답변의 numericValue를 n이라는 변수로 저장한다. n = numberTyper.numericValue ▶ 변수 n은 numberTyper 입력을 계산한 값(numberTyper.numericValue)으로 한다.numericValue는 입력한 식을 계산한 값을 가져온다. 예를 들어 "2+2"는 숫자 4를 돌려준다. # Check to see if the number matches different constraints and assign # a feedback variable accordingly. ▷ 숫자가 여러 조건에 맞는지 확인하고, 그에 따라 피드백 변수를 정한다. feedback = when submitted and n > 2 and n < 4 and not(n = 3) "\n\nNice!" when submitted "\n\nNope!" otherwise "" ▶ 변수 feedback은 submitted가 참이고 n이 2보다 크고 4보다 작고not(n = 3)이면 "\n\nNice!"(멋지다!), 그렇지 않고 submitted가 참이면 "\n\nNope!"(아니다!), 그 밖에는 빈 글자로 한다.
글자 안의\n\n은 줄바꿈 두 번(빈 줄)이다.not(…)은 참/거짓을 뒤집는 함수이고,and는 둘 다 참이어야 참이며,when은 조건을 차례로 확인해 처음 맞는 값을 쓴다. content: "Type a number that is greater than 2 and less than 4 and ISN'T 3.${feedback}" ▶ 메모의 내용(content)은 "Type a number that is greater than 2 and less than 4 and ISN'T 3.${feedback}"(2보다 크고 4보다 작으며 3은 아닌 숫자를 입력하시오.) 뒤에 feedback의 값을 이어 붙인 글로 한다.${ }는 글자 안에 변수의 값을 끼워 넣는 표기이다.content는 메모에 직접 적은 글을 덮어쓴다.
isDefined
어떤 타입이든 받아 그 값이 정의되어 있는지를 참/거짓으로 돌려준다. 예를 들어 수식 답변의 numericValue에 쓴다.
원문(영어) 보기
Takes any type and returns a boolean for if it's defined. For example, use with the numericValue of an expression input.
# Tries to assign the value in the "numberDefiner" math input to "a" # first and then plots 4 as a backup if that value is undefined. ▷ 먼저 "numberDefiner" 수식 답변의 값을 "a"에 정해 보고, 그 값이 정의되지 않았으면 대신 4를 그린다. number("a"): when isDefined(numberDefiner.numericValue) numberDefiner.numericValue otherwise 4 ▶ 그래프의 변수 a(number("a"))는isDefined(numberDefiner.numericValue)가 참이면 numberDefiner 입력을 계산한 값(numberDefiner.numericValue), 아니면 4로 한다.number("이름")은 그래핑 계산기 안의 변수 값을 정하고,isDefined(…)는 어떤 타입이든 받아 정의되어 있는지를 참/거짓으로 돌려준다.numericValue는 입력한 식을 계산한 값을 가져오며, 예를 들어 "2+2"는 숫자 4를 돌려준다.when은 조건을 차례로 확인해 처음 맞는 값을 쓴다.
isUndefined
어떤 타입이든 받아 그 값이 정의되지 않았는지를 참/거짓으로 돌려준다. 예를 들어 수식 답변의 numericValue에 쓴다.
원문(영어) 보기
Takes any type and returns a boolean for if it's undefined. For example, use with the numericValue of an expression input.
# Checks to see if the math input has been submitted and is undefined. # If that's true it displays an irritated warning. If that's false # it displays the welcome text. ▷ 수식 답변이 제출되었고 정의되지 않은 값인지 확인한다. 그렇다면 짜증 난 경고를 보여 주고, 그렇지 않다면 환영 글을 보여 준다. content: when undefinerInput.submitted and isUndefined(undefinerInput.numericValue) "WHAT DID WE SAY?!" when undefinerInput.submitted "Thank you. `${undefinerInput.numericValue}` is defined." otherwise "Type a defined number in the blank.\n\nWe mean it.\n\nDon't try to type anything undefined." ▶ 메모의 내용(content)은undefinerInput.submitted가 참이고isUndefined(undefinerInput.numericValue)가 참이면 "WHAT DID WE SAY?!"(내가 뭐라고 했는가?!), 그렇지 않고undefinerInput.submitted가 참이면 "Thank you. `${undefinerInput.numericValue}` is defined."(고맙다. …은 정의된 값이다.), 그 밖에는 "Type a defined number in the blank.\n\nWe mean it.\n\nDon't try to type anything undefined."(칸에 정의된 숫자를 입력하시오. 진심이다. 정의되지 않은 것을 입력하려 하지 마시오.)로 한다.isUndefined(…)는 어떤 타입이든 받아 정의되지 않았는지를 참/거짓으로 돌려주고,submitted는 입력(또는 구성요소)이 제출되었는지를 참 또는 거짓으로 알려 준다.and는 둘 다 참이어야 참이고,when은 조건을 차례로 확인해 처음 맞는 값을 쓴다. 글자 안의\n\n은 줄바꿈 두 번(빈 줄)이고,${ }는 글자 안에 변수의 값을 끼워 넣는 표기이다.content는 메모에 직접 적은 글을 덮어쓴다.
firstDefinedValue
같은 타입의 인자를 여러 개 받아 그중 처음으로 유효한 값을 돌려준다. 예를 들어 "a = firstDefinedValue(exp1.numericValue, 2)"처럼 쓰면 exp1.numericValue가 유효해지기 전까지는 2를 돌려준다.
원문(영어) 보기
Takes multiple arguments, all of the same type, and returns the first that's valid. Use, for example as "a = firstDefinedValue(exp1.numericValue, 2)". That will return 2 until exp.numericValue is valid.
# Tries to assign the value in the "numberDefiner" math input to "a" # first and then plots 4 as a backup if that value is undefined. ▷ 먼저 "numberDefiner" 수식 답변의 값을 "a"에 정해 보고, 그 값이 정의되지 않았으면 대신 4를 그린다. number("a"): firstDefinedValue(numberDefiner.numericValue,4) ▶ 그래프의 변수 a(number("a"))는firstDefinedValue(numberDefiner.numericValue,4), 즉 numberDefiner 입력의 계산한 값이 정의되어 있으면 그 값, 아니면 4로 한다.number("이름")은 그래핑 계산기 안의 변수 값을 정하고,firstDefinedValue(…)는 같은 종류의 인자를 여러 개 받아 처음으로 정의된(유효한) 값을 돌려준다.numericValue는 입력한 식을 계산한 값을 가져오며, 예를 들어 "2+2"는 숫자 4를 돌려준다.
isBlank
글자(string)를 받아 빈 글자인지를 참/거짓으로 돌려준다.
원문(영어) 보기
Takes a string and returns a boolean of whether it's the empty string.
# Check to see if the student has entered text into "friendInput" # and change the feedback display accordingly. ▷ 학생이 "friendInput"에 글을 입력했는지 확인하고, 그에 따라 피드백 표시를 바꾼다. feedback = when isBlank(friendInput.content) "" otherwise "\n\nHello, ${friendInput.content}." ▶ 변수 feedback은isBlank(friendInput.content)가 참이면, 즉 입력이 빈 글자이면 빈 글자, 그렇지 않으면 "\n\nHello, ${friendInput.content}."(안녕, 이름.)로 한다.isBlank(…)는 글자를 받아 빈 글자인지를 참/거짓으로 돌려주고,content는 학생이 입력한 값을 글자(string)로 가져온다. 글자 안의\n\n은 줄바꿈 두 번(빈 줄)이고,${ }는 글자 안에 변수의 값을 끼워 넣는 표기이다.when은 조건을 차례로 확인해 처음 맞는 값을 쓴다. content: "What's your name, friend?${feedback}" ▶ 메모의 내용(content)은 "What's your name, friend?${feedback}"(이름이 무엇인가, 친구?) 뒤에 feedback의 값을 이어 붙인 글로 한다.${ }는 글자 안에 변수의 값을 끼워 넣는 표기이다.content는 메모에 직접 적은 글을 덮어쓴다.
max
숫자배열을 받아 가장 큰 값을 숫자로 돌려준다.
원문(영어) 보기
Takes a numberList and returns its largest value as a number.
# Create a list using the values in column 1 of the table # and inject that ist into the graph. ▷ 표의 1열 값으로 배열(List)을 만들어 그래프에 끼워 넣는다. X = table.columnNumericValues(1) ▶ 변수 X는table.columnNumericValues(1), 즉 표의 1열 전체의 숫자배열로 한다.columnNumericValues(열)은 그 열의 각 셀을 계산한 값을 숫자배열로 돌려준다. numberList("X"): X ▶ 그래프의 숫자배열 X(numberList("X"))는 변수 X로 한다.numberList("이름")은 그래핑 계산기의 변수를 주어진 숫자배열의 내용으로 정한다. # Find the maximum and minimum values from the list, then # multiply by a scale factor to add some padding: ▷ 배열에서 가장 큰 값과 가장 작은 값을 찾은 뒤, 여유 공간을 주려고 척도 값을 곱한다: left = numericValue("${min(X)}-5") ▶ 변수 left는 "${min(X)}-5"를numericValue로 계산한 값, 즉 X의 최솟값에서 5를 뺀 값으로 한다.min(…)은 숫자배열의 가장 작은 값을 돌려주고,numericValue(…)는 latex 글자를 숫자로 계산한다.${ }는 글자 안에 변수의 값을 끼워 넣는 표기이다. right = numericValue("${max(X)}+5") ▶ 변수 right는 "${max(X)}+5"를 계산한 값, 즉 X의 최댓값에 5를 더한 값으로 한다.max(…)는 숫자배열의 가장 큰 값을 돌려준다. # Set the window bounds using the left and right # values calculated in the previous row. ▷ 앞의 줄에서 계산한 left와 right 값으로 창 경계를 정한다. bounds: makeBounds(left,right,-10,10) ▶ 그래프의 경계(bounds)는makeBounds(left,right,-10,10), 즉 왼쪽 left, 오른쪽 right, 아래 -10, 위 10으로 한다.makeBounds(left, right, bottom, top)은 왼쪽, 오른쪽, 아래, 위 값으로 경계 객체를 만든다.bounds는 그래프(또는 그림판)의 경계를 정한다.
min
숫자배열을 받아 가장 작은 값을 숫자로 돌려준다.
원문(영어) 보기
Takes a numberList and returns its smallest value as a number.
# Create a list using the values in column 1 of the table # and inject that ist into the graph. ▷ 표의 1열 값으로 배열을 만들어 그래프에 끼워 넣는다. X = table.columnNumericValues(1) ▶ 변수 X는table.columnNumericValues(1), 즉 표의 1열 전체의 숫자배열로 한다.columnNumericValues(열)은 그 열의 각 셀을 계산한 값을 숫자배열로 돌려준다. numberList("X"): X ▶ 그래프의 숫자배열 X(numberList("X"))는 변수 X로 한다.numberList("이름")은 그래핑 계산기의 변수를 주어진 숫자배열의 내용으로 정한다. # Find the maximum and minimum values from the list, then # multiply by a scale factor to add some padding: ▷ 배열에서 가장 큰 값과 가장 작은 값을 찾은 뒤, 여유 공간을 주려고 척도 값을 곱한다: left = numericValue("${min(X)}-5") ▶ 변수 left는 "${min(X)}-5"를numericValue로 계산한 값, 즉 X의 최솟값에서 5를 뺀 값으로 한다.min(…)은 숫자배열의 가장 작은 값을 돌려주고,numericValue(…)는 latex 글자를 숫자로 계산한다.${ }는 글자 안에 변수의 값을 끼워 넣는 표기이다. right = numericValue("${max(X)}+5") ▶ 변수 right는 "${max(X)}+5"를 계산한 값, 즉 X의 최댓값에 5를 더한 값으로 한다.max(…)는 숫자배열의 가장 큰 값을 돌려준다. # Set the window bounds using the left and right # values calculated in the previous row. ▷ 앞의 줄에서 계산한 left와 right 값으로 창 경계를 정한다. bounds: makeBounds(left,right,-10,10) ▶ 그래프의 경계(bounds)는makeBounds(left,right,-10,10), 즉 왼쪽 left, 오른쪽 right, 아래 -10, 위 10으로 한다.makeBounds(left, right, bottom, top)은 왼쪽, 오른쪽, 아래, 위 값으로 경계 객체를 만든다.bounds는 그래프(또는 그림판)의 경계를 정한다.