Skip to content

using hash-tables for rest-arguments that include keyword-arguments

License

Notifications You must be signed in to change notification settings

AlexKnauth/hash-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hash-lambda

documentation: http://pkg-build.racket-lang.org/doc/hash-lambda-toc/index.html

hash-lambdas allow you to create a "rest argument" see Declaring a Rest Argument that includes keyword arguments. Instead of storing the arguments in a list, hash-lambda stores them in a hash table, where you can use (hash-ref args-hash 0), etc. to access by-position arguments, and (hash-ref args-hash '#:kw), etc. to access keyword arguments, or you can use hash-lambda/match and use match patterns for the arguments. You can also use apply/hash to apply an args-hash to a function.

Examples:

> (require hash-lambda)
> (define my+
    (hash-lambda/match
     [(hash-table [0 a] [1 b])
      (+ a b)]))
> (my+ 1 2)
3
> (define/contract kinetic-energy (#:mass number? #:velocity number? . -> . number?)
    (hash-lambda/match
     [(hash-table ['#:mass mass] ['#:velocity velocity])
      (* 1/2 mass (sqr velocity))]))
> (kinetic-energy #:mass 2 #:velocity 1)
1

About

using hash-tables for rest-arguments that include keyword-arguments

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages