Skip to content

Commit

Permalink
reprovide call from mischief/function
Browse files Browse the repository at this point in the history
  • Loading branch information
countvajhula committed Oct 31, 2020
1 parent 103df9d commit d00e54a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions function.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
app
gen:application-scheme
application-scheme/c
call
(contract-out
[application-scheme? (predicate/c)]
[unthunk (binary-variadic-function/c procedure? any/c procedure?)]
Expand Down Expand Up @@ -122,6 +123,14 @@
[negate (function/c procedure? function?)]
[!! (function/c procedure? function?)]))

;; from mischief/function - reproviding it via require+provide runs aground
;; of some "name is protected" error while building docs, not sure why;
;; so including the implementation directly here for now
(define call
(make-keyword-procedure
(lambda (ks vs f . xs)
(keyword-apply f ks vs xs))))

(define (unthunk f . args)
(f:thunk*
(apply f args)))
Expand Down
19 changes: 19 additions & 0 deletions scribblings/function.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
(only-in racket/generator sequence->generator)
(prefix-in b: racket/function)
arguments
(only-in mischief/function (call m:call))
(prefix-in f: data/functor)]]

@(define eval-for-docs
Expand Down Expand Up @@ -427,6 +428,24 @@ This module provides general-purpose utilities to support programming in the @hy
]
}

@deftogether[(
@defproc[(call [g procedure?]
[v any/c]
...)
procedure?]
)]{

Reprovided from @racketlink[m:call]{@racket[call]}. This simply makes standard function invocation available as a function, for use in cases where we cannot directly (i.e. syntactically) invoke the function.
This function is in some respects similar to the @hyperlink["https://typeclasses.com/featured/dollar"]{@racket[$] operator} in Haskell.

@examples[
#:eval eval-for-docs
(call + 1 2 3 4)
(call = #:key string-upcase "Apple" "APPLE")
(map call (list add1 sqr) (list 2 3))
]
}

@section[#:tag "function:types"]{Types}

@subsection{Functions and Composition}
Expand Down

0 comments on commit d00e54a

Please sign in to comment.