Comments (3)
I've been chipping away at a change to resolve this issue. It is proving to be quite intrusive. Consider something like the implementation of the count
command:
func count(fm *Frame, args ...any) (int, error) {
var n int
switch nargs := len(args); nargs {
case 0:
// Count inputs.
fm.IterateInputs(func(any) {
n++
})
case 1:
// Get length of argument.
v := args[0]
if len := vals.Len(v); len >= 0 {
n = len
} else {
err := vals.Iterate(v, func(any) bool {
n++
return true
})
if err != nil {
return 0, fmt.Errorf("cannot get length of a %s", vals.Kind(v))
}
}
default:
// The error matches what would be returned if the `Inputs` API was
// used. See GoFn.Call().
return 0, errs.ArityMismatch{What: "arguments", ValidLow: 0, ValidHigh: 1, Actual: nargs}
}
return n, nil
}
All functions of this sort need to be changed to use an explicit int64
type for the return value.
Note that unit tests which do something like That("num 1").Puts(1)
are easy enough to handle by having the unit test framework handle the conversion so that the .Puts(1)
doesn't have to be written as .Puts(int64(1))
since num 1
now produces a int64
rather than a int
type. But that enhancement to the unit test framework only handles some of the int/int64 type differences as exhibited by the count
implementation above.
from elvish.
My main concern is not whether this change should be done. The external behavior of Elvish on 32 and 64 bit platforms should be identical. The question is how to minimize the size of the necessary changes, possibly by breaking them up over several commits.
from elvish.
The user @0323pin
on the DM channels asked:
Even though ... I don't know for how long 32bit systems will remain relevant but, that's for another discussion.
To which I replied:
They're likely to be relevant for a long time. For the same reasons even older 8/16 bit word length systems are still somewhat relevant. Obviously that diminished relevance doesn't require Elvish to support those systems, but Elvish should support 32 bit systems for the foreseeable future. In particular I think Elvish should exhibit the same behavior on 32 and 64 bits systems to the extent possible. This isn't entirely possible given the Go language specification. Consider that the maximum length of a slice/array is constrained by the range of the native int type. So Elvish is going to have a lower limit on the length of a list on 32 bit platforms. Which affects the behavior of the Elvish count command. Nonetheless, it should be possible for Elvish to otherwise treat numbers in the range of 64 bit ints the same on platforms with a 32 bit word length. Which affects commands like randint and %.
Note that this works on 64 bit platforms but not 32 bit platforms:
elvish> % (math:pow 2 31) 3
▶ (num 2)
But not 32 bit platforms:
elvish> % (math:pow 2 31) 3
Exception: wrong type for arg #0: must be integer
[tty 14]:1:1: % (math:pow 2 31) 3
I can't see a good reason why the modulo command should behave differently based on whether the platform uses 32 or 64 bit integers.
from elvish.
Related Issues (20)
- Support request: Where to install elvish completions in distro packages? HOT 2
- Pasting into Elvish is slow HOT 13
- `math:trunc` should output an exact num, not an inexact num HOT 2
- Failed to execute `bin/format.bat` on windows HOT 3
- Documentation for math:ceil shows examples for math:floor
- master branch os:chmod tests fail on FreeBSD HOT 2
- The `website/tools/check-rellinks.py` program has a surprising quirk regarding links that end in a slash HOT 2
- Delete from command history by Key command HOT 1
- flag::call does not recognize options with default $nil HOT 2
- Bracketed paste doesn't work with ConEmu HOT 1
- The os:mkdir transcript test fails if umask isn't zero HOT 1
- Transcript based unix:rlimits test failing on FreeBSD 13.0 amd64 HOT 2
- Completion takes 10-15 seconds to show on on wsl archlinux HOT 10
- Convert `for` loops to `range $int` when Go 1.22 becomes the minimum acceptable version HOT 1
- Change != !=s not-eq to only accept two arguments
- `kill-left-alnum-word` and `kill-alnum-word-left` HOT 1
- `store:next-cmd` and `store:prev-cmd` are not documented HOT 2
- Elvish binding for filtered directory history HOT 2
- Pipe in elvish alias? HOT 5
- Add atan2 to the math module
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elvish.