Tutorial by Examples: const

With TypeScript 1.8 it becomes possible for a type parameter constraint to reference type parameters from the same type parameter list. Previously this was an error. function assign<T extends U, U>(target: T, source: U): T { for (let id in source) { target[id] = source[id]; ...
Class implementation: CLASS lcl_abap_class DEFINITION. PUBLIC SECTION. METHODS: constructor, method1. PROTECTED SECTION. PRIVATE SECTION. METHODS: method2, method3. ENDCLASS. CLASS lcl_abap_class IMPLEMENTATION. METHOD constructor. &q...
As the static keyword is used for accessing fields and methods without an instantiated class, it can be used to declare constants for use in other classes. These variables will remain constant across every instantiation of the class. By convention, static variables are always ALL_CAPS and use unders...
CLP(FD) constraints are provided by all serious Prolog implementations. They allow us to reason about integers in a pure way. ?- X #= 1 + 2. X = 3. ?- 5 #= Y + 2. Y = 3.
CLP(FD) constraints are completely pure relations. They can be used in all directions for declarative integer arithmetic: ?- X #= 1+2. X = 3. ?- 3 #= Y+2. Y = 1.
Declaration and usage. // a is const int, so it can't be changed const int a = 15; a = 12; // Error: can't assign new value to const variable a += 1; // Error: can't assign new value to const variable Binding of references and pointers int &b = a; // Error: ca...
int a = 0, b = 2; const int* pA = &a; // pointer-to-const. `a` can't be changed through this int* const pB = &a; // const pointer. `a` can be changed, but this pointer can't. const int* const pC = &a; // const pointer-to-const. //Error: Cannot assign to a const reference *pA = b...
The non-block do construct looks like integer i do 100, i=1, 5 100 print *, i That is, where the labelled termination statement is not a continue statement. There are various restrictions on the statement that can be used as the termination statement and the whole thing is generally v...
A do construct is a looping construct which has a number of iterations governed by a loop control integer i do i=1, 5 print *, i end do print *, i In the form above, the loop variable i passes through the loop 5 times, taking the values 1 to 5 in turn. After the construct has completed th...
Member functions of a class can be declared const, which tells the compiler and future readers that this function will not modify the object: class MyClass { private: int myInt_; public: int myInt() const { return myInt_; } void setMyInt(int myInt) { myInt_ = myInt; } }; In a ...
Custom constructors can be made for derived types by using an interface to overload the type name. This way, keyword arguments that don't correspond to components can be used when constructing an object of that type. module ball_mod implicit none ! only export the derived type, and not any ...
In general, it is considered good practice to throw by value (rather than by pointer), but catch by (const) reference. try { // throw new std::runtime_error("Error!"); // Don't do this! // This creates an exception object // on the heap and would require you to catch the ...
You can declare multiple constants within the same const block: const ( Alpha = "alpha" Beta = "beta" Gamma = "gamma" ) And automatically increment constants with the iota keyword: const ( Zero = iota // Zero == 0 One // One == 1...
Large fluent assertions do become harder to read, but when combined with classes that have good implementations of ToString(), they can generate very useful error messages. [Test] public void AdvancedContraintsGiveUsefulErrorMessages() { Assert.That(actualCollection, Has .Count.Equa...
When a function is invoked as a constructor with the new keyword this takes the value of the object being constructed function Obj(name) { this.name = name; } var obj = new Obj("Foo"); console.log(obj); This will log { name: "Foo" }
An easy way to clone an object is by implementing a copy constructor. public class Sheep { private String name; private int weight; public Sheep(String name, int weight) { this.name = name; this.weight = weight; } // copy constructor // copies...
DROP PROCEDURE if exists displayNext100WithName; DELIMITER $$ CREATE PROCEDURE displayNext100WithName ( nStart int, tblName varchar(100) ) BEGIN DECLARE thesql varchar(500); -- holds the constructed sql string to execute -- expands the sizing of the output buffer to accomoda...
The type alias keyword combination gives a new name for a type, but the type keyword in isolation declares a new type. Let's examine one of the most fundamental of these types: Maybe type Maybe a = Just a | Nothing The first thing to note is that the Maybe type is declared with a type ...
It is possible to create custom routing constraint which can be used inside routes to constraint a parameter to specific values or pattern. This constrain will match a typical culture/locale pattern, like en-US, de-DE, zh-CHT, zh-Hant. public class LocaleConstraint : IRouteConstraint { pri...
Python's string module provides constants for string related operations. To use them, import the string module: >>> import string string.ascii_letters: Concatenation of ascii_lowercase and ascii_uppercase: >>> string.ascii_letters 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ...

Page 5 of 13