Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does tuple_size count the elements in the tuple like lists:length()?

Tags:

erlang

Is there ever a reason where I would do something like:

{foobar, NumberOfElementsInFoobarTuple, ...}

I would imagine the internal datastructure for tuple_size knows it's size already, like the binary type. With binaries it's still beneficial to keep track of byte size as a variable instead of calling byte_size(). It doesn't make sense but that's how it is. I'm creating this tuple through list_to_tuple so it may have varying size.

like image 210
BreezyChick89 Avatar asked Apr 30 '26 10:04

BreezyChick89


1 Answers

A tuple is one fixed size block compared to a list which is a linked list of list cells each of which has a head and a tail. So a tuple explicitly contains its size and tuple_size(Tuple) just directly returns this value.

like image 195
rvirding Avatar answered May 02 '26 23:05

rvirding



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!