Tutorial by Examples: clause

Guard clauses enables us to check the arguments before executing the function. Guard clauses are usually preferred to if and cond due to their readability, and to make a certain optimization technique easier for the compiler. The first function definition where all guards match is executed. Here is...
LOOP has its own IF statement that can control how the clauses are executed: (loop repeat 1000 for x = (random 100) if (evenp x) collect x into evens else collect x into odds finally (return (values evens odds))) Combining multiple clauses in an IF ...
Within a LOOP, you can use the Common Lisp (return) form in any expression, which will cause the LOOP form to immediately evaluate to the value given to return. LOOP also has a return clause which works almost identically, the only difference being that you don't surround it with parentheses. The c...
SELECT * FROM customers WHERE id IN ( SELECT DISTINCT customer_id FROM orders ); The above will give you all the customers that have orders in the system.
with clause is used to combine matching clauses. It looks like we combine anonymous functions or handle function with multiple bodies (matching clauses). Consider the case: we create a user, insert it into DB, then create greet email and then send it to the user. Without the with clause we might ...
Query: SELECT * FROM Customers ORDER BY CustomerID LIMIT 3; Result: CustomerID CustomerName ContactName Address City PostalCode Country 1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Ge...
Using the Employees Table, below is an example to return the Id, FName and LName columns in (ascending) LName order: SELECT Id, FName, LName FROM Employees ORDER BY LName Returns: IdFNameLName2JohnJohnson1JamesSmith4JohnathonSmith3MichaelWilliams To sort in descending order add the DESC keywo...
The FETCH clause was introduced in Oracle 12c R1: SELECT val FROM mytable ORDER BY val DESC FETCH FIRST 5 ROWS ONLY; An example without FETCH that works also in earlier versions: SELECT * FROM ( SELECT val FROM mytable ORDER BY val DESC ) WHERE ROWNUM <= 5;
WITHOUT_ARRAY_WRAPPER option enables you to generate a single object instead of the array. Use this option if you know that you will return single row/object: SELECT top 3 object_id, name, type, principal_id FROM sys.objects WHERE object_id = 3 FOR JSON PATH, WITHOUT_ARRAY_WRAPPER Single obje...
WHERE clause filters only those rows that satisfy some condition: SELECT * FROM sys.objects WHERE type = 'IT'
HAVING clause removes groups that do not satisfy condition: SELECT type, count(*) as c FROM sys.objects GROUP BY type HAVING count(*) < 10 typecSQ3PK1U5
Exceptions are powerful, but a single overzealous except clause can take it all away in a single line. try: res = get_result() res = res[0] log('got result: %r' % res) except: if not res: res = '' print('got exception') This example demonstrates 3 symptoms of t...
int i; int n = 1000000; double area = 0; double h = 1.0 / n; #pragma omp parallel for shared(n, h) reduction(+:area) for (i = 1; i <= n; i++) { double x = h * (i - 0.5); area += (4.0 / (1.0 + x*x)); } pi = h * area; In this example, each threads execute a subset of the iteration...
h = 1.0 / n; #pragma omp parallel for private(x) shared(n, h) reduction(+:area) for (i = 1; i <= n; i++) { x = h * (i - 0.5); area += (4.0 / (1.0 + x*x)); } pi = h * area; In this example, each threads execute a subset of the iteration count. Each thread has its local private copy ...
In Elixir, one can create multiple implementations of a function with the same name, and specify rules which will be applied to the parameters of the function before calling the function in order to determine which implementation to run. These rules are marked by the keyword when, and they go betwe...
Let's say we have multiple data sources which include database, file, prompt and argumentList. Depending on chosen source we change our approach: def loadData(dataSource: Symbol): Try[String] = dataSource match { case 'database => loadDatabase() // Loading data from database case 'file =&g...
If you have an Ecto.Queryable, named Post, which has a title and an description. You can fetch the Post with title: "hello" and description : "world" by performing : MyRepo.get_by(Post, [title: "hello", description: "world"]) All of this is possible beca...
You can generate JSON object using standard SELECT query with FOR JSON clause and WITHOUT_ARRAY_WRAPPER option, and insert it into JSON text as a third parameter: declare @json nvarchar(4000) = N'{"Id":17,"Name":"WWI"}' set @json = JSON_MODIFY(@json, '$.table', ...
#include <omp.h> #include <stdio.h> int main (void) { int t = (0 == 0); // true value int f = (1 == 0); // false value #pragma omp parallel if (f) { printf ("FALSE: I am thread %d\n", omp_get_thread_num()); } #pragma omp parallel if (t) { printf (&quo...
01 fillertest. 03 fillertest-1 PIC 9(10) value 2222222222. 03 filler PIC X value '|'. 03 fillertest-2 PIC X(10) value all 'A'. 03 filler PIC 9(03) value 111. 03 filler PIC X value '.'. INITIALIZE fillertest INITIALIZE fillertest REPLACING NUM...

Page 2 of 3