at and of, nth and ??? #1742

bjourne opened this Issue Nov 7, 2016 · 3 comments


None yet

4 participants

bjourne commented Nov 7, 2016

Something I've felt missing for a while is something like of but for sequences. Often in your code, you have the element index last and the sequence itself second-to-last. For example, if you do something with an array and then want to pick the fifth element:

100 sample ... [ sq ] map ... 5 swap nth

So if you had something like ath (bad name!) you could write 5 ath and avoid the swap. Grepping through the code git grep -e "\bswap nth\b" shows that the swap nth idiom is very common.

mrjbq7 commented Nov 8, 2016

It does look like (in a cursory inspection) that something like 25% of nth uses are swap nth. It would be good to provide such a word, but also maybe we could imagine some other ways to fix the general problem of mis-ordered stack arguments.


I use swap member? all the time.

catb0t commented Nov 8, 2016

Just looking for uses of swap in my own code, it seems that all, with a few exceptions, are related to swap nth, swap member? and swap at, which is not surprising to me -- usually I take pleasure in reFactoring to not use dup, swap, etc and so I'm left with the unfortunate and forgettable argument ordering to nth and friends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment