This program uses the Windows API (WinAPI) to print "Hello World" into a message box.
To include a dependency (like Windows in this case), add the uses block including a comma-separated list of units ending with an semicolon.
program HelloWorld;
uses
Windows;
begin
MessageBox...
To document a function, it is often helpful to have an example script which uses your function. The publish function in Matlab can then be used to generate a help file with embedded pictures, code, links, etc. The syntax for documenting your code can be found here.
The Function
This function uses ...
Folds are (higher-order) functions used with sequences of elements. They collapse seq<'a> into 'b where 'b is any type (possibly still 'a). This is a bit abstract so lets get into concrete practical examples.
Calculating the sum of all numbers
In this example, 'a is an int. We have a list of...
let x = true
match x with
| true -> printfn "x is true"
yields a warning
C:\Program Files (x86)\Microsoft VS Code\Untitled-1(2,7): warning FS0025: Incomplete pattern matches on this expression. For example, the value 'false' may indicate a case not covered by the pattern(s).
...
Incorrect usage:
In the following snippet, the last match will never be used:
let x = 4
match x with
| 1 -> printfn "x is 1"
| _ -> printfn "x is anything that wasn't listed above"
| 4 -> printfn "x is 4"
prints
x is anything that wasn't listed abov...
Returns a string that represents the unqualified name of a variable, type, or member.
int counter = 10;
nameof(counter); // Returns "counter"
Client client = new Client();
nameof(client.Address.PostalCode)); // Returns "PostalCode"
The nameof operator was introduced in C# ...
compile built-in function can be used to precompile an expression to a code object; this code object can then be passed to eval. This will speed up the repeated executions of the evaluated code. The 3rd parameter to compile needs to be the string 'eval'.
>>> code = compile('a * b + c', '&l...
>>> variables = {'a': 6, 'b': 7}
>>> eval('a * b', globals=variables)
42
As a plus, with this the code cannot accidentally refer to the names defined outside:
>>> eval('variables')
{'a': 6, 'b': 7}
>>> eval('variables', globals=variables)
Traceback (most ...
The Application directive defines application-specific attributes. It is provided at the top of the global.aspx file.
The basic syntax of Application directive is:
<%@ Application Language="C#" %>
The attributes of the Application directive are:
AttributesDescriptionInheritsThe...
The Implement directive indicates that the web page, master page or user control page must implement the specified .Net framework interface.
The basic syntax for implements directive is:
<%@ Implements Interface="interface_name" %>
The Import directive imports a namespace into a web page, user control page of application. If the Import directive is specified in the global.asax file, then it is applied to the entire application. If it is in a page of user control page, then it is applied to that page or control.
The basic synt...
The MasterType directive assigns a class name to the Master property of a page, to make it strongly typed.
The basic syntax of MasterType directive is:
<%@ MasterType attribute="value"[attribute="value" ...] %>
The Page directive defines the attributes specific to the page file for the page parser and the compiler.
The basic syntax of Page directive is:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Trace="tr...
The OutputCache directive controls the output caching policies of a web page or a user control.
The basic syntax of OutputCache directive is:
<%@ OutputCache Duration="15" VaryByParam="None" %>
You can also use regular expressions to split a string. For example,
import re
data = re.split(r'\s+', 'James 94 Samantha 417 Scarlett 74')
print( data )
# Output: ['James', '94', 'Samantha', '417', 'Scarlett', '74']
You can get rid of manage.py and use the django-admin command instead. To do so, you will have to manually do what manage.py does:
Add your project path to your PYTHONPATH
Set the DJANGO_SETTINGS_MODULE
export PYTHONPATH="/home/me/path/to/your_project"
export DJANGO_SETTINGS_MODULE...
Using threading & queue:
from socket import socket, AF_INET, SOCK_STREAM
from threading import Thread
from queue import Queue
def echo_server(addr, nworkers):
print('Echo server running at', addr)
# Launch the client workers
q = Queue()
for n in range(nworkers):
...
Record syntax can be used with newtype with the restriction that there is exactly one constructor with exactly one field. The benefit here is the automatic creation of a function to unwrap the newtype. These fields are often named starting with run for monads, get for monoids, and un for other typ...
In a non-strict-mode scope, when a variable is assigned without being initialized with the var, const or the let keyword, it is automatically declared in the global scope:
a = 12;
console.log(a); // 12
In strict mode however, any access to an undeclared variable will throw a reference error:
&...