Primitives

Hey guys,

so we all know that every language has primitives C++ has - int,bool,double,long,short,char etc

but is there any language with more primitives? better yet does any language have strange primitives that C++ does not have?

also is the string type a primitive in any language? As far as I can recall I think Python has data structures like list and tuple as primitives
Python's strings are "primitive".

Python does have language support for tuples but a tuple isn't a concrete type, no more than a list is a type or a C++ template is a type; some languages might call these things "type constructors" or relate them to "higher-kinded types", depending on the theory the particular tool relies on:
https://en.wikipedia.org/wiki/Type_constructor
https://en.wikipedia.org/wiki/Kind_(type_theory)

Does any language have strange primitives that C++ does not have?

Common lisp has symbols, which are data objects that (among other things) name variables, functions and macros.
There is also a broader view beyond primitive data types.
https://en.wikipedia.org/wiki/Language_primitive
And that is what throws me. I think of primitive(atomic?) as 'can be represented on the cpu in one register of some sort'. So for most modern computers that is all the integer types up to 64 bits of any sign (includes char which is just an integer with a special printing option, includes pointers which are just integer offsets, etc) + float and double. If you want to call an array primitive, because it is effectively a pointer in c/c++, then C-strings would be primitive from that definition.

The language primitive thing is just weird in a lot of languages. Some rather complex things are considered primitive in some languages.
Last edited on
And that is what throws me.

https://www.techopedia.com/definition/3860/primitive is another place to widen the horizons.

'primitive' can mean just about anything depending on the level of programming.

At the circuit level there are only two primitives - 0 and 1. Or maybe it is individual electrons, photons or even quantum bits.

At the other end of the spectrum a CAD program has a point and a line as the relevant primitives (data type) and that's without even considering function primitives.

SDL2 as we have all come to know has primitives, even built-in collision detection functionality ... a primitive for use in the final game design.
'can be represented on the cpu in one register of some sort'
By this definition C++ doesn't have primitives, because the language doesn't guarantee any relationship between types exposed by the implementation and data sizes that the hardware can handle natively. A compliant compiler targeting an 8-bit architecture could present a 128-bit long type. As a more concrete example, long long on 32-bit Windows is (was?) a software-emulated 64-bit integer implemented as two hardware 32-bit integers.

High-level languages present a machine model where all operations are reducible to operations between values of a limited set of fundamental types. The word "primitive" refers to any of these types.
Last edited on
I get that. But that puts it back to:

'primitive' can mean just about anything depending on the level of programming.


The concept itself seems flawed -- trying to define things that make sense in a narrow scope (one language?) but not really across the board.
How is that a flaw, though? Yes, two languages may have different primitives. They may also have different grammar and different semantics. I don't understand the issue.

The problem of finding something that holds throughout all languages is that the abstract idea of a programming language is too powerful. You could construct a Turing tarpit out of a single primitive (a bit) and as few as two operators. Example:
https://esolangs.org/wiki/Ultimate_bf_instruction_minimalization!
Or you could construct a DSL with exceedingly complex primitives, because the language helps you succinctly express complex manipulations on large volumes of data.
In general all you'll able to say about all languages is that they have grammar and semantics (primitives would be part of the semantics), which is such an abstract statement it's almost useless.
When I use a word,” Humpty Dumpty said in rather a scornful tone, “it means just what I choose it to mean — neither more nor less.”
“The question is,” said Alice, “whether you can make words mean so many different things.”
“The question is,” said Humpty Dumpty, “which is to be master – – that’s all.”
If the only languages you have experience with are ones "close to the metal" then you will think primitive types are ones the hardware can handle efficiently.
But that's just one way of designing a language.
In general, "primitive" just means that it's built in to the core of the language.

In Perl, regex is primitive!
There is at least one universal primitive of every programming language and that is the single instruction or set of instructions required to commence execution of a useful program in that language.

If it is a set of instructions then any subset of that set is itself a primitive.

The primitive can also be the whole program.

int main blah blah is a primitive of C++ which initiates program execution.

Turning the power on is a language-independent primitive of all executeable computer programming languages given that most, if not all, programmable devices are driven by some form of energy.
In general all you'll able to say about all languages is that they have grammar and semantics (primitives would be part of the semantics), which is such an abstract statement it's almost useless.



And yes, that is about where I ended up.
Grammar and semantics are both made up of primitives. Collectively and separately in functional and data form they provide conceptual context and arguably the sole utility of any, if not all, programs.

Primitives are hardly useless. They are even less abstract as the numerous examples here show. To say concrete as a building primitive is abstract or useless is obviously incorrect.
Topic archived. No new replies allowed.