length's type.

Gary Chike chikega at gmail.com
Fri Feb 9 02:55:48 UTC 2024


On Friday, 9 February 2024 at 02:13:04 UTC, Gary Chike wrote:

Reviewing the default return type in a couple more newer 
languages for the length function or equivalent. (`len()`, 
`length()`, `size()`):

The Nim language appears to return an `int` type:
```python
let something = @['a', 'b', 'c']

echo("len: ", something.len) # 3
echo("type: ", typeof(something.len)) # int
for i in -1..something.len.int:
     echo("i: ", i)
```
The Crystal language appears to return an `Int32` type:
```ruby
something = ['a', 'b', 'c']

puts "len: #{something.size}" # .size returns length
puts typeof(something.size) # Int32
(-1..something.size).each do |i|
     puts "i: #{i}"
end
```
Interesting to see that the signed integer type has been adopted 
as the return type for the length function by these newer 
languages.


More information about the Digitalmars-d-learn mailing list