tuples vs records
Asked Answered
S

3

31

What is difference between tuples and records?

Southland answered 18/11, 2010 at 6:40 Comment(2)
@BoltClock: actually I'm asking generally, but let's assume in context of Pascal or CSouthland
Terminology depends on context: you need to give us more information. C has no notion of either tuples or records in the language itself, so that depends on whichever library or whatever else is using the terms.Detest
S
20

Both are product types which let you build types from multiple simpler types. Some languages treat tuples as a kind of record.

Definitions

A tuple is an ordered group of elements, like (10, 25).

A record is typically a group of named elements like { "x": 10, "y": 25 } where the value has two fields labelled x and y and the value of field x is 10.

Etymology

The word "tuple" comes from the common "-tuple" suffix on "quintuple", "sextuple", "septuple", "octuple" which mean groups of 5, 6, 7, and 8 respectively.

The word "record" comes from data tables. You can think of all possible tuples with x and y fields as a table where columns correspond to fields and rows collect all the fields for a particular record instance.

 value address     field x    field y
 0xABCD            10         25
 0x1234            42         "xyz"

Equivalence of product types

You can treat a tuple as a kind of record, where the index of an element in a tuple is its name within the equivalent record, so (10, 25) is { "0": 10, "1": 25 }. I believe Standard ML and related languages use records as the basic unit of type conjunction (algebraic data types provide type disjunction) and treat tuples as a kind of record in this way.

Smother answered 18/11, 2010 at 6:44 Comment(0)
M
6

According to Wikipedia:

In computer science, a record (also called tuple or struct) is one of the simplest data structures, consisting of two or more values or variables stored in consecutive memory positions; so that each component (called a field or member of the record) can be accessed by applying different offsets to the starting address.

I would say there is little difference between a tuple and a record.

Molehill answered 18/11, 2010 at 6:47 Comment(2)
Wikipedia may not have this correct in the general case. Languages that implement a record and tuple concept seem to always do it with the semantics Mike Samuel describes.Sectionalism
Consecutive memory locations, using an offset.. hmm why I feel I'm reading about Arrays?Livvie
P
1

Record is a complete row of data elements of one table, let say a student has a record under roll no. 3 in one table, where as tuple is a super set of record in which data belongs to other tables also, e.g. rows of records of student roll no.3 in other tables in relationship i.e. attendance, results, contacts, fees etc. So, that whole lot of data set of one student from all tables is tuple. As I know it. Thanks.

Pneumatophore answered 5/12, 2016 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.