Arguments Structures
arguments
make-arguments
arguments?
arguments-positional
arguments-keyword
apply/  arguments
arguments-merge
lambda/  arguments
define/  arguments
empty-arguments
keyword-hash?
7.1

Arguments Structures

Jack Firth <[email protected]>

This library defines arguments structures, values containing a set of positional and keyword argument values. Various utility procedures for constructing and manipulating these structures are provided.

Source code for this library is avaible on Github and is provided under the terms of the MIT License.

Returns all arguments given, in the form of an arguments structure. Accepts both positional and keyword arguments.

Example:
> (arguments 1 2 3 #:foo "bar")

(arguments 1 2 3 #:foo "bar")

procedure

(make-arguments positional keyword)  arguments?

  positional : list?
  keyword : keyword-hash?
Returns an arguments structure with positional and keyword as its arguments.

Example:
> (make-arguments '(1 2 3) (hash '#:foo "bar"))

(arguments 1 2 3 #:foo "bar")

value

arguments? : predicate/c

procedure

(arguments-positional arguments)  list?

  arguments : arguments?

procedure

(arguments-keyword arguments)  keyword-hash?

  arguments : arguments?
Predicate and accessors for arguments structures.

procedure

(apply/arguments f args)  any

  f : procedure?
  args : arguments?
Calls f with args and returns whatever values are returned by f.

Example:
> (apply/arguments sort
                   (arguments '("fooooo" "bar" "bazz") <
                              #:key string-length))

'("bar" "bazz" "fooooo")

Added in version 1.1 of package arguments.
Changed in version 1.2.1: caused nondeterministic contract exceptions

procedure

(arguments-merge args ...)  arguments?

  args : arguments?
Returns a combination of the given args. The returned arguments structure contains all the positional and keyword arguments of each args structure. Positional arguments are ordered left to right, and if two args structures have duplicate keyword arguments the rightmost args takes precedence. When called with no arguments, returns empty-arguments.

Examples:
> (arguments-merge (arguments 1 #:foo 2 #:bar 3)
                   (arguments 'a 'b #:foo 'c))

(arguments 1 'a 'b #:bar 3 #:foo 'c)

> (arguments-merge)

(arguments)

Added in version 1.3 of package arguments.

syntax

(lambda/arguments args-id body ...+)

Constructs an anonymous function that accepts any number of arguments, collects them into an arguments structure, and binds that structure to args-id in the body forms.

Examples:
> (define pos-sum
    (lambda/arguments args
      (apply + (arguments-positional args))))
> (pos-sum 1 2 3)

6

> (pos-sum 1 2 3 #:foo 'bar)

6

Added in version 1.2 of package arguments.

syntax

(define/arguments (id args-id) body ...+)

Defines id as a function that accepts any number of arguments, collects them into an arguments structure, and binds that structure to args-id in the body forms.

Examples:
> (define/arguments (keywords-product args)
    (for/product ([(k v) (in-hash (arguments-keyword args))])
      v))
> (keywords-product #:foo 2 #:bar 3)

6

> (keywords-product 'ignored #:baz 6 #:blah 4)

24

Added in version 1.2 of package arguments.

The empty arguments structure. Equivalent to (arguments).

A flat contract that recognizes immutable hashes whose keys are keywords. Equivalent to (hash/c keyword? any/c #:flat? #t #:immutable #t). Used for the keyword arguments of an arguments structure.

Examples:
> (keyword-hash? (hash '#:foo "bar"))

#t

> (keyword-hash? (make-hash '((#:foo . "bar"))))

#f

> (keyword-hash? (hash 'foo "bar"))

#f