isaacg1 / pyth

Pyth, an extremely concise language. Try it here:
https://pyth.herokuapp.com/
MIT License
263 stars 57 forks source link

Implicitly round/floor float when multiplying with an array/string/etc. #247

Open xPMo opened 6 years ago

xPMo commented 6 years ago

An answer to a recent challenge had to floor a float in order to multiply by a string. If a floor is not explicitly provided, Pyth simply errors out.

There are two directions that this can go:

  1. round/floor before multiplying: *c5 2"ab" -> abab

  2. append that fraction (rounded/floored) of the string/list: *c5 2"ab" -> ababa

I don't know which way would be better, but either way shouldn't cause any regressions.

Steven-Hewitt commented 6 years ago

I wouldn't quite call my answer recent, but this could be a nice change.

However, I'd recommend keeping the old behavior on one of the two permutations (preferably * <num> <seq>, so that we can hack a check for floats with .x*TG (where we're checking T for floatiness, and G is the current global value of "abc...yz".)

ConorOBrien-Foxx commented 6 years ago

I'm not a Pyth expert, but wouldn't is just be better to have a float check builtin? IIRC there are some open commands.

Mr-Xcoder commented 6 years ago

I think we shouldn't go with rounding, because it can be rather confusing. Honestly, I think it should floor the argument. Regarding float check, it's not too hard to do it without a dedicated command (!sI). I think this functionality can be extended to:

And perhaps even more. Another version for @ would be to return the elements at indices floor(argument) and ceil(argument), similar to how Jelly does it. What do you think?