5주차 Discussion #8
Replies: 11 comments 13 replies
-
2.17 function last_pair(list) {
return is_null(list)
? null
: length(list) === 1
? head(list)
: last_pair(tail(list));
} |
Beta Was this translation helpful? Give feedback.
-
2.18 function reverse(items) {
return is_null(items)
? null
: is_null(tail(items))
? head(items)
: pair(
reverse(tail(items)),
pair(head(items), null),
);
} |
Beta Was this translation helpful? Give feedback.
-
2.20 (1) function brooks(curried, list) {
function iter(list) {
return brooks(curried(head(list)), tail(list))
}
return is_null(list) ? curried : iter(list);
} |
Beta Was this translation helpful? Give feedback.
-
2.20 (2) function brooks_curried(list) {
return is_null(list)
? null
: is_null(tail(list))
? head(list)
: brooks_curried(
pair(head(list)(head(tail(list)))),
tail(tail(list)),
);
} |
Beta Was this translation helpful? Give feedback.
-
2.21 function square_list(items) {
return is_null(items)
? null
: pair(head(items) ** 2, square_list(tail(items)));
}
function square_list(items) {
return map(x => x ** 2, items)
} |
Beta Was this translation helpful? Give feedback.
-
2.23 function for_each(fun, items) {
return is_null(items)
? null
: (fun(head(items)), for_each(fun, tail(items)));
} |
Beta Was this translation helpful? Give feedback.
-
2.24 [1, [ [2, [ [3, [ 4, null ] ] ] ] ] ] |
Beta Was this translation helpful? Give feedback.
-
2.25 // list(1, 3, list(5, 7), 9)
[
1,
[
3,
[
[5, [7, null]],
[9, null],
],
],
];
// list(list(7))
[[7, null], null];
// list(1, list(2, list(3, list(4, list(5, list(6, 7))))))
[
1,
[
[
2,
[
[
3,
[
[
4,
[
[
5,
[
[6, [7, null]],
null,
],
],
null,
],
],
null,
],
],
null,
],
],
null,
],
]; |
Beta Was this translation helpful? Give feedback.
-
2.26 // append(x, y)
[1, [2, [3, [4, [5, [6, null]]]]]];
list(1, 2, 3, 4, 5, 6);
// pair(x, y)
[
[1, [2, [3, null]]],
[4, [5, [6, null]]],
];
[list(1, 2, 3), list(4, 5, 6)];
// list(x, y)
[
[1, [2, [3, null]]],
[[4, [5, [6, null]]], null],
];
list(list(1, 2, 3), list(4, 5, 6)); |
Beta Was this translation helpful? Give feedback.
-
// 2.27 // deep_reverse(x)
function deep_reverse(items) {
return is_null(items)
? null
: !is_pair(items)
? items
: is_null(tail(items))
? deep_reverse(head(items))
: pair(
deep_reverse(tail(items)),
pair(
deep_reverse(head(items)),
null,
),
);
} |
Beta Was this translation helpful? Give feedback.
-
2.17function lastPair(list) {
return isNull(list) ? null : lastPair(tail(list) || head(list));
} |
Beta Was this translation helpful? Give feedback.
-
📢 책을 읽으면서 궁금한 점들을 자유롭게 적고 대답해주세요
5주차 진행 방식
복습
: 2.2 문제 풀어오기 - 17, 18, 20 - 27 (10문제)진도
: 2.3까지 읽어오고 정리 & 의견 나누기미래 정하기
: 2.3 에서 풀 문제 정하기Beta Was this translation helpful? Give feedback.
All reactions