Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
This list is filtered with keywords : Language=[Rust]

Idiom #93 Pass a runnable procedure as parameter

Implement the procedure control which receives one parameter f, and runs f.

Idiom #8 Create a map (associative array)

Create a new map object x, and provide some (key, value) pairs as initial content.

Idiom #35 First-class function : compose

Implement a function compose (A -> C) with parameters f (A -> B) and g (B -> C), which returns the composition function g ∘ f

Idiom #59 Write to standard error stream

Print the message "x is negative" to standard error (stderr), with integer x value substitution (e.g. "-2 is negative").

Idiom #67 Binomial coefficient "n choose k"

Calculate binom(n, k) = n! / (k! * (n-k)!). Use an integer type able to handle huge numbers.

Idiom #76 Binary digits from an integer

Create the string s of integer x written in base 2.

E.g. 13 -> "1101"

Idiom #82 Count substring occurrences

Find how many times string s contains substring t.
Specify if overlapping occurrences are counted.

Idiom #105 Current executable name

Assign to the string s the name of the currently executing program (but not its full path).

Idiom #123 Assert condition

Verify that predicate isConsistent returns true, otherwise report assertion violation.
Explain if the assertion is executed even in production environment or not.

Idiom #169 String length

Assign to the integer n the number of characters of the string s.
Make sure that multibyte characters are properly handled.
n can be different from the number of bytes of s.

Idiom #3 Create a procedure

Like a function which doesn't return any value, thus has only side effects (e.g. Print to standard output)