Tutorial by Examples: def

Values can be given names using let: # let a = 1;; val a : int = 1 You can use similar syntax to define a function. Just provide additional parameters for the arguments. # let add arg1 arg2 = arg1 + arg2;; val add : int -> int -> int = <fun> We can call it like this: # add 1...
A defer statement in Go is simply a function call marked to be executed at a later time. Defer statement is an ordinary function call prefixed by the keyword defer. defer someFunction() A deferred function is executed once the function that contains the defer statement returns. Actual call to th...
Before ECMAScript 2015 (ES6), a parameter's default value could be assigned in the following way: function printMsg(msg) { msg = typeof msg !== 'undefined' ? // if a value was provided msg : // then, use that value in the reassignemnt 'Default value for ...
This is MATLAB's long-winded way of saying that it cannot find the function that you're trying to call. There are a number of reasons you could get this error: That function was introduced after your current version of MATLAB The MATLAB online documentation provides a very nice feature which allow...
To differentiate between plural and singular strings, you can define a plural in your strings.xml file and list the different quantities, as shown in the example below: <?xml version="1.0" encoding="utf-8"?> <resources> <plurals name="hello_people&quo...
library(tidyr) ## example data set.seed(123) df <- data.frame( name = rep(c("firstName", "secondName"), each=4), numbers = rep(1:4, 2), value = rnorm(8) ) df # name numbers value # 1 firstName 1 -0.56047565 # 2 firstName 2 -0.2301...
In general, classes in Perl are just packages. They can contain data and methods, as usual packages. package Point; use strict; my $CANVAS_SIZE = [1000, 1000]; sub new { ... } sub polar_coordinates { ... } 1; It is important to note that the variables declared in a packa...
Add typings to your package.json { ... "typings": "path/file.d.ts" ... } Now when ever that library is imported typescript will load the typings file
Using pattern matching one can intertwine function definition and pattern matching, similar to SML. (trivia:defun-match fib (index) "Return the corresponding term for INDEX." (0 1) (1 1) (index (+ (fib (1- index)) (fib (- index 2))))) (fib 5) ;; => 8
(in-package #:asdf-user) (defsystem #:foo :components ((:file "foo")) :in-order-to ((asdf:test-op (asdf:load-op :foo))) :perform (asdf:test-op (o c) (uiop:symbol-call :foo-tests 'run-tests))) (defsystem #:foo-tests :name "foo-test" :compo...
ASDF provides the package ASDF-USER for developers to define their packages in.
The "factory default" number of worksheets created in a new Excel workbook is generally set to three. Your VBA code can explicitly set the number of worksheets in a new workbook. '--- save the current Excel global setting With Application Dim oldSheetsCount As Integer oldSheets...
#include <iostream> long double operator"" _km(long double val) { return val * 1000.0; } long double operator"" _mi(long double val) { return val * 1609.344; } int main() { std::cout << "3 km = " << 3.0_km << " m...
There are cases, where custom objects need to be created and defined in the resources of the application. Such objects can be composed of Java simple types, for example Integer, Float, String. Here is the example of how to import an object defined in application resources. The object Category cons...
Basic usage of dependency injection is done by the annotations. When you need to tweak things a little bit, you need custom code to further specify how you want some classes to be instantiated and injected. This code goes in what is called a Module. import com.google.inject.AbstractModule // Pla...
Abilities are defined in the Ability class using can and cannot methods. Consider the following commented example for basic reference: class Ability include CanCan::Ability def initialize(user) # for any visitor or user can :read, Article if user if user.admin? ...
The function angular.isDefined tests a value if it is defined angular.isDefined(someValue) This is the equivalent of performing value !== undefined; // will evaluate to true is value is defined Examples angular.isDefined(42) // true angular.isDefined([1, 2]) // true angular.isDefined(un...
Functions are defined with five components: The header, which includes the defn keyword, the name of the function. (defn welcome ....) An optional Docstring that explains and document what the function does. (defn welcome "Return a welcome message to the world" ...) Pa...
Deferred function calls serve a similar purpose to things like finally blocks in languages like Java: they ensure that some function will be executed when the outer function returns, regardless of if an error occurred or which return statement was hit in cases with multiple returns. This is useful f...
A declaration introduces an identifier and describes its type, be it a type, object, or function. A declaration is what the compiler needs to accept references to that identifier. These are declarations: extern int bar; extern int g(int, int); double f(int, double); /* extern can be omitted for f...

Page 9 of 27