# How can Pyth be improved? [closed]

Pyth is in ongoing development, meaning that new features are being added all the time.

I want to make Pyth a better langauge, so I'd like to know what features people are looking for.

This is the place the post ideas you have for making Pyth better.

• What you'd like to see changed/added.

• An example usage of the change.

I'll comment if I'm planning to implement the suggestion.

Please check if the idea you want to suggest has already been suggested. Upvote ideas you'd like implemented.

Implemented suggestions:

This was on topic as per this meta question when I posted the question, it is no longer clear.

• Why is this a community wiki? – Geobits Oct 7 '15 at 18:19
• It's more of a discussion and collection of suggestions. Nobody should gain or lose rep for suggesting a Pyth feature. Also, implemented suggestions should probably be deleted. This related question is also community wiki. – Dennis Oct 7 '15 at 18:25
• I'm not sure how I feel about questions like this. I can see that it sort of makes sense here, because PPCG probably covers most (if not all) of Pyth's user base, but I'm not sure we should use it as an issue tracker. I have added an answer to the meta post. – Martin Ender Oct 8 '15 at 7:12
• Shouldn't this been meta? Seriously guys – Alec Teal Oct 9 '15 at 7:02
• @AlecTeal "Meta Programming Puzzles & Code Golf Stack Exchange is the part of the site where users discuss the workings and policies of Code Golf Stack Exchange rather than discussing programming puzzles or code golf itself." Meta is specifically about this community. It really doesn't belong on meta. Whether it belongs here or not on PPCG at all is currently being discussed in the meta post I linked. – Martin Ender Oct 9 '15 at 8:29

## Nested loops

If you want to nest for loops, you currently have to waste a byte for using F<var><seq> inside a V<seq> or vice versa. I'd love to have the same thing as with lambdas, where the variable used for the loop would change when nesting loops.

• This might even be extensible to other things like L, which could redefine, say, C the second time it were called. – FryAmTheEggman Oct 7 '15 at 20:33

# Turt

Pyth equivalent of turtle graphics, as per import turtle.

## Easier Module Importing

So far, every time I have used $ it has been something like: $from <module> import <function> as <pyth-function-with-same-arity>$for example:$from unicodedata import name as neg$ There could be a new function that summarized this for example .$:

.$"unicodedata""name""neg" .$"unicodedata name neg"


Or using the newer syntax like _M which may not be easy/possible to do:

_$unicodedata name$


In addition, one function with each arity could be given a single letter macro name so that these calls could be shorter (except for the _$ option). # Sleeping This caused trouble here, and @mbomb007 suggested to put it as an improvement to Pyth. Basically, right now, in order to sleep for the given number of seconds, I need to do something like: Q$__import__('time').sleep(Q)\$


Which is annoying and long as heck.

• You can simulate the sleeping behaviour with the date-function. f>.d1Q0 for instance sleeps Q seconds. – Jakube Oct 9 '15 at 18:43
• @Jakube That doesn't always work. According to the docs, on Unix, it returns how long the program has been running for. Which is bad when the user is entering input. – kirbyfan64sos Oct 9 '15 at 18:45
• How about this one than: J.d0f>-.d0JQ0. It's quite long though... I agree, a sleep function would be nice. – Jakube Oct 9 '15 at 18:48

# More lambdas

This is really FryAmTheEggman's idea, but I'm posting it to get it out there.

Sometimes I find that using two different one-argument lambdas would shorten the code, while having to use a two-argument lambda for one wouldn't.

It would be nice to have L, M and friends redefine a different function every time used; for example, this code:

L*b2L*b3y5'5


could compile to:

@memoized
def subsets(b):
return times(b,2)
@memoized
return times(b,3)
imp_print(subsets(5))


The exact choice of functions could be changed, of course.

## Improved multi-dimensional arrays

Using multi-dimensional arrays is rather hard to do currently. For example, the C code A[B][C][D] would translate to @@@ABCD in Pyth. Something like @A[BCD) would be much nicer (albeit not any shorter here). The same also goes for X; A[B][C][D] = E is currently X@@ABCDE, when it could be XA[BCD)E.

## Some minor ideas

• Absolute difference, i.e. abs(val1 - val2). Currently it's .a-<val1><val2>.
• min/max for values. Currently it's hS,<val1><val2>/eS,<val1><val2> or the same thing with more values. (hS<seq>/eS<seq> for sequences is short enough.)

Not a Pyth feature, but nevertheless...

## Modularize the Pyth code

This only affects Pyth under the hood. Some parts of the Pyth implementation are quite messy. Lots of global variables and other hacky things.

I really got frustrated a few days ago, when I tried using a few functions of the Pyth implementation (like executing a string of Pyth commands) from another Python script.

Something like the following would be nice:

from pyth import execute_pyth
print(execute_pyth(code='sQ', input='[1, 2, 3]'))


Well, I guess this is just a help call for Pyth5.

• – kirbyfan64sos Oct 7 '15 at 22:07

# Unique elements

Pyth currently has no short way of getting unique elements of a sequence. You can test if it's unique, but you can't get the items that are actually unique. Currently, the shortest way is:

{.-Q{Q


6 bytes! Compare that to K, where getting the unique elements is a one-byte operation: =x.

Maybe .} would work here?

• What use cases (other than tat one challenge) are you thinking of? – isaacg Oct 15 '15 at 20:57
• @isaacg I can't quite recall, but I've had to try and get the unique elements of a list before and had to use something else (which was always longer). – kirbyfan64sos Oct 15 '15 at 20:58
• I'm not a Pyth programmer, but I run into this all the time in GolfScript/CJam: .& resp. _& appears in a lot of answers. It's very useful. – Lynn Oct 15 '15 at 21:06
• How is this different from {Q? – isaacg Oct 15 '15 at 21:43
• @isaacg It's sorted – Ypnypn Oct 15 '15 at 21:48