Ignoring Multiple Return Values ​​in Racket

In Racket, you can return multiple values ​​from a function by doing, for example,

(define (foo) (values 1 2 3)) 

Then we can bind them by doing

 (define-values (one two three) (foo)) 

Now one bound to 1 , two to 2 and three to 3 .

I have a function that returns multiple values, but I'm only interested in some of them. Is there a way to extract the “interesting” return values, while the “ignoring” (i.e., not binding) else is a la _ pattern in Haskell?

+4
source share
1 answer

You can use match-let-values or match-define-values for this (depending on whether you want lexical or top variables):

 > (match-let-values (((_ _ a _) (values 1 2 3 4))) a) ; => 3 > (match-define-values (_ a _ _) (values 1 2 3 4)) > a ; => 2 
+6
source

Source: https://habr.com/ru/post/1487133/


All Articles