Open glyh opened 6 months ago
Also it looks like there's no sane way to hack out a solution without using source
. This won't work.
func parseBase(num_string, base) {
shopt --unset ysh:all {
eval """
write -n \$(($base#$num_string))
"""
}
}
Related: https://github.com/oilshell/oil/issues/428#issuecomment-2041158822
OK, I guess we can put this in the same place that Python puts it? Not sure what JS does
ysh andy@andy-VirtualBox:~/git/oilshell/oil$ = int('15', 3)
= int('15', 3)
^
[ interactive ]:5: fatal: Expected 1 typed args, but got 2
open to API ideas
parseInt('ff', 16)
Integer.parse('ff', 16)
It depends on what kind of language ysh is, really. For an OOP language, the API could be something like a class instantiation. But for FPs, a function called parseInt
seems to be enough. (The elixir thing is a function under a module).
I think overall JS's approach is better if we have this in default namespace, o.w. arguably elixir's naming is better.
FWIW I added a little hack to do this in YSH, using OSH /bash features
https://github.com/oils-for-unix/oils/blob/master/demo/url-search-params.ysh#L53
func strFromTwoHex(two_hex) {
var result
printf -v result "\\x$two_hex"
return (result)
}
OK well I guess this turns 0x1f
into a string, not an integer
But printf
can probably also do the latter
Currently there's no way to do so.