<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged language keyword string function</title>
<link>https://ask.clojure.org/index.php/tag/language+keyword+string+function</link>
<description></description>
<item>
<title>Are there design considerations behind allowing keywords to be functions, but not strings or numbers?</title>
<link>https://ask.clojure.org/index.php/11025/considerations-allowing-keywords-functions-strings-numbers</link>
<description>&lt;p&gt;related to a thread on clojureverse: &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojureverse.org/t/x-x-auto-transducifying-thread-macros/8122/26&quot;&gt;https://clojureverse.org/t/x-x-auto-transducifying-thread-macros/8122/26&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;,where the author's library provides a transducerized variant of -&amp;gt;&amp;gt; called x&amp;gt;&amp;gt; that recog,nizes transducers and tries to turn the threading expression into an efficient transducer form.&lt;/p&gt;
&lt;p&gt;The author then decided to fold in keyword-access semantics for strings and numbers, to enable threaded expressions that equate to &lt;code&gt;get&lt;/code&gt; or &lt;code&gt;get-in&lt;/code&gt; with less verbosity.  Something like &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(let [m {1 {&quot;b&quot; [0 1 {:c :res}]}}]
     (x&amp;gt; m 1 &quot;b&quot; 2 :c name)) ;=&amp;gt; &quot;res&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which is akin to the keyword idiom of &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(-&amp;gt; m :a :b :c) ;;some-nested-value
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is there any reason why in the general case, &lt;code&gt;eval&lt;/code&gt; should not support keyword access semantics for other simple types like numbers and strings (maybe booleans, whatever)?&lt;br&gt;
Aside from being unable to extend IFn to strings and numbers (this would have to be handled with additional type checks dispatching on the first arg instead of focusing on IFn), are there language design arguments against this?  I am unable to derive any off the top of my head.&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11025/considerations-allowing-keywords-functions-strings-numbers</guid>
<pubDate>Wed, 08 Sep 2021 20:24:28 +0000</pubDate>
</item>
</channel>
</rss>