Sometimes you want to destructure key under a map which might not be present in the map, but you want a default value for the destructured value. You can do that this way:
(def my-map {:a 3 :b 4})
(let [{a :a
b :b
:keys [c d]
:or {a 1
c 2}} my-map]
(println ...
Destructurling works in many places, as well as in the param list of an fn:
(defn my-func [[_ a b]]
(+ a b))
(my-func [1 2 3]) ;= 5
(my-func (range 5)) ;= 3
Destructuring also works for the & rest construct in the param list:
(defn my-func2 [& [_ a b]]
(+ a b))
(my-func2 1 ...
Destructuring also gives you the ability to interpret a sequence as a map:
(def my-vec [:a 1 :b 2])
(def my-lst '("smthg else" :c 3 :d 4))
(let [[& {:keys [a b]}] my-vec
[s & {:keys [c d]} my-lst]
(+ a b c d)) ;= 10
It is useful for defining functions with named p...
Predicates that produce side effects leave the realm of pure logic. These are for example:
writeq/1
read/1
format/2
Side effects are phenomena that cannot be reasoned about within the program. For example, deletion of a file or output on the system terminal.
Predicates that reason about instantiations are called meta-logical. Examples are:
var/1
ground/1
integer/1
These predicates are outside the realm of pure monotonic logic programs, because they break properties like commutativity of conjunction.
Other predicates that are meta-logical includ...
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.
In oracle, the difference (in days and/or fractions thereof) between two DATEs can be found using subtraction:
SELECT DATE '2016-03-23' - DATE '2015-12-25' AS difference FROM DUAL;
Outputs the number of days between the two dates:
DIFFERENCE
----------
89
And:
SELECT TO_DATE( '201...
Our example array:
arr=(a b c d e f)
Using a for..in loop:
for i in "${arr[@]}"; do
echo "$i"
done
2.04
Using C-style for loop:
for ((i=0;i<${#arr[@]};i++)); do
echo "${arr[$i]}"
done
Using while loop:
i=0
while [ $i -lt ${#arr[@]} ]; do...
The MEDIAN function since Oracle 10g is an easy to use aggregation function:
SELECT MEDIAN(SAL)
FROM EMP
It returns the median of the values
Works on DATETIME values too.
The result of MEDIAN is computed by first ordering the rows. Using N as the number of rows in the group, Oracle calcula...
Following code will release the lock. There will be no problem. Behind the scenes lock statement works as try finally
lock(locker)
{
throw new Exception();
}
More can be seen in the C# 5.0 Specification:
A lock statement of the form
lock (x) ...
where x is an expression of a referenc...
Partial application means calling a function with less arguments than it has and saving the result as another function (that waits for the rest of the arguments).
multiplyBy: Int -> Int -> Int
multiplyBy x y =
x * y
multiplyByTwo : Int -> Int -- one Int has disappeared! we ...
The function toupper will convert a string to upper case (capital letters). For example:
BEGIN {
greeting = "hello"
loud_greeting = toupper(greeting)
print loud_greeting
}
This code will output "HELLO" when run.
Given a C++ source file main.cpp defining a main() function, an accompanying CMakeLists.txt file (with the following content) will instruct CMake to generate the appropriate build instructions for the current system and default C++ compiler.
main.cpp (C++ Hello World Example)
#include <iostream...
We create a new concurrent process by calling the spawn function. The spawn function will get as parameter a function Fun that the process will evaluate. The return value of the spawn function is the created process identifier (pid).
1> Fun = fun() -> 2+2 end.
#Fun<erl_eval.20.52032458>...
Enum classes as any other classes can have a constructor and be initialized
enum class Color(val rgb: Int) {
RED(0xFF0000),
GREEN(0x00FF00),
BLUE(0x0000FF)
}
Enum classes can also declare members (i.e. properties and functions). A semicolon (;) must be placed between the last enum object and the first member declaration.
If a member is abstract, the enum objects must implement it.
enum class Color {
RED {
override val rgb: Int = 0xFF0000
...