Firstly, you'll need to add the crate into your Cargo.toml file as a dependency.
[dependencies]
rand = "0.3"
This will retrieve the rand crate from crates.io. Next, add this to your crate root.
extern crate rand;
As this example is going to provide a simple output through the term...
Combining change of character case with Enumeration_IO and using a text buffer for the image. The first character is manipulated in place.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Handling; use Ada.Characters.Handling;
procedure Main is
type Fruit is (Banana, Pear, Orange, Me...
There are standard functions built in for comparing equality, inequality etc.
NameSymbolAlternativeExampleEqual=EQi = jNot equal<>NEi <> jLess than<LTi < jless than or equal<=LEi <= jGreater than>=GTi > jGreater than or equal≥=GEi >= j
The symbol can be exchanged w...
RANDOM - generates a random number
RANDOM(low, high)
Generates a pseudo random integer between low and high
// Example that generates 20 random numbers between 1 and 20 (1 and 20 included)
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 1 TO 20.
DISPLAY i RANDOM(1, 20).
PAUSE.
...
Ada.Text_IO.Editing offers formatting decimal fixed point values using “picture strings”. These describe output using “magical” characters for separators, currency signs, etc.
with Ada.Text_IO.Editing; use Ada.Text_IO;
procedure Print_Value is
Max_Count : constant := 1_000_000;
...
Sometimes it is required to implement Enum on your own. E.g. there is no clear way to extend other enums. Custom implementation allows this:
class Enum {
constructor(protected value: string) {}
public toString() {
return String(this.value);
}
public is(value: Enum | string) {
...
enum SourceEnum {
value1 = <any>'value1',
value2 = <any>'value2'
}
enum AdditionToSourceEnum {
value3 = <any>'value3',
value4 = <any>'value4'
}
// we need this type for TypeScript to resolve the types correctly
type TestEnumType = SourceEnum | AdditionToS...
@sorted = sort { $a <=> $b } @list;
Comparing $a and $b with the <=> operator ensures they are compared numerically and not textually as per default.
The user can call Incrementor.Increment K number of times by pressing a key within '0' .. '9' and it's possible to call Incrementor.Increment faster than the task Incrementor can increment I.
with Ada.Text_IO;
with Ada.Integer_Text_IO;
procedure Main is
use Ada.Text_IO;
task Incrementor...
NameStorage SizeDescriptionRangesmallint2 bytessmall-range integer-32768 to +32767integer4 bytesypical choice for integer-2147483648 to +2147483647bigint8 byteslarge-range integer-9223372036854775808 to +9223372036854775807decimalvariableuser-specified precision, exactup to 131072 digits before the...
The following code will attempt to execute loadFromHttp() up to 5 times (maxAttempts), with each attempt delayed by as many seconds. If maxAttempts is surpassed, the Observable gives up.
// assume loadFromHttp() returns a Promise, which might fail.
Rx.Observable.from(loadFromHttp())
....
Converting date and time strings to numeric arrays can be done with datenum, though it may take as much as half the time of reading a large data file.
Consider the data in example Textscan. By, again, using textscan and interpret date and time as integers, they can rapidly be converted into a numer...
If you need to select between several options,
enabling just one via enable_if<> can be quite cumbersome,
since several conditions needs to be negated too.
The ordering between overloads can instead be selected using
inheritance, i.e. tag dispatch.
Instead of testing for the thing that ne...
As of Salt version 2014.1.0, Salt uses a date based system for version numbers. Version numbers are in the format YYYY.MM.R. The year (YYYY) and month (MM) indicate when the release was created. The bugfix release number (R) increments within that feature release.
In order to distinguish future rel...
Let's say we want to move a given date a numof months. We can define the following function, that uses the mondate package:
moveNumOfMonths <- function(date, num) {
as.Date(mondate(date) + num)
}
It moves consistently the month part of the date and adjusting the day, in case the date re...
The following regular expression:
us.phones.regex <- "^\\s*(\\+\\s*1(-?|\\s+))*[0-9]{3}\\s*-?\\s*[0-9]{3}\\s*-?\\s*[0-9]{4}$"
Validates a phone number in the form of: +1-xxx-xxx-xxxx, including optional leading/trailing blanks at the beginning/end of each group of numbers, but not ...
type Fruit is (Banana, Orange, Pear);
Choice : Fruit := Banana;
A character type is an enumeration that includes a character literal:
type Roman_Numeral is
('I', 'V', 'X', 'L', 'C', 'D', 'M', Unknown);`
Optionals type, which handles the absence of a value. Optionals say either "there is a value, and it equals x" or "there isn't a value at all".
An Optional is a type on its own, actually one of Swift’s new super-powered enums. It has two possible values, None and Some(T), where ...