Ada: attribute 'last and 'safe_large - attributes

it's very common in Ada to create a derived type say a new Float type with the last element being Float'Last. I have not yet seen someone using Float'Safe_Large instead of the attribute Float'Last when defining a new Float type. On my 32-bit machine, both
Put( Float'Image( Float'Last ));
and
Put( Float'Image( Float'Safe_large ));
return me the value 3.402..E38
I would like to know the difference between these two number attributes and perhaps also why 'Safe_Large is not as commonly used as the attribute 'Last.
Thanks a lot...

Presently, the Last attribute is defined for any scalar subtype. Now obsolete, Safe_Large is available in GNAT as an implementation defined attribute for compatibility with Ada 83. The Ada 95 Rationale offers some insights about the change in the discussion on "Safe Range".

Related

Right way to type as "Any"

Let's say I'm using gdscript static typing and for one function parameter I don't know in advance what I'm going to get. That's what typing.Any is for in python. How do I do it with gdscript?
It seems that Variant is not a valid type and I'm not sure about using Object for that purpose (since it could be a built-in)
edit
Leaving the type blank obviously works, but the docs has a specific section called typed-or-dynamic-stick-to-one-style, and since we're already kinda short on good practices using gdscript I'd rather find another way
Any idea?
As of Godot 3.2, GDScript does not feature a Variant or any type hint yet. However, you can still use the Object type hint if you expect a variable to hold any object (or null, as Object is nullable by design). Object may not hold primitive types like int or bool though.
Therefore, you should just leave out the type hint for now.

A question about AUTOSAR, does [constr_1221] apply to Initial Value Representation at level 2?

When i use a NumericalValueSpecification to init value for an ApplicationPrimitiveDataType of category 'BOOLEAN' with a NonqueuedSenderComSpec, it can correctly generate RTE codes without any compilation error, but as [constr_1221] said, if a DataPrototype is typed by an ApplicationPrimitiveDataType its initValue shall be provided by an ApplicationValueSpecification. So, does [constr_1221] apply to Initial Value Representation at level 2?
Yes, any DataPrototype that is typed by an ApplicationDataType shall only be initialized by means of an ApplicationValueSpecification. A NumericalValueSpecification or TextValueSpecification can be used to initialize a DataPrototype typed by an ImplementationDataType.

How to get fields of a Julia object

Given a Julia object of composite type, how can one determine its fields?
I know one solution if you're working in the REPL: First you figure out the type of the object via a call to typeof, then enter help mode (?), and then look up the type. Is there a more programmatic way to achieve the same thing?
For v0.7+
Use fieldnames(x), where x is a DataType. For example, use fieldnames(Date), instead of fieldnames(today()), or else use fieldnames(typeof(today())).
This returns Vector{Symbol} listing the field names in order.
If a field name is myfield, then to retrieve the values in that field use either getfield(x, :myfield), or the shortcut syntax x.myfield.
Another useful and related function to play around with is dump(x).
Before v0.7
Use fieldnames(x), where x is either an instance of the composite type you are interested in, or else a DataType. That is, fieldnames(today()) and fieldnames(Date) are equally valid and have the same output.
suppose the object is obj,
you can get all the information of its fields with following code snippet:
T = typeof(obj)
for (name, typ) in zip(fieldnames(T), T.types)
println("type of the fieldname $name is $typ")
end
Here, fieldnames(T) returns the vector of field names and T.types returns the corresponding vector of type of the fields.

Keywords with and without # in Swift

In Swift, sometimes, keywords are plain keywords, and some others start with an #.
For instance, weak, unowned, inout, class are plain. But #final, #lazy start with #.
Sometimes, we even have both! prefix and #prefix, infix and #infix for instance.
It is not entirely an Objective-C inheritance since we have #class and not class in Objective-C. I could understand why we have class and not #class in Swift, but since we have #final or #lazy , I would have thought that it should be #weak and not weak.
Why this choice? Is there a kind of intuitive way that should tell: "hey, it is logical that this keyword starts with #?
Even if I think with a preprocessor perspective in mind, it is not obvious that # would call a kind of specific preprocessor before compilation (e.g. #final is not really a kind of preprocessor directive).
#-prefixed items in Swift are not keywords, these are attributes.
Apple's book on Swift says that
Attributes provide more information about a declaration or type. There are two kinds of attributes in Swift, those that apply to declarations and those that apply to types.
Some attributes (such as #objc(isEnabled)) accept parameters.
The main difference between attributes and keywords is that keywords tell the compiler what you are defining (a class, a method, a property, a variable, and so on), while attributes tell the compiler in what contexts you intend to use that definition. For example, you would use a func keyword to tell the compiler that you are defining a function, and decorate that function with an #infix attribute to tell the compiler that you plan to use that function as an infix operator.

i'm confused about languages category, can anyone please explain?

Which of the following statements is FALSE?
(A) In statically typed languages, each variable in a program has a fixed type
(B) In un-typed languages, values do not have any types
(C) In dynamically typed languages, variables have no types
(D) In all statically typed languages, each variable in a program is associated with values of only a single type during the execution of the program
Can you please explain the theory as well?
C) (In dynamically typed languages, variables have no types) Is false.
The variable has a type, however it is simply not stated or decided until run time. This implies there is no type checking prior to running the program.
a useful link describing Types and what it means:
http://en.wikipedia.org/wiki/Type_system
If you have ever done much with PHP you will notice that when you declare a varialbe, you do not have to say whether it is an INT or a STRING. However, sometimes you know that you will be receiving a string, but need an int, so you can still type cast variables at runtime, even though when you declared the variable you did not explicitly state the variable would hold an int.
<?php
#some more code here.....
# over here $myValue could be of some different type, but it can dynamically change to another type
$myValue = '5'; #storing a string...so $myValue is currently of type String
$myNewValue = (int)$myValue + 5 #type casted to integer, so in this case $myValue is currently of type integer
?>
If that doesn't help, maybe take a look at this.
myPythonVariable = "I am currently a string" #the variable is of type string
myPythonVariable = 5 #the variable is now of type integer
In the above code sample, myPythonVariable always has a type, whether or not that type changes doesn't matter.

Resources