Tutorial by Examples: c

A traversal can be run in the opposite direction with the help of the Backwards applicative functor, which flips an existing applicative so that composed effects take place in reversed order. newtype Backwards f a = Backwards { forwards :: f a } instance Applicative f => Applicative (Backward...
The standard (section 23.3.7) specifies that a specialization of vector<bool> is provided, which optimizes space by packing the bool values, so that each takes up only one bit. Since bits aren't addressable in C++, this means that several requirements on vector are not placed on vector<bool...
When the following is compiled, it will return a different value depending on which directives are defined. // Compile with /d:A or /d:B to see the difference string SomeFunction() { #if A return "A"; #elif B return "B"; #else return "C"; #endif ...
Compiler warnings can be generated using the #warning directive, and errors can likewise be generated using the #error directive. #if SOME_SYMBOL #error This is a compiler Error. #elif SOME_OTHER_SYMBOL #warning This is a compiler Warning. #endif
Use #region and #endregion to define a collapsible code region. #region Event Handlers public void Button_Click(object s, EventArgs e) { // ... } public void DropDown_SelectedIndexChanged(object s, EventArgs e) { // ... } #endregion These directives are only beneficial whe...
Line #line controls the line number and filename reported by the compiler when outputting warnings and errors. void Test() { #line 42 "Answer" #line filename "SomeFile.cs" int life; // compiler warning CS0168 in "SomeFile.cs" at Line 42 #line defa...
package main import ( "log" "net/http" ) func main() { // Create a mux for routing incoming requests m := http.NewServeMux() // All URLs will be handled by this function m.HandleFunc("/", func(w http.ResponseWriter, r *http.Reque...
#import <Foundation/Foundation.h> @interface Car:NSObject { NSString *CarMotorCode; NSString *CarChassisCode; } - (instancetype)initWithMotorValue:(NSString *) motorCode andChassisValue:(NSInteger)chassisCode; - (void) startCar; - (void) stopCar; @end @implementation Car...
C11 Reading an object will cause undefined behavior, if the object is1: uninitialized defined with automatic storage duration it's address is never taken The variable a in the below example satisfies all those conditions: void Function( void ) { int a; int b = a; } 1 (Quo...
The following will log the JSON response from the API to the console if the request was successful, otherwise it will log the error. var xhr = new XMLHttpRequest(); xhr.open('GET', 'https://api.twitch.tv/kraken', true); xhr.setRequestHeader('Client-ID', '...'); xhr.onload = function(...
Array types inherit their equals() (and hashCode()) implementations from java.lang.Object, so equals() will only return true when comparing against the exact same array object. To compare arrays for equality based on their values, use java.util.Arrays.equals, which is overloaded for all array types...
// Create an array with a fixed size and type. var array = new Uint8Array(5); // Generate cryptographically random values crypto.getRandomValues(array); // Print the array to the console console.log(array); crypto.getRandomValues(array) can be used with instances of the following classes...
// Convert string to ArrayBuffer. This step is only necessary if you wish to hash a string, not if you aready got an ArrayBuffer such as an Uint8Array. var input = new TextEncoder('utf-8').encode('Hello world!'); // Calculate the SHA-256 digest crypto.subtle.digest('SHA-256', input) // Wait fo...
With constructor: Vector v1 = new Vector(); v1.X = 1; v1.Y = 2; v1.Z = 3; Console.WriteLine("X = {0}, Y = {1}, Z = {2}",v1.X,v1.Y,v1.Z); // Output X=1,Y=2,Z=3 Vector v1 = new Vector(); //v1.X is not assigned v1.Y = 2; v1.Z = 3; Console.WriteLine("X = {0}, Y = {1}, Z =...
Setting values Using Unicode directly var str: String = "I want to visit 北京, Москва, मुंबई, القاهرة, and 서울시. 😊" var character: Character = "🌍" Using hexadecimal values var str: String = "\u{61}\u{5927}\u{1F34E}\u{3C0}" // a大🍎π var character: Character = &quo...
Swift's C interoperability allows you to use functions and types from the C standard library. On Linux, the C standard library is exposed via the Glibc module; on Apple platforms it's called Darwin. #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin #elseif os(Linux) import Glibc...
6 var myIterableObject = {}; // An Iterable object must define a method located at the Symbol.iterator key: myIterableObject[Symbol.iterator] = function () { // The iterator should return an Iterator object return { // The Iterator object must implement a method, next() next: func...
dynamic foo = 123; Console.WriteLine(foo + 234); // 357 Console.WriteLine(foo.ToUpper()) // RuntimeBinderException, since int doesn't have a ToUpper method foo = "123"; Console.WriteLine(foo + 234); // 123234 Console.WriteLine(foo.ToUpper()): // NOW A STRING
using System; public static void Main() { var value = GetValue(); Console.WriteLine(value); // dynamics are useful! } private static dynamic GetValue() { return "dynamics are useful!"; }
using System; using System.Dynamic; dynamic info = new ExpandoObject(); info.Id = 123; info.Another = 456; Console.WriteLine(info.Another); // 456 Console.WriteLine(info.DoesntExist); // Throws RuntimeBinderException

Page 62 of 826