

Under which name is this function usually known as? (define (mapmap f xss)
(for/list ([xs xss])
(map f xs)))

No idea. First made-up name that came to my mind was mmap
.

Not all simple functions have a name. IIRC, identity
was introduced very late in Racket (because you can use values
, but it’s not the same contract)

I sort of thought it was called deep-map, but I couldn’t find that name in the docs.

deep-map sounds more like a tree-map to me

That would be okay - but I can’t find tree-map for a standard list-based tree either.

some srfi?

tree-map is different though since elements that are lists are recurred through.

I don’t think you’d want either of these choices, but <https://hoogle.haskell.org/?hoogle=(a-%3Eb)-%3E%5B%5Ba%5D%5D-%3E%5B%5Bb%5D%5D|Hoogle says> <<$>> or <$$>. Conclusion: not as common as you would think?

@soegaard2 I didn’t check, but it may be faster to use (define (mapmap f xss)
(for/list ([xs (in-list xss)])
(for/list ([x (in-list xs)])
(f x))))
because map
will check the list contract many times, whereas there’s a chance for the compiler to lift it when using for/list

(because map is a function but for/list is a macro, so more chances to speed things up, but I don’t know for sure)

Good point. I am using it on relatively small “tables” though.

table-map
also came to my mind, but I’m not sure how widespread it is to call these 2d-lists tables. I would say that a table must have the same number of rows, which is not necessarily the case for you function.

@laurent.orseau They both involve checking the outer list once, and each inner list once, so I don’t see the check you’re thinking of. I can imagine different optimizations that might get applied to each, so it would need profiling with a particular enviroment and use case.

I was thinking of the list?
check in the inner loop, but it’s actually constant-time amortized, so that doesn’t apply here. (I had in mind a map
with two lists, which checks that the lengths are equal, and this is linear time. for
friends don’t check this.) +1 to profiling in any case

@cyunus has joined the channel

@sandel.konjevic.teodo https://docs.racket-lang.org/threading/index.html?q=threading

@samth how would you turn a type->sexp
value back into a type at runtime?

I got something to work for simple types, but fails if a type uses an extra def from the #%type-decl
submodule.
The simple thing is: • have a module that imports the same bindings as a type-decl submod does • define-namespace-anchor NS in this module • (eval ty-datum NS) I’ve tried changing tc-toplevel.rkt
to put a copy of (make-env-init-codes)
as an S-expression in the module toplevel, and eval’ing that too … but I still get unbound id errors
I also tried putting a sexp->type
function inside the #%type-decl
submod, using eval in its anchored namespace, and still get unbound ids