Skip to content

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

Merged
merged 2 commits into from
May 14, 2025
Merged

Add list-ops #159

merged 2 commits into from
May 14, 2025

Conversation

keiravillekode
Copy link
Contributor

No description provided.

@keiravillekode keiravillekode force-pushed the list-ops branch 2 times, most recently from 96e89cc to 25a4d15 Compare May 9, 2025 04:24
"""

def array_literal(digits):
return '{' + ', '.join(str(d) for d in digits) + '}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Comment on lines 98 to 111
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})'
Copy link
Contributor

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:

Suggested change
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})'

}
"""

def array_literal(digits):
Copy link
Contributor

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); */
Copy link
Contributor

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 ...):

Suggested change
/* 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
Copy link
Contributor

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?

@keiravillekode keiravillekode merged commit 8677ee1 into exercism:main May 14, 2025
4 checks passed
@keiravillekode keiravillekode deleted the list-ops branch May 14, 2025 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants