[racket] (procedure? (hash)) -> true
Consider overriding #%app for your modules. And
(define (curt-style-receiver data)
(cond
[(data 'COMPANY) => (curry db-exec ...)]
[else .. what are you doing in the #f case? nothing? ...]))
On Aug 5, 2013, at 11:30 AM, John Griffin wrote:
> I do a lot of work with hash as the result of JSON-RPC calls, with considerable use of hash-ref. In most places, I've replaced the hash with a local result of transforming the hash to a procedure so that I can:
>
> (stuff 'COMPANY)
>
> rather than
>
> (hash-ref stuff 'COMPANY)
>
> Of course, the setup call to exchange the hash for the procedure takes another line, such that I only bother on longer functions with repeated benefit.
>
> It certainly would be handy from a succinctness standpoint if a hash acted like a procedure (Any -> Any). Noticing that struct can be a procedure? via a property , I wonder if there's a way for hash? and procedure? to both hold true.
>
> It's more than simply saving the 9 letters of hash-ref followed by a space. Performance is not an issue and given a curt enough representation, I'd prefer calling it twice rather than making a local define. My current choices are:
>
> ; current STYLE #1
> (define (current-rpc-receiver data)
> (define company (hash-ref data 'COMPANY #f))
> (when company
> (db-exec … company))
>
> ; current STYLE #2
> (define (curt-style-rpc-receiver data)
> (define HF (hash->procedure data))
> (when (HF 'COMPANY)
> (db-exec …. (HF 'COMPANY))
>
> ; what would be handier….
>
> (define (handy-style data)
> (when (data 'COMPANY)
> (db-exec … (data 'COMPANY))
>
> Thanks in advance for any advice leading to more succinct hash access.
>
> ------
> John Griffin, CTO
> IT Talent Team, LLC
> www.ittalentteam.com
> 855-488-8326
>
>
>
>
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130805/2c2593f1/attachment.html>