How can Pyth be improved?

24

2

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.

In your answer, please state:

  • 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.

isaacg

Posted 2015-10-07T18:08:55.613

Reputation: 39 268

Question was closed 2015-10-18T09:03:19.427

1Why is this a community wiki? – Geobits – 2015-10-07T18:19:55.920

4

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 – 2015-10-07T18:25:53.490

9

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 – 2015-10-08T07:12:13.043

Shouldn't this been meta? Seriously guys – Alec Teal – 2015-10-09T07:02:45.470

2@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 – 2015-10-09T08:29:01.660

@MartinBüttner So, should I close the question? – isaacg – 2015-10-09T09:13:46.327

@isaacg I'd say give it some time to see if the new answer actually pulls ahead on meta. – Martin Ender – 2015-10-09T09:14:32.087

If it's relevant either way to people voting on meta, this type of question will almost invariably reach HNQ. (Being community wiki does not prevent it showing on HNQ.) – trichoplax – 2015-10-09T11:55:50.067

All of the good suggestions here will end up on the Github issue tracker, won't they? I'd say this isn't an appropriate use of SE. – curiousdannii – 2015-10-09T12:56:49.960

I think at 27 vs 17 (+/- the votes Alex and I couldn't cast on our own answers), the consensus is fairly clear now. Therefore, I'm closing this question now. – Martin Ender – 2015-10-18T09:02:43.387

Answers

7

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.

PurkkaKoodari

Posted 2015-10-07T18:08:55.613

Reputation: 16 699

This might even be extensible to other things like L, which could redefine, say, C the second time it were called. – FryAmTheEggman – 2015-10-07T20:33:37.687

5

Turt

Pyth equivalent of turtle graphics, as per import turtle.

Digital Trauma

Posted 2015-10-07T18:08:55.613

Reputation: 64 644

4

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

FryAmTheEggman

Posted 2015-10-07T18:08:55.613

Reputation: 16 206

4

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.

kirbyfan64sos

Posted 2015-10-07T18:08:55.613

Reputation: 8 730

You can simulate the sleeping behaviour with the date-function. f>.d1Q0 for instance sleeps Q seconds. – Jakube – 2015-10-09T18:43:20.430

@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 – 2015-10-09T18:45:35.990

How about this one than: J.d0f>-.d0JQ0. It's quite long though... I agree, a sleep function would be nice. – Jakube – 2015-10-09T18:48:13.773

4

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
def read_file(b):
 return times(b,3)
imp_print(subsets(5))
imp_print(read_file(5))

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

PurkkaKoodari

Posted 2015-10-07T18:08:55.613

Reputation: 16 699

3

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.

PurkkaKoodari

Posted 2015-10-07T18:08:55.613

Reputation: 16 699

3

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

PurkkaKoodari

Posted 2015-10-07T18:08:55.613

Reputation: 16 699

3

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.

Jakube

Posted 2015-10-07T18:08:55.613

Reputation: 21 462

https://github.com/isaacg1/pyth/issues/111? – kirbyfan64sos – 2015-10-07T22:07:43.783

1

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?

kirbyfan64sos

Posted 2015-10-07T18:08:55.613

Reputation: 8 730

What use cases (other than tat one challenge) are you thinking of? – isaacg – 2015-10-15T20:57:43.367

@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 – 2015-10-15T20:58:33.190

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 – 2015-10-15T21:06:50.480

1How is this different from {Q? – isaacg – 2015-10-15T21:43:13.493

1@isaacg It's sorted – Ypnypn – 2015-10-15T21:48:04.547

@kirbyfan64sos =x looks like a 2 byte operation to me! Maybe I'm missing something... – wizzwizz4 – 2015-12-15T20:36:29.290

@wizzwizz4 I was referring to the =; the x was just an example. – kirbyfan64sos – 2015-12-15T22:52:16.913