[racket] Lunch choosing program ported from Haskell to Racket

From: Brian Adkins (racketusers at lojic.com)
Date: Mon Jul 7 21:17:41 EDT 2014

On Jul 5, 2014, at 2:25 PM, Alexander D. Knauth wrote:
> On Jul 5, 2014, at 12:10 PM, Brian Adkins <racketusers at lojic.com> wrote:
> 
>> I've modified the code with Matthias' feedback and a brief reading of the style guide. I must have been confused on the use of "local". I got the impression that it was required if you wanted to (define (foo arg ...)) within another function, but I took it out, and everything works fine. Maybe local is only required for circumstances that I haven't hit yet. The rank-restaurants functions is nicer looking w/o the local.
> 
> I’m pretty sure that local is never required for that in any circumstances.  
> 
> See http://lists.racket-lang.org/users/archive/2013-November/060352.html

Thanks - that's good to know. I probably just saw it in HTDP and made an assumption about it's necessity.

>> Is match typically used to destructure lists?
> 
> Match can be used for a lot of things, but (looking ahead) you might want to look at one of the match-lambda s:
> 
> http://docs.racket-lang.org/reference/match.html?q=match-lambda#%28form._%28%28lib._racket%2Fmatch..rkt%29._match-lambda%29%29
> 
> Probably the one you want is either match-lambda* or maybe match-lambda**.

The various match-lambdas got me closer. I haven't found one w/o an extra set of [ ] or ( ) yet, but if I don't, I think I can make a macro for it after gaining some experience to allow the following:

(define foo 
  (my-match-lambda ((arg1 _ arg2) arg3)
    (bar arg1 arg2 arg3)))

instead of:

(define foo 
  (match-lambda* [(list (list arg1 _ arg2) arg3)
                  (bar arg1 arg2 arg3)]))

Unless I'm missing something, that seems to be a fairly straightforward transformation.



Posted on the users mailing list.