-
-
Notifications
You must be signed in to change notification settings - Fork 9
Add list-ops #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add list-ops #159
Conversation
96e89cc
to
25a4d15
Compare
generators/exercises/list_ops.py
Outdated
""" | ||
|
||
def array_literal(digits): | ||
return '{' + ', '.join(str(d) for d in digits) + '}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
generators/exercises/list_ops.py
Outdated
if prop == 'append': | ||
str_list.append('int64_t buffer[BUFFER_SIZE];\n') | ||
call = f'{prop}(buffer, {list1_with_count}, {list2_with_count})' | ||
|
||
if prop in ['filter', 'map']: | ||
str_list.append('int64_t buffer[BUFFER_SIZE];\n') | ||
call = f'{prop}(buffer, {list_with_count}, {function})' | ||
|
||
if prop in ['foldl', 'foldr']: | ||
call = f'{prop}({list_with_count}, {initial}, {function})' | ||
|
||
if prop == 'reverse': | ||
str_list.append('int64_t buffer[BUFFER_SIZE];\n') | ||
call = f'{prop}(buffer, {list_with_count})' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use elif
to avoid evaluations that for sure will be false. Or use pattern matching:
if prop == 'append': | |
str_list.append('int64_t buffer[BUFFER_SIZE];\n') | |
call = f'{prop}(buffer, {list1_with_count}, {list2_with_count})' | |
if prop in ['filter', 'map']: | |
str_list.append('int64_t buffer[BUFFER_SIZE];\n') | |
call = f'{prop}(buffer, {list_with_count}, {function})' | |
if prop in ['foldl', 'foldr']: | |
call = f'{prop}({list_with_count}, {initial}, {function})' | |
if prop == 'reverse': | |
str_list.append('int64_t buffer[BUFFER_SIZE];\n') | |
call = f'{prop}(buffer, {list_with_count})' | |
match prop: | |
case 'append': | |
str_list.append('int64_t buffer[BUFFER_SIZE];\n') | |
call = f'{prop}(buffer, {list1_with_count}, {list2_with_count})' | |
case 'filter' | 'map': | |
str_list.append('int64_t buffer[BUFFER_SIZE];\n') | |
call = f'{prop}(buffer, {list_with_count}, {function})' | |
case 'foldl' | 'foldr': | |
call = f'{prop}({list_with_count}, {initial}, {function})' | |
case 'reverse': | |
str_list.append('int64_t buffer[BUFFER_SIZE];\n') | |
call = f'{prop}(buffer, {list_with_count})' |
generators/exercises/list_ops.py
Outdated
} | ||
""" | ||
|
||
def array_literal(digits): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are not necessarily digits, right? Maybe call it values
or numbers
instead?
.globl reverse | ||
|
||
|
||
/* extern size_t append(int64_t* buffer, const int64_t* list1, size_t list1_count, const int64_t* list2, size_t list2_count); */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with list_ops_test.c
(but really nit picking here ...):
/* extern size_t append(int64_t* buffer, const int64_t* list1, size_t list1_count, const int64_t* list2, size_t list2_count); */ | |
/* extern size_t append(int64_t *buffer, const int64_t *list1, size_t list1_count, const int64_t *list2, size_t list2_count); */ |
Also applies to other C function signatures in this file.
mov x15, x2 | ||
lsl x9, x2, #3 | ||
add x9, x1, x9 /* end of list */ | ||
cbz x2, .reverse_return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to move this before line 170?
No description provided.