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

Reply via email to