7주차 Discussion #10
chloe-codes1
started this conversation in
General
Replies: 3 comments
-
2.80// 2.80
function install_javascript_number_package() {
function is_equal_to_zero(x) {
return x === 0;
}
// ...
put("is_equal_to_zero", list("javascript_number"), is_equal_to_zero);
// ...
}
function install_rational_package() {
function is_equal_to_zero(x) {
return numer(x) === 0;
}
// ...
put("is_equal_to_zero", list("rational"), is_equal_to_zero);
// ...
}
function install_complex_package() {
function is_equal_to_zero(z) {
return real_part(z) === 0 && imag_part(z) === 0;
}
// ...
put("is_equal_to_zero", list("complex"), is_equal_to_zero);
// ...
}
function is_equal_to_zero(z) {
return apply_generic("is_equal_to_zero", list(z));
} 의문점: |
Beta Was this translation helpful? Give feedback.
0 replies
-
2.87// 2.87
function install_polynomial_package() {
// ...
function is_equal_to_zero_poly(L) {
return is_empty_termlist(L)
? true
: is_equal_to_zero(coeff(first_term(L)))
? is_equal_to_zero_poly(rest_terms(L))
: false;
}
// ...
put("is_equal_to_zero", list("polynomial"), is_equal_to_zero_poly);
// ...
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
2.81a. 무한 반복 -> maximum call stack size exceeded 에러 발생 function apply_generic(op, args) {
const type_tags = map(type_tag, args);
const fun = get(op, type_tags);
if (!is_undefined(fun)) {
return apply(fun, map(contents, args));
} else {
if (length(args) === 2) {
const type1 = head(type_tags);
const type2 = head(tail(type_tags));
if (is_same_type(type1, type2)) {
return error(list(op, type_tags), "no method for these types");
}
const a1 = head(args);
const a2 = head(tail(args));
const t1_to_t2 = get_coercion(type1, type2);
const t2_to_t1 = get_coercion(type2, type1);
return !is_undefined(t1_to_t2)
? apply_generic(lop, list(t1_to_t2(a1)), a2)
: !is(undefined(t2_to_t1))
? apply_generic(lop, list(a1, t2_to_t1(a2)))
: error(list(op, type_tags), "no method for these types");
} else {
return error(list(op, type_tags), "no method for these types");
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
📢 책을 읽으면서 궁금한 점들을 자유롭게 적고 대답해 주세요
7주차 진행 방식
진도
: 2.5 까지 읽어오고 정리 & 의견 나누기문제 풀이
: 2.5 문제 풀고, Github 에 올리기 - 2.80, 2.81, 2.87 (총 3문제)Beta Was this translation helpful? Give feedback.
All reactions