Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: [Way OT] Python to D.

by AnomalousMonk (Archbishop)
on Jun 15, 2018 at 18:01 UTC ( [id://1216736]=note: print w/replies, xml ) Need Help??


in reply to Re^3: [OT] Python to Perl.
in thread [OT] Python to Perl.

... this makes sense at some wacky level.

For me, the semantic sense is that in a 0-based array, the length of the array can be used to represent its highest index. A D example:

import std.stdio; void main () { auto ra = [ 'a', 'b', 'c', 'd', 'e', ]; writefln("length of ra is %s", ra.length); writeln(); write("A: "); foreach (i; 0 .. ra.length) { writef("'%s' @ index %d ", ra[i], i); } writeln(); write("B: "); foreach (i, e; ra[ 0 .. $ ]) { writef("ra[%d] == '%s' ", i, e); } writeln(); write("C: "); foreach (i, e; ra) { writef("ra[%d] == '%s' ", i, e); } }
Output:
C:\@Work\DMD2\posts\davido> python_to_d_1 length of ra is 5 A: 'a' @ index 0 'b' @ index 1 'c' @ index 2 'd' @ index 3 'e' @ +index 4 B: ra[0] == 'a' ra[1] == 'b' ra[2] == 'c' ra[3] == 'd' ra[4] == ' +e' C: ra[0] == 'a' ra[1] == 'b' ra[2] == 'c' ra[3] == 'd' ra[4] == ' +e'
(The expression  ra[ 0 .. $ ] is shorthand for  ra[ 0 .. ra.length ])


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1216736]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found