Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Array slicing
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===1983: [[Ada (programming language)|Ada 83]] and above=== {{Wikibooks|Ada Programming|Types/array}} Ada 83 supports slices for all array types. Like [[Fortran#FORTRAN 77|Fortran 77]] such arrays could be passed by <u>reference</u> to another subroutine, the length would also be passed transparently to the subroutine as a kind of '''short''' dope vector. <syntaxhighlight lang="ada"> with Text_IO; procedure Main is Text : String := "ABCDE"; begin Text_IO.Put_Line (Text (2 .. 4)); end Main; </syntaxhighlight> Produces: <syntaxhighlight lang="output"> BCD </syntaxhighlight> '''Note:''' Since in Ada indices are n-based the term <code>Text (2 .. 4)</code> will result in an Array with the base index of 2. The definition for <code>Text_IO.Put_Line</code> is: <syntaxhighlight lang="ada"> package Ada.Text_IO is procedure Put_Line(Item : in String); </syntaxhighlight> The definition for <code>String</code> is: <syntaxhighlight lang="ada"> package Standard is subtype Positive is Integer range 1 .. Integer'Last; type String is array(Positive range <>) of Character; pragma Pack(String); </syntaxhighlight> As Ada supports true negative indices as in {{code|type History_Data_Array is array (-6000 .. 2010) of History_Data;|ada}} it places no special meaning on negative indices. In the example above the term <code> Some_History_Data (-30 .. 30)</code> would slice the <code>History_Data</code> from 31 [[Before Christ|BC]] to 30 [[Anno Domini|AD]] (since there was no year zero, the year number 0 actually refers to 1 [[Before Christ|BC]]).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)