Skip to content

Conversation

@ikappaki
Copy link
Contributor

Hi,

Could you please consider a patch to add documentation for Python slicing? This has come up a few times in Discussions, and without guidance, it might take users a while to understand how slicing is achieved in Basilisp.

Thanks

Copy link
Member

@chrisrink10 chrisrink10 left a comment

Choose a reason for hiding this comment

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

Seems like a good addition.

I don't see any obviously good macro solution for generic slicing. The fact that all 3 attributes can be omitted makes figuring out a generic solution.

@chrisrink10 chrisrink10 merged commit 566d307 into basilisp-lang:main Apr 20, 2025
12 checks passed
@ikappaki
Copy link
Contributor Author

ikappaki commented Apr 21, 2025

Seems like a good addition.

I don't see any obviously good macro solution for generic slicing. The fact that all 3 attributes can be omitted makes figuring out a generic solution.

Thinking about it, it might be a good idea to add a simple aslice (array slice) macro that translates to (aget coll (pyton/slice args...)). This would eliminate the need to call aget directly. Would you be open to supporting this? If so, I can raise a ticket/PR.

e.g., (aslice coll 1 5 2)

thanks

@chrisrink10
Copy link
Member

chrisrink10 commented Apr 21, 2025

@ikappaki I would accept a ticket/patch adding this function to basilisp.core. I do think the interface of such a method is somewhat messier than the corresponding Python construct.

For example, if you want to take a slice of every 2 elements in a list, the leading nils would be required:

(aslice coll nil nil 2)

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