How to use Primitive Datatype?
Hello,
I would like to know how to use Primitive Datatypes. You can create them in the structure aspect of a language. However I created a Primitive Datatype named "real" (as in real number) and used it in a property "num" of a concept "Main". When trying to set the value of this property in a sandbox I get an error:
Property contraint violation for the property "num"
From this post:
I have deduced, that I could "restrict your type in the property constraints section". I see such a section on Main_Constraints concepts contraint, although I do not know how to use is properly. Also, I want to define the usage of "real" anywhere, not just in one concept.
Thank you for any swift replies.
Please sign in to leave a comment.
Hi Adrian,
I do not know, unfortunately, about the state of primitive data types and why they cause the error you are experiencing. Maybe we will get an official comment about them. Might be a simple thing to fix, but to me it looks rather like the three existing types might be hard-coded into MPS somehow and one should not use PrimitiveDatatypeDeclaration to declare custom types. My point of reference is often what you can find in the KernelF (iets3), the mbeddr, and the mps-extensions projects. Looking at how they deal with floating point types is an indication that this might be the best way to go about it (i.e. implementing it yourself).
The mentioned ConstrainedDataTypeDeclaration, however, you could use yourself and declare your own "real" type.
About the links: there is a menu bar above the comment section. You can mark some text you want to put your link on and use the right most button to show a text field where you can paste the link into:
In case you are asking how you get such a link in the first place. Use the context menu in the editor on the node you want to have a link for.
Best,
Robert
Hi Adrian,
just some general advice in case you don't already know that: it is always a good idea in MPS to look for other instances of something that is new to you, just as a general tip.
For Primitive Datatypes, you can navigate to the concept declaration and then use the "Find Usages" dialog (Ctrl+Shift+Alt+F7) to look for instances globally:
Now, I *think* the primitive types are somewhat hard coded, or at least not what you should use for a "real" type. You might want to look into "ConstrainedDataTypeDeclaration" and see how it is used, for example here.
I hope this helps.
Firstly, thanks for the tip with the Find Usages extended options, especially the global scope helps. I had searched only Alt + F7. I have just now gone through all of the usages of integer primitive datatype but mostly to no avail when trying to find some implementation around it.
I reckon I could use one of _FPNumber_String or _FloatNumberValue for a real number, but yeah that's a bit clumsy if you have such nice string/bool/int alternatives... I was looking for an alternative of a float/double inside a concept. I am actually generating these concepts from a language model, so I was looking for standard ready-to-use alternatives to basic types, not to invent my own number types and generate also them.
But still I want to know what is the reason, goal, function, usage of a Primitive Datatype. I can create one but not use it? Why? How to actually use it and what for? I have not found much documentation on that.
P.S.: How do you put the localhost links to MPS into the forum comment?