Development Tip

인덱스 배열 위치가 0이 아닌 다른 일반적인 "c 유사"또는 비 "c 유사"언어가 있습니까?

yourdevel 2020. 10. 20. 08:14
반응형

인덱스 배열 위치가 0이 아닌 다른 일반적인 "c 유사"또는 비 "c 유사"언어가 있습니까?


C 프로그래밍 언어는 제로 인덱스 배열 언어로 알려져 있습니다. 배열의 첫 번째 항목은를 사용하여 액세스 할 수 있습니다 0. 예를 들어 double arr[2] = {1.5,2.5}배열의 첫 번째 항목 arr은 위치 0에 arr[0] === 1.5있습니다. 1 기반 인덱스는 어떤 프로그래밍 언어입니까?

배열 액세스를 위해 이러한 언어가 0이 아닌 1에서 시작한다고 들었습니다 : Algol, Matlab, Action !, Pascal, Fortran, Cobol. 완료 되었습니까?

구체적으로 1 기반 배열은 0이 아닌 1로 첫 번째 항목에 액세스합니다.


목록은 wikipedia 에서 찾을 수 있습니다 .

ALGOL 68
APL
AWK
CFML
COBOL
Fortran
FoxPro
Julia
Lua
Mathematica
MATLAB
PL/I
Ring
RPG
Sass
Smalltalk
Wolfram Language
XPath/XQuery

Fortran은 1부터 시작합니다. 제 아버지는 제가 태어나 기 전에 Fortran을 프로그래밍하곤 하셨고 (지금은 33 살입니다) 0부터 시작하는 현대 프로그래밍 언어를 정말 비판 하셨기 때문에 수학과는 달리 인간이 생각하는 방식이 아니라 부자연 스럽다고 말씀하셨습니다. 곧.

그러나 0에서 시작하는 것은 매우 자연 스럽습니다. 내 첫 번째 실제 프로그래밍 언어는 C 였고 n이 0에서 시작하지 않았다면 * (ptr + n)은 그렇게 잘 작동하지 않았을 것입니다!


상당히 큰 언어 목록은 Wikipedia의 "Array system cross-reference list"테이블 (기본 기본 인덱스 열) 아래의 Compare of Programming Languages ​​(array) 아래에 있습니다.

이것은 일반적으로 1- 대 0- 인덱싱 및 구독에 대한 좋은 토론을 가지고 있습니다.

블로그에서 인용하려면 :

EW Dijkstra의 EWD831, 1982.

첨자로 구분하려는 요소 인 길이 N의 시퀀스를 다룰 때 다음 번거로운 질문은 시작 요소에 할당 할 첨자 값입니다. 규칙 a)를 준수하면 아래 첨자 1로 시작할 때 아래 첨자 범위 1 ≤ i <N + 1이됩니다. 그러나 0으로 시작하면 더 좋은 범위 0 ≤ i <N을 제공합니다. 따라서 서수를 0에서 시작하도록하겠습니다. 요소의 서수 (아래 첨자)는 시퀀스에서 선행하는 요소의 수와 같습니다. 그리고 이야기의 교훈은 우리가 – 그 모든 세기가 지난 후에! – 0을 가장 자연적인 숫자로 더 잘 인식했다는 것입니다.

비고 :: 많은 프로그래밍 언어는이 세부 사항에 대한주의없이 설계되었습니다. FORTRAN에서 아래 첨자는 항상 1부터 시작합니다. ALGOL 60 및 PASCAL에서는 c) 협약이 채택되었습니다. 더 최근의 SASL은 FORTRAN 규약으로 대체되었습니다. SASL의 시퀀스는 동시에 양의 정수에 대한 함수입니다. 안타깝다! (비고 끝.)


Fortran, Matlab, Pascal, Algol, Smalltalk 및 기타 다수.


Perl에서 할 수 있습니다.

$[ = 1;  # set the base array index to 1

그렇게 느끼면 42로 시작할 수도 있습니다. 이는 문자열 인덱스에도 영향을 미칩니다.

실제로이 기능을 사용하는 것은 권장되지 않습니다.


또한 Ada에서 필요에 따라 배열 인덱스를 정의 할 수 있습니다.

A : array(-5..5) of Integer;       -- defines an array with 11 elements
B : array(-1..1, -1..1) of Float;  -- defines a 3x3 matrix

누군가는 사용자 정의 배열 인덱스 범위가 유지 관리 문제로 이어질 것이라고 주장 할 수 있습니다. 그러나 배열 인덱스에 의존하지 않는 방식으로 Ada 코드를 작성하는 것은 정상입니다. 이를 위해 언어는 정의 된 모든 유형에 대해 자동으로 정의되는 요소 속성을 제공합니다.

A'first   -- this has the value -5
A'last    -- this has the value +5
A'range   -- returns the range -5..+5 which can be used e.g. in for loops

JDBC (언어가 아니라 API)

String x = resultSet.getString(1);  // the first column

Erlang의 튜플목록 인덱스는 1부터 시작합니다.


Lua-실망스럽게


찾음 -Lua (프로그래밍 언어)

다음과 같은 배열 섹션을 확인하십시오.

"Lua 배열은 1 기반입니다. 첫 번째 인덱스는 다른 많은 프로그래밍 언어와 마찬가지로 0이 아니라 1입니다 (명시적인 인덱스 0도 허용됨)."


VB Classic, 적어도

Option Base 1

Delphi의 문자열은 1부터 시작합니다.

(정적 배열에는 명시 적으로 지정된 하한이 있어야합니다. 동적 배열은 항상 0에서 시작합니다.)


ColdFusion-Java 내부에 있지만


Ada와 Pascal.


PL / SQL . 이것의 결론은 0에서 시작하는 언어를 사용하고 Oracle과 상호 작용할 때 인덱스에 의한 어레이 액세스를 위해 0-1 변환을 직접 처리해야한다는 것입니다. 실제로 foreach과 같은 구조를 사용 하거나 이름으로 열에 액세스하는 경우 큰 문제는 아니지만 가장 왼쪽 열 (예 : 열 1)을 원할 수 있습니다.


인덱스는 CFML에서 1부터 시작합니다.


Pascal, Object Pascal, Modula-2, Modula-3, Oberon, Oberon-2 및 Ada를 포함한 전체 Wirthian 언어 라인을 통해 원하는 지점에서 배열을 색인화 할 수 있습니다. 분명히, 1.

Erlang indexes tuples and arrays from 1.

I think—but am no longer positive—that Algol and PL/1 both index from 1. I'm also pretty sure that Cobol indexes from 1.

Basically most high level programming languages before C indexed from 1 (with assembly languages being a notable exception for obvious reasons – and the reason C indexes from 0) and many languages from outside of the C-dominated hegemony still do so to this day.


There is also Smalltalk


Visual FoxPro, FoxPro and Clipper all use arrays where element 1 is the first element of an array... I assume that is what you mean by 1-indexed.


I see that the knowledge of fortran here is still on the '66 version.

Fortran has variable both the lower and the upper bounds of an array.

Meaning, if you declare an array like:

real, dimension (90) :: x

then 1 will be the lower bound (by default).

If you declare it like

real, dimension(0,89) :: x

then however, it will have a lower bound of 0.

If on the other hand you declare it like

real, allocatable :: x(:,:)

then you can allocate it to whatever you like. For example

allocate(x(0:np,0:np))

means the array will have the elements

x(0, 0), x(0, 1), x(0, 2 .... np)
x(1, 0), x(1, 1), ...
.
.
.
x(np, 0) ...

There are also some more interesting combinations possible:

real, dimension(:, :, 0:) :: d
real, dimension(9, 0:99, -99:99) :: iii

which are left as homework for the interested reader :)

These are just the ones I remembered off the top of my head. Since one of fortran's main strengths are array handling capabilities, it is clear that there are lot of other in&outs not mentioned here.


Nobody mentioned XPath.


Mathematica and Maxima, besides other languages already mentioned.


informix, besides other languages already mentioned.


Basic - not just VB, but all the old 1980s era line numbered versions.

Richard


FoxPro used arrays starting at index 1.


dBASE used arrays starting at index 1.

Arrays (Beginning) in dBASE


RPG, including modern RPGLE


Although C is by design 0 indexed, it is possible to arrange for an array in C to be accessed as if it were 1 (or any other value) indexed. Not something you would expect a normal C coder to do often, but it sometimes helps.

Example:

#include <stdio.h>
int main(){
    int zero_based[10];
    int* one_based;
    int i;
    one_based=zero_based-1;

    for (i=1;i<=10;i++) one_based[i]=i;
    for(i=10;i>=1;i--) printf("one_based[%d] = %d\n", i, one_based[i]);
    return 0;
}

참고URL : https://stackoverflow.com/questions/1499749/are-there-other-common-c-like-or-non-c-like-languages-with-non-zero-index-ar

반응형