### Generate Sequence of Numbers (Iota) (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `iota` function generates a list of n numbers. It starts from a specified `start` value (defaulting to 0) and increments each subsequent number by a `step` value (defaulting to 1). Numeric contagion from `step` is applied. ```common-lisp (iota 4) ``` ```common-lisp (iota 3 :start 1 :step 1.0) ``` ```common-lisp (iota 3 :start -1 :step -1/2) ``` -------------------------------- ### Check Sequence Start: starts-with (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `starts-with` function returns true if a `sequence` begins with a specific `object`. It returns `nil` if the sequence is not a sequence or is empty. The optional `test` and `key` arguments allow for custom comparison logic. ```common-lisp (starts-with 'a '(a b c)) ;=> T (starts-with 1 '(2 3 4)) ;=> NIL ``` -------------------------------- ### Check Subsequence Prefix: starts-with-subseq (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria This function tests if a `sequence` starts with another sequence (`prefix`). It supports custom `test` functions. If `return-suffix` is `t`, it returns the remaining part of the sequence as a second value. It handles various sequence types and potential errors. ```common-lisp (starts-with-subseq '(1 2) '(1 2 3 4)) ;=> T (starts-with-subseq '(1 2) '(1 2 3 4) :return-suffix t) ;=> T, (3 4) (starts-with-subseq "ab" "abcde") ;=> T ``` -------------------------------- ### Apply Function to Sequence of Numbers (Map-Iota) (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `map-iota` function applies a given `function` to a sequence of n numbers, generated similarly to `iota` (with optional `start` and `step`). It returns n. The function is called for each number in the sequence. ```common-lisp (map-iota #'print 3 :start 1 :step 1.0) ``` -------------------------------- ### Map Over Combinations: map-combinations (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `map-combinations` function applies a `function` to all possible combinations of elements from a `sequence`. It supports specifying `start`, `end`, and `length` for the combinations, and an optional `copy` argument. This is useful for generating and processing combinations. ```common-lisp (map-combinations (lambda (combo) (print combo)) '(a b c) :length 2) ; Output: ; (A B) ; (A C) ; (B C) ;=> NIL ``` -------------------------------- ### Randomize and Select Elements: shuffle and random-elt (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `shuffle` function returns a random permutation of a sequence, potentially modifying the original. `random-elt` returns a random element from a sequence. Both functions support optional `start` and `end` arguments to specify a sub-sequence. Errors are signaled if the input is not a proper sequence or if bounds are invalid. ```common-lisp (shuffle '(1 2 3 4 5)) ; Returns a random permutation, e.g., (3 1 5 2 4) (random-elt "abcde") ; Returns a random character, e.g., #\c ``` -------------------------------- ### Destructuring Case Macro in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria The `destructuring-case` macro combines `case` with `destructuring-bind`. It allows clauses to destructure the `cdr` of a key form based on matching the `car`. It supports various destructuring patterns and provides examples for different clause types. ```common-lisp (defun dcase (x) (destructuring-case x ((:foo a b) (format nil "foo: ~S, ~S" a b)) ((:bar &key a b) (format nil "bar: ~S, ~S" a b)) (((:alt1 :alt2) a) (format nil "alt: ~S" a)) ((t &rest rest) (format nil "unknown: ~S" rest)))) ``` ```common-lisp (dcase (list :foo 1 2)) ; => "foo: 1, 2" (dcase (list :bar :a 1 :b 2)) ; => "bar: 1, 2" (dcase (list :alt1 1)) ; => "alt: 1" (dcase (list :alt2 2)) ; => "alt: 2" (dcase (list :quux 1 2 3)) ; => "unknown: 1, 2, 3" ``` ```common-lisp (defun decase (x) (destructuring-case x ((:foo a b) (format nil "foo: ~S, ~S" a b)) ((:bar &key a b) (format nil "bar: ~S, ~S" a b)) (((:alt1 :alt2) a) (format nil "alt: ~S" a)))) ``` ```common-lisp (decase (list :foo 1 2)) ; => "foo: 1, 2" (decase (list :bar :a 1 :b 2)) ; => "bar: 1, 2" (decase (list :alt1 1)) ; => "alt: 1" (decase (list :alt2 2)) ; => "alt: 2" (decase (list :quux 1 2 3)) ; =| error ``` -------------------------------- ### Combinatorial and Permutation Functions Source: https://alexandria.common-lisp.dev/draft/alexandria Functions to calculate binomial coefficients and the number of permutations. ```APIDOC ## BINOMIAL-COEFFICIENT ### Description Binomial coefficient of `n` and `k`, also expressed as `n` choose `k`. This is the number of `k` element combinations given `n` choises. `n` must be equal to or greater then `k`. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (binomial-coefficient 5 2) ; Returns 10 ``` ### Response #### Success Response (200) - **result** (integer) - The binomial coefficient of n and k. #### Response Example ```json { "result": 10 } ``` ## COUNT-PERMUTATIONS ### Description Number of `k` element permutations for a sequence of `n` objects. `k` defaults to `n`. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (count-permutations 5 2) ; Returns 20 (count-permutations 4) ; Returns 24 (4!) ``` ### Response #### Success Response (200) - **result** (integer) - The number of k-element permutations for n objects. #### Response Example ```json { "result": 20 } ``` ``` -------------------------------- ### Get Proper List Length - Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Returns the length of a proper list. Signals an error if the input is not a proper list. This function is crucial for list size calculations. ```common-lisp (proper-list-length '(1 2 3)) ``` -------------------------------- ### Statistical Functions Source: https://alexandria.common-lisp.dev/draft/alexandria Functions for calculating mean, median, variance, and standard deviation of a sample. ```APIDOC ## MEAN ### Description Returns the mean of `sample`. `sample` must be a sequence of numbers. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (mean '(1 2 3 4 5)) ; Returns 3.0 ``` ### Response #### Success Response (200) - **result** (number) - The mean of the sample. #### Response Example ```json { "result": 3.0 } ``` ## MEDIAN ### Description Returns median of `sample`. `sample` must be a sequence of real numbers. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (median '(1 2 3 4 5)) ; Returns 3 (median '(1 2 3 4)) ; Returns 2.5 ``` ### Response #### Success Response (200) - **result** (number) - The median of the sample. #### Response Example ```json { "result": 3 } ``` ## VARIANCE ### Description Variance of `sample`. Returns the biased variance if `biased` is true (the default), and the unbiased estimator of variance if `biased` is false. `sample` must be a sequence of numbers. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters - **biased** (boolean) - Optional. If true, returns biased variance. Defaults to true. #### Request Body None ### Request Example ``` (variance '(1 2 3 4 5)) ; Returns 2.0 (biased) (variance '(1 2 3 4 5) :biased nil) ; Returns 2.5 (unbiased) ``` ### Response #### Success Response (200) - **result** (number) - The variance of the sample. #### Response Example ```json { "result": 2.0 } ``` ## STANDARD-DEVIATION ### Description Standard deviation of `sample`. Returns the biased standard deviation if `biased` is true (the default), and the square root of the unbiased estimator for variance if `biased` is false (which is not the same as the unbiased estimator for standard deviation). `sample` must be a sequence of numbers. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters - **biased** (boolean) - Optional. If true, returns biased standard deviation. Defaults to true. #### Request Body None ### Request Example ``` (standard-deviation '(1 2 3 4 5)) ; Returns 1.4142135623730951 (biased) (standard-deviation '(1 2 3 4 5) :biased nil) ; Returns 1.5811388300841898 (sqrt of unbiased variance) ``` ### Response #### Success Response (200) - **result** (number) - The standard deviation of the sample. #### Response Example ```json { "result": 1.4142135623730951 } ``` ``` -------------------------------- ### Get Last Element of List - Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Returns the last element of a proper list. Signals a type-error if the input is not a proper list. This function is essential for accessing the tail of a list. ```common-lisp (lastcar '(1 2 3)) ``` -------------------------------- ### Sequence Generation Source: https://alexandria.common-lisp.dev/draft/alexandria Functions to generate sequences of numbers. ```APIDOC ## IOTA ### Description Return a list of n numbers, starting from `start` (with numeric contagion from `step` applied), each consequtive number being the sum of the previous one and `step`. `start` defaults to `0` and `step` to `1`. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (iota 4) ; Returns (0 1 2 3) (iota 3 :start 1 :step 1.0) ; Returns (1.0 2.0 3.0) (iota 3 :start -1 :step -1/2) ; Returns (-1 -3/2 -2) ``` ### Response #### Success Response (200) - **result** (list) - A list of n numbers. #### Response Example ```json { "result": [0, 1, 2, 3] } ``` ## MAP-IOTA ### Description Calls `function` with `n` numbers, starting from `start` (with numeric contagion from `step` applied), each consequtive number being the sum of the previous one and `step`. `start` defaults to `0` and `step` to `1`. Returns `n`. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (map-iota #'print 3 :start 1 :step 1.0) ;;; Output: ;;; 1.0 ;;; 2.0 ;;; 3.0 ;;; Returns 3 ``` ### Response #### Success Response (200) - **result** (integer) - The value of n. #### Response Example ```json { "result": 3 } ``` ``` -------------------------------- ### Clamping and Interpolation Source: https://alexandria.common-lisp.dev/draft/alexandria Functions for clamping a number within a range and linear interpolation. ```APIDOC ## CLAMP ### Description Clamps the `number` into [min, max] range. Returns `min` if `number` is lesser then `min` and `max` if `number` is greater then `max`, otherwise returns `number`. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (clamp 5 0 10) ; Returns 5 (clamp -2 0 10) ; Returns 0 (clamp 15 0 10) ; Returns 10 ``` ### Response #### Success Response (200) - **result** (number) - The clamped number. #### Response Example ```json { "result": 5 } ``` ## LERP ### Description Returns the result of linear interpolation between A and `b`, using the interpolation coefficient `v`. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (lerp 0.5 10 20) ; Returns 15.0 (lerp 0 10 20) ; Returns 10 (lerp 1 10 20) ; Returns 20 ``` ### Response #### Success Response (200) - **result** (number) - The interpolated value. #### Response Example ```json { "result": 15.0 } ``` ``` -------------------------------- ### read-file-into-string Source: https://alexandria.common-lisp.dev/draft/alexandria Reads the entire content of a file and returns it as a fresh string. ```APIDOC ## CALL `read-file-into-string` ### Description Return the contents of the file denoted by `pathname` as a fresh string. The `external-format` parameter will be passed directly to `with-open-file` unless it’s `nil`, which means the system default. ### Method N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **string** (string) - The content of the file as a string. #### Response Example ``` "file content" ``` ``` -------------------------------- ### When-Let* Macro for Sequential Conditional Binding in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria The `when-let*` macro creates bindings sequentially, allowing subsequent bindings to refer to previously bound variables. Execution stops if any `initial-form` evaluates to `nil`. If all forms evaluate to true, the `body` is executed. ```common-lisp (when-let* ((config (load-config)) (user (get-user config)) (session (start-session user))) (log-login user session) (display-dashboard session)) ``` ```common-lisp (when-let* (val1 (get-val1)) (val2 (process-val1 val1)) (val3 (validate-val2 val2))) (do-something val1 val2 val3)) ``` -------------------------------- ### map-permutations Source: https://alexandria.common-lisp.dev/draft/alexandria Calls a function with each permutation of a specified length constructible from a subsequence. ```APIDOC ## CALL `map-permutations` ### Description Calls function with each permutation of `length` constructable from the subsequence of `sequence` delimited by `start` and `end`. `start` defaults to `0`, `end` to length of the sequence, and `length` to the length of the delimited subsequence. ### Method N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) N/A (Function returns values based on the provided function's execution) #### Response Example None ``` -------------------------------- ### Function Argument Manipulation: curry, rcurry Source: https://alexandria.common-lisp.dev/draft/alexandria `curry` returns a function with pre-filled arguments at the beginning. `rcurry` pre-fills arguments at the end. ```APIDOC ## Functions: curry, rcurry ### Description `curry` returns a function that applies pre-supplied `arguments` and the arguments it is called with to the target `function`. `rcurry` is similar but applies the pre-supplied `arguments` after the arguments it is called with. ### Method Function ### Endpoint N/A (Lisp Functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp ;; curry example (funcall (curry #'+ 1 2) 3 4) ;=> 10 (1+2+3+4) ;; rcurry example (funcall (rcurry #'+ 1 2) 3 4) ;=> 10 (3+4+1+2) ``` ### Response #### Success Response (200) Returns a new function with partially applied arguments. #### Response Example ```lisp ;; For curry: 10 ;; For rcurry: 10 ``` ``` -------------------------------- ### Factorial and Subfactorial Functions Source: https://alexandria.common-lisp.dev/draft/alexandria Functions to calculate the factorial and subfactorial of a non-negative integer. ```APIDOC ## FACTORIAL ### Description Factorial of non-negative integer `n`. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (factorial 5) ; Returns 120 ``` ### Response #### Success Response (200) - **result** (integer) - The factorial of n. #### Response Example ```json { "result": 120 } ``` ## SUBFACTORIAL ### Description Subfactorial of the non-negative integer `n`. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (subfactorial 4) ; Returns 9 ``` ### Response #### Success Response (200) - **result** (integer) - The subfactorial of n. #### Response Example ```json { "result": 9 } ``` ``` -------------------------------- ### Threading Macros: line-up-first, line-up-last Source: https://alexandria.common-lisp.dev/draft/alexandria `line-up-first` threads forms as the first argument to their successor. `line-up-last` threads forms as the last argument. ```APIDOC ## Macros: alexandria-2:line-up-first, alexandria-2:line-up-last ### Description `alexandria-2:line-up-first` lines up `forms` elements as the first argument of their successor. `alexandria-2:line-up-last` lines up `forms` elements as the last argument of their successor. ### Method Macro ### Endpoint N/A (Lisp Macros) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp ;; line-up-first example (alexandria-2:line-up-first 5 (+ 20) / (+ 40)) ;; Equivalent to: (+ (/ (+ 5 20)) 40) ;; line-up-last example (alexandria-2:line-up-last 5 (+ 20) / (+ 40)) ;; Equivalent to: (+ 40 (/ (+ 20 5))) ``` ### Response #### Success Response (200) Returns the result of the threaded form evaluation. #### Response Example ```lisp ;; For line-up-first: (+ (/ (+ 5 20)) 40) ;; For line-up-last: (+ 40 (/ (+ 20 5))) ``` ``` -------------------------------- ### read-stream-content-into-string Source: https://alexandria.common-lisp.dev/draft/alexandria Reads the entire content of a stream and returns it as a fresh string. ```APIDOC ## CALL `read-stream-content-into-string` ### Description Return the "content" of `stream` as a fresh string. ### Method N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **string** (string) - The content of the stream as a string. #### Response Example ``` "stream content" ``` ``` -------------------------------- ### Function Composition Functions: compose, multiple-value-compose Source: https://alexandria.common-lisp.dev/draft/alexandria `compose` creates a function by applying arguments to functions sequentially from right to left. `multiple-value-compose` is similar but passes all return values. ```APIDOC ## Functions: compose, multiple-value-compose ### Description `compose` returns a function composed of other functions that applies its arguments to each in turn, starting from the rightmost function. `multiple-value-compose` is similar but passes all return values from one function to the next. ### Method Function ### Endpoint N/A (Lisp Functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp ;; compose example (funcall (compose #'1+ #'*) 2 3) ;=> 7 ( (2*3) + 1 ) ;; multiple-value-compose example (defun foo (x) (values x (+ x 1))) (defun bar (x y) (+ x y)) (funcall (multiple-value-compose #'bar #'foo) 5) ;=> 11 (bar (foo 5) => bar 5 6 => 5+6) ``` ### Response #### Success Response (200) Returns a new function that represents the composition of the input functions. #### Response Example ```lisp ;; For compose: 7 ;; For multiple-value-compose: 11 ``` ``` -------------------------------- ### Format and Create Symbol - Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria The `format-symbol` function constructs a symbol name by formatting arguments and then interns the resulting string in a specified package. It handles different package specifications, including returning uninterned symbols. -------------------------------- ### Exclusive OR Macro: xor Source: https://alexandria.common-lisp.dev/draft/alexandria Evaluates arguments sequentially and handles truth values to return specific primary and secondary values. ```APIDOC ## Macro: xor ### Description Evaluates its arguments one at a time, from left to right. If more than one argument evaluates to a true value, no further arguments are evaluated, and `nil` is returned as both primary and secondary value. If exactly one argument evaluates to true, its value is returned as the primary value after all arguments have been evaluated, and `t` is returned as the secondary value. If no arguments evaluate to true, `nil` is returned as primary, and `t` as secondary value. ### Method Macro ### Endpoint N/A (Lisp Macro) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (xor (> 5 3) (> 2 4)) ;; Returns: 5, T (xor (> 5 3) (> 2 1)) ;; Returns: NIL, NIL (xor (> 5 6) (> 2 4)) ;; Returns: NIL, T ``` ### Response #### Success Response (200) Returns primary and secondary values based on the truthiness of evaluated arguments. #### Response Example ```lisp 5, T ;; (Primary value, Secondary value) ``` ``` -------------------------------- ### Currying Functions in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Provides functions for currying, which partially apply arguments to a function. `curry` applies initial arguments first, then subsequent arguments. `rcurry` applies subsequent arguments first, then initial arguments. ```common-lisp (defun curry (function &rest arguments)) ;; Returns a function that applies `arguments` and the arguments it is called with to `function`. (defun rcurry (function &rest arguments)) ;; Returns a function that applies the arguments it is called with and `arguments` to `function`. ``` -------------------------------- ### Random Number Generation Source: https://alexandria.common-lisp.dev/draft/alexandria Function to generate Gaussian random double floats. ```APIDOC ## GAUSSIAN-RANDOM ### Description Returns two gaussian random double floats as the primary and secondary value, optionally constrained by `min` and `max`. Gaussian random numbers form a standard normal distribution around `0.0d0`. Sufficiently positive `min` or negative `max` will cause the algorithm used to take a very long time. If `min` is positive it should be close to zero, and similarly if `max` is negative it should be close to zero. ### Method FUNCTION ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (gaussian-random) ; Returns two gaussian random doubles (gaussian-random 0.0 1.0) ; Returns two gaussian random doubles between 0.0 and 1.0 ``` ### Response #### Success Response (200) - **primary_value** (double-float) - The primary Gaussian random number. - **secondary_value** (double-float) - The secondary Gaussian random number. #### Response Example ```json { "primary_value": 0.54321, "secondary_value": -0.12345 } ``` ``` -------------------------------- ### Control Flow Macros: switch, cswitch, eswitch Source: https://alexandria.common-lisp.dev/draft/alexandria These macros provide conditional evaluation based on matching clauses. `switch` returns the first matching clause's values. `cswitch` is similar but signals a continuable error if no match. `eswitch` signals a non-continuable error if no match. ```APIDOC ## Macros: switch, cswitch, eswitch ### Description Provides conditional evaluation based on matching clauses. `switch` returns the values of the first matching clause. `cswitch` signals a continuable error if no match is found. `eswitch` signals a non-continuable error if no match is found. ### Method Macro ### Endpoint N/A (Lisp Macros) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (switch (get-color) (:red "Stop") (:yellow "Caution") (:green "Go")) (cswitch (get-status) (:ok "Success") (otherwise "Unknown Status")) (eswitch (get-value) (1 10) (2 20)) ``` ### Response #### Success Response (200) Returns the values of the first matching clause, or the values of `t` or `otherwise` if no keys match for `switch`. For `cswitch` and `eswitch`, an error is signaled if no match is found. #### Response Example ```lisp ;; For switch "Go" ;; For cswitch (if no match) ;; Error: Unknown Status ;; For eswitch (if no match) ;; Error: Unhandled case: NIL ``` ``` -------------------------------- ### read-file-into-byte-vector Source: https://alexandria.common-lisp.dev/draft/alexandria Reads the entire content of a file and returns it as a fresh byte vector. ```APIDOC ## CALL `read-file-into-byte-vector` ### Description Read `pathname` into a freshly allocated (unsigned-byte 8) vector. ### Method N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **byte-vector** (vector) - The content of the file as a byte vector. #### Response Example ``` #.(make-array 5 :element-type '(unsigned-byte 8) :initial-contents '(72 101 108 108 111)) ``` ``` -------------------------------- ### read-stream-content-into-byte-vector Source: https://alexandria.common-lisp.dev/draft/alexandria Reads the entire content of a stream and returns it as a fresh byte vector. ```APIDOC ## CALL `read-stream-content-into-byte-vector` ### Description Return "content" of `stream` as freshly allocated (unsigned-byte 8) vector. ### Method N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **byte-vector** (vector) - The content of the stream as a byte vector. #### Response Example ``` #.(make-array 5 :element-type '(unsigned-byte 8) :initial-contents '(72 101 108 108 111)) ``` ``` -------------------------------- ### Function Composition and Argument Handling in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Offers functions for composing functions and handling arguments. `compose` creates a function by applying arguments sequentially from right to left. `multiple-value-compose` is similar but passes all return values. `ensure-function` returns a function designator as a function. ```common-lisp (defun compose (function &rest more-functions)) ;; Returns a function composed of `function` and `more-functions` that applies its arguments to to each in turn, starting from the rightmost of `more-functions`, and then calling the next one with the primary value of the last. (defun ensure-function (function-designator)) ;; Returns the function designated by `function-designator:` if `function-designator` is a function, it is returned, otherwise it must be a function name and its `fdefinition` is returned. (defun multiple-value-compose (function &rest more-functions)) ;; Returns a function composed of `function` and `more-functions` that applies its arguments to each in turn, starting from the rightmost of `more-functions`, and then calling the next one with all the return values of the last. ``` -------------------------------- ### If-Let Macro for Conditional Binding in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria The `if-let` macro provides a concise way to create bindings and conditionally execute forms. It evaluates initial forms, binds variables, and executes `then-form` if all bindings are true, otherwise `else-form`. `else-form` defaults to `nil`. ```common-lisp (if-let ((a (get-value)) (b (process a))) (format t "Success: ~S ~S" a b) (format t "Failure.")) ``` ```common-lisp (if-let (value (find-item list)) (handle-item value) (format t "Item not found.")) ``` -------------------------------- ### Convert Property List to Association List - Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Converts a property list (plist) into an association list (alist), preserving the order of keys and values. This facilitates working with different data representations. ```common-lisp (plist-alist '(:a 1 :b 2)) ``` -------------------------------- ### Conditional Execution with Switch Macros in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Provides macros for conditional execution based on matching clauses. `switch` returns values of the first matching clause or a default. `cswitch` signals a continuable error if no match, while `eswitch` signals a non-continuable error. ```common-lisp (defmacro switch (object &key test key) &body clauses) ;; Evaluates first matching clause, returning its values, or evaluates and returns the values of `t` or `otherwise` if no keys match. (defmacro cswitch (object &key test key) &body clauses) ;; Like `switch`, but signals a continuable error if no key matches. (defmacro eswitch (object &key test key) &body clauses) ;; Like `switch`, but signals an error if no key matches. ``` -------------------------------- ### Convert Association List to Property List - Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Converts an association list (alist) into a property list (plist), preserving the order of keys and values. This is useful for data format transformations. ```common-lisp (alist-plist '((:a 1) (:b 2))) ``` -------------------------------- ### When-Let Macro for Conditional Execution in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria The `when-let` macro creates bindings and conditionally executes forms. If all bound variables evaluate to true values, the specified `forms` are executed as an implicit `progn`. Otherwise, the forms are skipped. ```common-lisp (when-let ((user (find-user session)) (permissions (get-permissions user))) (log-activity user "Accessed resource") (grant-access permissions)) ``` ```common-lisp (when-let (data (read-data-source)) (process-data data)) ``` -------------------------------- ### Calculate Binomial Coefficient (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `binomial-coefficient` function calculates 'n choose k', representing the number of combinations of k items from a set of n items. It requires that n be greater than or equal to k. ```common-lisp (binomial-coefficient 5 2) ``` -------------------------------- ### Modify-macros for max and min Source: https://alexandria.common-lisp.dev/draft/alexandria These macros modify a place to hold the maximum or minimum of its current value and provided numbers. ```APIDOC ## MAXF ### Description Modify-macro for `max`. Sets place designated by the first argument to the maximum of its original value and `numbers`. ### Method MACRO ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (let ((x 5)) (maxf x 10 2) ; x becomes 10 (maxf x 3 7) ; x remains 10 ) ``` ### Response #### Success Response (200) N/A (Macro operation) #### Response Example N/A ## MINF ### Description Modify-macro for `min`. Sets place designated by the first argument to the minimum of its original value and `numbers`. ### Method MACRO ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` (let ((x 5)) (minf x 2 8) ; x becomes 2 (minf x 7 9) ; x remains 2 ) ``` ### Response #### Success Response (200) N/A (Macro operation) #### Response Example N/A ``` -------------------------------- ### Random Selection and Logical Operations in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Includes macros for selecting elements and performing logical operations. `whichever` randomly evaluates one of its arguments. `xor` evaluates arguments sequentially, returning `nil` if multiple are true, the single true value if one is true, or `nil` if none are true. ```common-lisp (defmacro whichever &rest possibilities) ;; Evaluates exactly one of `possibilities`, chosen at random. (defmacro xor &rest datums) ;; Evaluates its arguments one at a time, from left to right. If more than one argument evaluates to a true value no further `datums` are evaluated, and `nil` is returned as both primary and secondary value. If exactly one argument evaluates to true, its value is returned as the primary value after all the arguments have been evaluated, and `t` is returned as the secondary value. If no arguments evaluate to true `nil` is returned as primary, and `t` as secondary value. ``` -------------------------------- ### Random Choice Macro: whichever Source: https://alexandria.common-lisp.dev/draft/alexandria Evaluates exactly one of the provided possibilities, chosen at random. ```APIDOC ## Macro: whichever ### Description Evaluates exactly one of the provided `possibilities`, chosen at random. ### Method Macro ### Endpoint N/A (Lisp Macro) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (whichever (print "Option 1") (print "Option 2") (print "Option 3")) ``` ### Response #### Success Response (200) Returns the primary value of the randomly chosen possibility. #### Response Example ```lisp "Option 2" ;; (Output depends on random selection) ``` ``` -------------------------------- ### Argument Threading Macros in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Introduces macros for threading arguments through a sequence of forms. `line-up-first` inserts forms as the first argument of their successor. `line-up-last` inserts forms as the last argument of their successor. These macros simplify nested function calls. ```common-lisp (defmacro alexandria-2:line-up-first (&rest forms)) ;; Lines up `forms` elements as the first argument of their successor. Example: ;; (line-up-first ;; 5 ;; (+ 20) ;; / ;; (+ 40)) ;; is equivalent to: ;; (+ (/ (+ 5 20)) 40) ;; Note how the single ’/ got converted into a list before threading. (defmacro alexandria-2:line-up-last (&rest forms)) ;; Lines up `forms` elements as the last argument of their successor. Example: ;; (line-up-last ;; 5 ;; (+ 20) ;; / ;; (+ 40)) ;; is equivalent to: ;; (+ 40 (/ (+ 20 5))) ;; Note how the single ’/ got converted into a list before threading. ``` -------------------------------- ### Function Conversion: ensure-function Source: https://alexandria.common-lisp.dev/draft/alexandria Returns the function designated by `function-designator`. If it's already a function, it's returned directly; otherwise, it's expected to be a function name whose `fdefinition` is returned. ```APIDOC ## Function: ensure-function ### Description Returns the function designated by `function-designator`. If `function-designator` is a function, it is returned. Otherwise, it must be a function name and its `fdefinition` is returned. ### Method Function ### Endpoint N/A (Lisp Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (ensure-function #'list) ;=> # (ensure-function 'list) ;=> # ``` ### Response #### Success Response (200) The function designated by `function-designator`. #### Response Example ```lisp # ``` ``` -------------------------------- ### Clamp a Number to a Range (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `clamp` function restricts a given number to a specified range [min, max]. If the number is less than min, it returns min; if it's greater than max, it returns max; otherwise, it returns the number itself. ```common-lisp (clamp 10 0 5) ``` ```common-lisp (clamp 3 0 5) ``` ```common-lisp (clamp -2 0 5) ``` -------------------------------- ### Create Circular List by Length - Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Creates a circular list of a specified length, initializing each element with a given value. This is useful for pre-allocating circular structures. ```common-lisp (make-circular-list 5 :initial-element 0) ``` -------------------------------- ### Calculate Mean of a Sample (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `mean` function computes the arithmetic mean (average) of a sequence of numbers. The input `sample` must be a sequence containing numerical values. ```common-lisp (mean '(1 2 3 4 5)) ``` -------------------------------- ### Calculate Median of a Sample (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `median` function finds the median value of a sequence of real numbers. For an odd number of elements, it's the middle element; for an even number, it's typically the average of the two middle elements. ```common-lisp (median '(1 2 3 4 5)) ``` ```common-lisp (median '(1 2 3 4)) ``` -------------------------------- ### Predicate Combination Functions: disjoin, conjoin Source: https://alexandria.common-lisp.dev/draft/alexandria `disjoin` returns the first true value from a sequence of predicates. `conjoin` returns `nil` if any predicate is false, otherwise returns the last predicate's primary value. ```APIDOC ## Functions: disjoin, conjoin ### Description `disjoin` returns a function that applies predicates in turn and returns the primary value of the first predicate that returns true. `conjoin` returns a function that applies predicates in turn and returns `nil` if any predicate returns false; otherwise, it returns the primary value of the last predicate. ### Method Function ### Endpoint N/A (Lisp Functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp ;; disjoin example (funcall (disjoin #'evenp #'zerop) 4) ;=> 4 (funcall (disjoin #'evenp #'zerop) 3) ;=> NIL ;; conjoin example (funcall (conjoin #'evenp #'zerop) 4) ;=> NIL (funcall (conjoin #'evenp #'zerop) 0) ;=> 0 ``` ### Response #### Success Response (200) Returns a new function that combines the behavior of the input predicates. #### Response Example ```lisp ;; For disjoin with 4: returns 4 ;; For disjoin with 3: returns NIL ;; For conjoin with 4: returns NIL ;; For conjoin with 0: returns 0 ``` ``` -------------------------------- ### Access First and Last Elements: first-elt, last-elt, and their setters (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria These functions provide access to the first and last elements of a sequence. `first-elt` and `last-elt` retrieve the respective elements. Their `setf` counterparts allow modification of these elements. Errors are signaled for non-sequences, empty sequences, or invalid element types. ```common-lisp (first-elt '(a b c)) ;=> A (last-elt "hello") ;=> #\o (let ((lst '(1 2 3))) (setf (first-elt lst) 10) lst) ;=> (10 2 3) ``` -------------------------------- ### Predicate Composition Functions in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Provides functions for composing predicates. `disjoin` returns a function that applies predicates until one returns true, returning its value. `conjoin` returns a function that applies predicates, returning `nil` if any is false, otherwise returning the last predicate's value. ```common-lisp (defun disjoin (predicate &rest more-predicates)) ;; Returns a function that applies each of `predicate` and `more-predicate` functions in turn to its arguments, returning the primary value of the first predicate that returns true, without calling the remaining predicates. If none of the predicates returns true, `nil` is returned. (defun conjoin (predicate &rest more-predicates)) ;; Returns a function that applies each of `predicate` and `more-predicate` functions in turn to its arguments, returning `nil` if any of the predicates returns false, without calling the remaining predicates. If none of the predicates returns false, returns the primary value of the last predicate. ``` -------------------------------- ### Calculate Factorial (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `factorial` function computes the factorial of a non-negative integer n. The factorial of n is the product of all positive integers less than or equal to n. ```common-lisp (factorial 5) ``` -------------------------------- ### parse-ordinary-lambda-list Function for Parsing Lambda Lists in Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria The `parse-ordinary-lambda-list` function parses an ordinary lambda list and returns multiple values representing its components. These include required parameters, optional parameter specifications, rest parameter name, keyword parameter specifications, `&allow-other-keys` presence, `&aux` parameter specifications, and the existence of `&key`. ```common-lisp (defun parse-ordinary-lambda-list (lambda-list &key normalize allow-specializers normalize-optional normalize-keyword normalize-auxilary) "Parses an ordinary lambda-list, returning as multiple values: `1`. Required parameters. `2`. Optional parameter specifications, normalized into form: ``` (name init suppliedp) ``` `3`. Name of the rest parameter, or `nil`. `4`. Keyword parameter specifications, normalized into form: ``` ((keyword-name name) init suppliedp) ``` `5`. Boolean indicating `&allow-other-keys` presence. `6`. `&aux` parameter specifications, normalized into form ``` (name init). ``` `7`. Existence of `&key` in the lambda-list. Signals a `program-error` is the lambda-list is malformed. " ) ``` -------------------------------- ### Map Product of Lists - Common Lisp Source: https://alexandria.common-lisp.dev/draft/alexandria Applies a function to combinations of elements from multiple lists, returning a list of results. This computes the Cartesian product of the input lists. ```common-lisp (map-product 'list '(1 2) '(3 4) '(5 6)) ``` -------------------------------- ### Copy Sequence: copy-sequence (Common Lisp) Source: https://alexandria.common-lisp.dev/draft/alexandria The `copy-sequence` function creates and returns a new sequence of a specified `type` that contains the same elements as the input `sequence`. This is useful for creating independent copies of sequences. ```common-lisp (copy-sequence 'list '(1 2 3)) ;=> (1 2 3) (copy-sequence 'vector #(a b c)) ;=> #(A B C) ```