smartdispatch
smartdispatch copied to clipboard
Add more types of folded arguments.
It would be really nice to handle different type of folded arguments. Here a list of what I think could be useful. Feel free to comment or suggest other types.
Listing
- [x] List:
echo [1 3]
echo 1
echo 3
- [x] Range:
echo [1:4] |
echo [1:6:2] |
---|---|
echo 1 |
echo 1 |
echo 2 |
echo 3 |
echo 3 |
echo 5 |
- [ ] Linspace:
echo Lin[1:6:5]
echo 1
echo 2.25
echo 3.5
echo 4.75
echo 6
- [ ] Logspace:
echo Log[0:3:4]
echo 1
echo 10
echo 100
echo 1000
Random sampling
- [ ] Uniform:
echo U[0,1:3]
echo 0.999
echo 0.42
echo 0
- [ ] Normal:
echo N[0,1:4]
echo 1.5
echo -0.42
echo 0.0001
echo -0.9
The remaining ones have been requested over and over. It's pretty simple to implement we just need to think of a nice way to put that in the command line.
Maybe we could unify all those like so: [1 3] -> List(1,3) [1:6:2] -> Range(1,6,2) Lin[1:6:5] -> Lin(1,6,5) N[0,1:4] -> N(0,1,4)
Not sure though. What do you think @vdumoulin @rizar @caglar ?
Maybe function names should all be lowercase? Also should we still support [1 3] and [1:6:2] for backward compatibility?
My suggestion is to try to stick to the typical Python syntax as much as possible:
[1 3] -> [1, 3]
[1:6:2] -> ok
Lin[1:6:5] -> Lin(1,6,5)
Log[1:6:5] -> Log(1,6,5)
N[0,1:4] -> N(0,1,4)
I don't have a strong preference on lowercase vs uppercase, but since N has to be uppercase maybe it makes sense to keep Log and Lin uppercase too.
For me suggestions made by both @mgermain and @fvisin are good. But I think I would prefer having lower case for Lin, Log and N functions.
I vote for [] because bash cares about () sometimes.