{"id":11980,"date":"2024-02-16T11:47:13","date_gmt":"2024-02-16T16:47:13","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=11980"},"modified":"2024-02-16T11:47:13","modified_gmt":"2024-02-16T16:47:13","slug":"cl-callf","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=11980","title":{"rendered":"Cl-callf"},"content":{"rendered":"<p>\nJust a quickie today. I came across this <a href=\"https:\/\/www.reddit.com\/r\/emacs\/comments\/1ap9azk\/til_to_use_clcallf_to_toggle_a_var_without\/\">reddit post about cl-callf<\/a>. It was something I had never heard of. One of the Lisp idioms is to toggle a boolean with\n<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\">(<span style=\"color: #a020f0;\">setq<\/span> bool (not bool))\n<\/pre>\n<\/div>\n<p>\nI use it all the time but when the variable is named <code>AVeryLongAndStupidName<\/code> instead of something reasonable like bool, it can be a pain because you have to repeat the name. Of course, no true <del>Scotsman<\/del> Lisper would use such a name but occasionally one comes across such monstrosities.\n<\/p>\n<p>\nIt turns out that Elisp has the macro <code>cl-callf<\/code> that lets you write the idiom as\n<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\">(<span style=\"color: #a020f0;\">cl-callf<\/span> not bool)\n<\/pre>\n<\/div>\n<p>\nThere&rsquo;s also the related <code>cl-callf2<\/code>. You should check out the documentation for both because they&rsquo;re a bit richer than the above suggests.\n<\/p>\n<p>\nI&rsquo;m not sure why Emacs thinks this is a Common Lisp thing because as far as I can tell there is no <code>callf<\/code> in Common Lisp. It&rsquo;s probably due to the fact that the variable can be a place rather than a simple variable in which case <code>cl-callf<\/code> does the equivalent of a <code>setf<\/code>, a Common Lisp form. In any event, it can save you some typing when using a common idiom.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just a quickie today. I came across this reddit post about cl-callf. It was something I had never heard of. One of the Lisp idioms is to toggle a boolean with (setq bool (not bool)) I use it all the &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=11980\">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-11980","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\/11980","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=11980"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/11980\/revisions"}],"predecessor-version":[{"id":11981,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/11980\/revisions\/11981"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}