@brentgordon146 has joined the channel
sometimes, for sure. I agree define-values is not so different from that.
I ask because I usually recommend using define
instead of let
/ let*
/ etc.
so I was curious how you do things
yeah, good point. I do have a habit of using define
s
that is my style as well
although if I just have one thing to match on, I might just match
if I have multiple things, always match-define
how can i determine a file’s mime type?
@brentgordon146 In the general case, you can’t, but that isn’t a very helpful answer. The two usual general approaches (not specific to Racket) are either to use a heuristic based on the file’s content or to rely on metadata. A common type of metadata is the file extension—probably you know that, and probably you also realize there are limitations. You can get it with path-get-extension
. The main Racket distribution comes with a mapping of mime types for common file extensions to support the web server: https://docs.racket-lang.org/web-server-internal/mime-types.html Some platforms maintain additional metadata about a file’s type. The GUI library includes file-creator-and-type
to access one such mechanism on Mac OS, though you would also need to know what mime type corresponds to each Mac OS content type: https://docs.racket-lang.org/gui/Windowing_Functions.html#(def._((lib._mred%2Fmain..rkt)._file-creator-and-type)) You could use the FFI to access other interfaces from the OS. The way the Unix file
command does this (<http://www.darwinsys.com/file/>) is by looking at the file content, usually (maybe always?) just the first few bytes. I thought I remembered there being a Racket package that used this strategy, either in pure Racket or by using libmagic
through the FFI, but I can’t find it now. You could run the file
command with system*
, though, or implement such a package yourself.