{"id":7606,"date":"2023-04-01T01:00:52","date_gmt":"2023-04-01T01:00:52","guid":{"rendered":"https:\/\/www.dyalog.com\/blog\/?p=7606"},"modified":"2023-04-21T11:32:36","modified_gmt":"2023-04-21T11:32:36","slug":"extending-structural-functions-to-scalars","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2023\/04\/extending-structural-functions-to-scalars\/","title":{"rendered":"Extending Structural Functions to Scalars"},"content":{"rendered":"<p>Traditionally, the set of monadic reversing or reflecting primitives,\u00a0<em>Reverse-First<\/em> (<code>\u2296<\/code>), <em>Transpose<\/em> (<code>\u2349<\/code>), and <em>Reverse<\/em>\u00a0(<code>\u233d<\/code>) apply to entire arrays and are defined as identity functions on scalar arguments. Dyalog v19.0 extends the definitions to provide equivalent reflections on scalars.<\/p>\n<h2>Character Data<\/h2>\n<p>We expect that the new transformations will be most useful on characters. For example:<\/p>\n<pre>      (\u2349'A')(\u233d'P')(\u2296'L')\r\n\u15c9\ua7fc\u0393\r\n<\/pre>\n<p>Note that you can apply the same transformation to all the items of an array using <em>Each<\/em> (<code>\u00a8<\/code>) or <em>Rank<\/em> (<code>\u23640<\/code>):<\/p>\n<pre>      \u233d\u00a8 'New APL?'\r\n\u0376\u0258w A\ua7fc\u2143\u2e2e\r\n      (\u2296\u23640) 'CAN HAPPEN SOON!'\r\nC\u2200N H\u2200\u042c\u042cEN \ua644OO\u0376\u00a1\r\n<\/pre>\n<p>Composition allows the combination of reflections to perform rotation:<\/p>\n<pre>      \u2296\u2218\u2349\u00a8 '\u2192A\/common'  \u235d 90\u00b0 clockwise rotation\r\n\u2193\u15c6\\\u1d12o\u1d1f\u1d1fo\u1d1d\r\n      \u233d\u2218\u2296\u00a8 '\u2192A\/common'  \u235d 180\u00b0 rotation\r\n\u2190\u2200\/\u0254o\u026f\u026fou\r\n<\/pre>\n<p>We can combine the above techniques with additional structural functions, including reflection of the entire array, to achieve more advanced effects that are often needed in modern user interfaces:<\/p>\n<pre>      \u233d\u00a8 \u233d 'New APL?'     \u235d mirror\r\n\u2e2e\u2143\ua7fcA w\u0258\u0376\r\n      \u2296\u2218\u2349\u00a8 \u236a '\u2192A\/common'  \u235d vertical\r\n\u2193\r\n\u15c6\r\n\\\r\n\u1d12\r\no\r\n\u1d1f\r\n\u1d1f\r\no\r\n\u1d1d\r\n      \u233d\u2218\u2296\u00a8 \u233d '\u2192A\/common'  \u235d upside-down\r\nuo\u026f\u026fo\u0254\/\u2200\u2190\r\n<\/pre>\n<h2>Numeric Data<\/h2>\n<p>Although the transformations are more easily applicable to characters, many numbers are also in the domain of the extended functions:<\/p>\n<pre>      \u233d\u00a8 1.618 2.71828 3.1415\r\n816.1 82817.2 5141.3\r\n      \u233d\u00a8 3J4 0J1 0.5\r\n4J3 1 5\r\n      \u233d\u2218\u2296\u00a8 60 69 908    \u235d 180\u00b0 rotation\r\n9 69 806\r\n      \u2349\u233d 8              \u235d 90\u00b0 counter-clockwise rotation\r\n1.797693135E308\r\n<\/pre>\n<h2>Notes<\/h2>\n<h3>Character Data<\/h3>\n<ul>\n<li>Although the new definitions are available in both 32-bit and 64-bit Unicode editions of Dyalog, very few characters can be reflected in the Classic edition.<\/li>\n<li>A <code>TRANSLATION ERROR<\/code> will be signalled if the required result cannot be represented.<\/li>\n<\/ul>\n<p>For example, using the Classic Edition where the <em>Rank<\/em> operator is represented as <code>\u2395U2364<\/code>:<\/p>\n<pre>      (\u2296 \u2395U2364 0) 'PHI!'\r\nbHI\u00a1\r\n      (\u2296 \u2395U2364 0) 'ABC'\r\nTRANSLATION ERROR: Unicode character \u2395UCS 8704 not in \u2395AVU\r\n      (\u2296\u2395U2364 0)'ABC'\r\n      \u2227\r\n<\/pre>\n<h3>Numeric Data<\/h3>\n<ul>\n<li>The result of numeric reflections can depend on the value of <code>\u2395FR<\/code>.<\/li>\n<li>A <code>DOMAIN ERROR<\/code> will be signalled if the required result cannot be represented.<\/li>\n<\/ul>\n<p>For example, beginning with the default value <code>\u2395FR\u2190645<\/code>:<\/p>\n<pre>      \u233d 1.2345E67\r\nDOMAIN ERROR\r\n      \u233d1.2345E67\r\n      \u2227\r\n      \u2395FR\u21901287\r\n      \u233d 1.2345E67    \u235d 76\u00d710*5432.1\r\n9.56783313E5433\r\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>Although it is extremely unlikely that real applications rely on the current behaviour, the extensions are potentially breaking changes and are, therefore, being released as part of a major version upgrade.<\/p>\n<p>We are somewhat surprised that these obviously useful extensions have been ignored by the APL community for such a long time, and are very pleased to finally make them available to commercial, educational and hobbyist users. Please contact \u0287\u0279oddns@dyalog.com if you would like to test a pre-release of Dyalog v19.0 and help us understand the potential impact on existing applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Traditionally, the set of monadic reversing or reflecting primitives,\u00a0Reverse-First (\u2296), Transpose (\u2349), and Reverse\u00a0(\u233d) apply to entire arrays and are defined as identity functions on scalar arguments. Dyalog v19.0 extends the definitions to provide equivalent reflections on scalars. Character Data &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2023\/04\/extending-structural-functions-to-scalars\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-7606","post","type-post","status-publish","format-standard","hentry","category-recreational"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/7606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=7606"}],"version-history":[{"count":87,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/7606\/revisions"}],"predecessor-version":[{"id":7728,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/7606\/revisions\/7728"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=7606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=7606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=7606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}