← 수업 제작 도구
홈 › Index › Types

Types (타입)

원본: Computation Layer 문서(Types)

코드 안의 회색 줄은 원문 영어 주석이고, 파란 줄은 그 영어 주석의 번역이며, 연분홍 줄은 코드가 하는 일의 설명이다. 항목 설명은 번역이 아니라 해석이며 원문은 접어 둔 "원문(영어) 보기"에 있다.

Computation Layer의 모든 값에는 타입이 있다. 예를 들어 수식 답변(Math Input) 구성요소의 source와 sink 몇 가지를 보자. timeSinceSubmit source는 숫자를 만든다. latex source는 구성요소의 LaTeX 값을 만든다. submitLabel sink는 글자(string) 값을 기대한다. hidden sink는 참/거짓 값을 기대한다.

원문(영어) 보기

Every value in the Computation Layer has a type. For example, consider some of the sources and sinks for the Math Input component: The timeSinceSubmit source produces a number The latex source produces the LaTeX value of the component The submitLabel sink expects a string value The hidden sink expects a true/false value

이 예들은 기본 타입인 숫자, LaTeX, 글자, 불리언을 보여 준다. 그 밖에도 스케치, 숫자배열(numberList), 색 같은 타입이 있다. 추상적으로 타입은 값에 어떤 종류의 데이터가 들어 있고 그 값에 어떤 연산을 쓸 수 있는지를 설명한다. 예를 들어 숫자배열 타입은 숫자의 배열(List)을 담고, 배열의 길이를 구하거나 특정 번호의 원소를 가져오는 연산을 쓸 수 있다.

원문(영어) 보기

These examples demonstrate some basic types: numbers, LaTeX, strings, and booleans. However there are other types like sketches, numberLists, colors, etc. Abstractly, a type describes what kind of data is stored in a value, and what operations are available for that value. For example, the numberList type stores a list of numbers, and some of the available operations are to find the length of the list, or to get an element at a specific index.

Computation Layer는 "강타입(strongly typed)" 언어이다. 모든 식은 어떤 타입의 값을 만든다. 예를 들어 sketch1.sketch.pointCount는 숫자 타입의 값을 만들고, 부분식 sketch1.sketch는 스케치 타입의 값을 만든다. 값을 쓸 때마다(식, 함수 호출, sink 안에서) 올바른 타입인지 검사하고, 아니면 오류를 보여 준다(예: 글자를 기대하는 sink에 숫자를 쓰려 할 때).

원문(영어) 보기

Computation Layer is a "Strongly typed" language. Every expression produces a value of some type. For example,sketch1.sketch.pointCount produces a value of type number, while the subexpression sketch1.sketch produces a value of type sketch. Whenever you use a value(e.g., in an expression, function call, or sink), we check that is the correct type for that usage, and show an error if it is not (e.g., trying to use a number in a sink that expects a string).

기본 타입(Basic Types) (Basic Types)

Computation Layer에서 가장 흔한 타입은 숫자, 글자, LaTeX, 불리언이다. 숫자는 수치 값을, 글자(string)는 글 값을, 불리언은 참/거짓 값을, LaTeX는 수학 표기를 나타낸다. 글자는 따옴표("")로, LaTeX는 백틱(``)으로 감싼다. 둘의 차이는 메모에 끼워 넣었을 때 어떻게 보이는지로 알 수 있다. 예를 들면 다음과 같다:

원문(영어) 보기

The most common types in the Computation Layer are numbers, strings, LaTeX and booleans. Numbers represent numeric values String represent text values Booleans are true/false values LaTeX represent written mathematics Strings are wrapped in quotes (""), while LaTeX is wrapped in backticks (``). One way to see the difference is to observe how they look when inserted into a note. For example: #this is a regular string: str1 = "y=x^2" ​ #this is a LaTeX string str2 = `y=x^2` ​ #you can put LaTeX inside of a string, like so: str3 = "string outside `y=x^2` string outside"

1 CL 코드
#this is a regular string:
▷ 일반 글자(string)이다:
str1 = "y=x^2"
▶ 변수 str1은 "y=x^2"로 한다.
따옴표로 감싼 값은 글자(string) 타입이다.
#this is a LaTeX string ▷ LaTeX 글자이다. str2 = `y=x^2` ▶ 변수 str2는 latex 글자 `y=x^2`로 한다.
백틱으로 감싼 값은 LaTeX 타입이다. 같은 y=x^2라도 글자(str1)와 LaTeX(str2)는 메모에 끼워 넣으면 보이는 모양이 다르다.
#you can put LaTeX inside of a string, like so: ▷ 다음처럼 글자 안에 LaTeX를 넣을 수도 있다: str3 = "string outside `y=x^2` string outside" ▶ 변수 str3은 "string outside `y=x^2` string outside"로 한다.
글자 안에 백틱으로 감싼 LaTeX가 들어 있으며, 이렇게 글자 안에 LaTeX를 넣을 수 있다.

복잡한 타입(Complex Types) (Complex Types)

스케치, 색, 숫자배열 같은 복잡한 타입은 특정 종류의 데이터를 담고, 그 타입에서 데이터를 꺼내거나 변형하는 데 쓸 수 있는 속성(attribute) 또는 멤버 함수를 갖는다.

원문(영어) 보기

Complex types, such as sketches, colors, numberLists, etc, store a specific kind of data, and have a set of attributes, or member functions, which you can use to extract data from the type or transform it in some way.

이런 타입을 다룰 때는 보통 다음 질문에 답할 수 있어야 한다. 이 타입은 어떤 정보를 나타내는가? 이 타입의 값은 어떻게 얻는가? 이 타입을 다루는 데 어떤 속성이나 함수를 쓸 수 있는가? 이 타입은 어디에 쓸 수 있는가? 이런 타입은 보통 구성요소의 source나 함수에서 얻고, 추가 함수를 호출해 변형한 뒤, sink에 쓰거나 다른 함수의 인자로 쓴다.

원문(영어) 보기

When working with one of these types, you generally need to answer these questions: What kind of information does this type represent? How do I obtain values of this type? What attributes or functions can I use to manipulate this type? Where can I use this type? You'll generally get these types from either a component source or a function, transform them by calling additional functions on them, and then use them in a sink or as an argument to another function.

유틸리티 타입(Utility Types) (Utility Types)

유틸리티 타입인 sketchTools, buttonStyles, colorPalette는 유용한 객체에 접근하게 해 주려고 만들어졌다. 예를 들어 colorPalette 타입에는 Desmos의 표준 색들이 있어 그림판 구성요소의 initialColor sink에 쓸 수 있다. 이 타입들은 colorPalette 타입의 colors처럼 전역 상수를 가리켜서 얻는다.

원문(영어) 보기

The utility types, sketchTools, buttonStyles, and colorPalette, are designed to provide access to useful objects. For example, the colorPalette type contains standard Desmos colors that can then be used in the initialColor sink for the Sketch component. These types are obtained by referencing a global constant, e.g. colors for the colorPalette type.