{"id":12549,"date":"2024-10-31T11:24:49","date_gmt":"2024-10-31T15:24:49","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=12549"},"modified":"2024-10-31T11:24:49","modified_gmt":"2024-10-31T15:24:49","slug":"define-alternatives","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=12549","title":{"rendered":"Define Alternatives"},"content":{"rendered":"<p>\nMarcin Borkowski (mbork) has an <a href=\"https:\/\/mbork.pl\/2024-10-28_Command_alternatives\">excellent post<\/a> concerning a function I didn&rsquo;t know about. It helps with the following problem: suppose you have a function with several implementations, want to access them with a single function name, and need to choose the implementation to use when you invoke the common function name.\n<\/p>\n<p>\nThat probably seems a little obscure but the example that mbork gives makes it clear. His use case is wanting to play some music using one of <code>mplayer<\/code>, <code>vlc<\/code>, or <code>mpv<\/code> using a single invocation name.\n<\/p>\n<p>\nThere are plenty of straightforward ways of doing this, of course, but mbork shows a very nice builtin method: <code>define-alternatives<\/code>. It&rsquo;s easy to use and set up. You simply provide an alist of method\/function pairs and use <code>define-alternatives<\/code> to specify a function name that will invoke the method of the user&rsquo;s choice. See mborks post or <a href=\"https:\/\/www.gnu.org\/software\/emacs\/manual\/html_node\/elisp\/Generic-Commands.html#index-define_002dalternatives\">the documentation<\/a> for the details.\n<\/p>\n<p>\nDefine-alternatives is a great way of handling this situation. It&rsquo;s hard to imagine a method that requires less code or effort on the developer&rsquo;s part. As mbork says, the method doesn&rsquo;t seem to be well known so it&rsquo;s worthwhile pointing to mbork&rsquo;s post as a way of getting the word out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Marcin Borkowski (mbork) has an excellent post concerning a function I didn&rsquo;t know about. It helps with the following problem: suppose you have a function with several implementations, want to access them with a single function name, and need to &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=12549\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18],"class_list":["post-12549","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12549"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12549\/revisions"}],"predecessor-version":[{"id":12550,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12549\/revisions\/12550"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}