I don't fully understand what the append-map command does in racket, nor do I understand how to use it and I'm having a pretty hard time finding some decently understandable documentation online for it. Could someone possibly demonstrate what exactly the command does and how it works?
相关问题
- Generating powerset in one function, no explicit r
- What is fixed point?
- How to include another file of definitions in curr
- unfold function in scheme
- Smoothing issue with Diamond-Square algorithm
相关文章
- Does learning one Lisp help in learning the other?
- What is “3D syntax”?
- What is the definition of “natural recursion”?
- How do I define a sub environment in scheme?
- Why is it legal in a function definition to make s
- How do I get Oracle, see what procedures are runni
- Sending HTTP POST in Racket
- How to split list into evenly sized chunks in Rack
The
append-map
procedure is useful for creating a single list out of a list of sublists after applying a procedure to each sublist. In other words, this code:... Is semantically equivalent to this:
... Or this:
The applying-append-to-a-list-of-sublists idiom is sometimes known as flattening a list of sublists. Let's look at some examples, this one is right here in the documentation:
For a more interesting example, take a look at this code from Rosetta Code for finding all permutations of a list:
The last procedure can be expressed more concisely by using
append-map
:Either way, the result is as expected:
In Common Lisp, the function is named "mapcan" and it is sometimes used to combine filtering with mapping:
In Racket that would be:
But it's better to do it this way: