Note that there are some explanatory texts on larger screens.

plurals
  1. POJ : creating a family of verbs from an array
    primarykey
    data
    text
    <p>The following expression shows a truth table for each of the 16 primitive Boolean operations:</p> <pre><code> (0 b./; 1 b./; 2 b./; 3 b./; 4 b./; 5 b./; 6 b./; 7 b./; 8 b./; 9 b./; 10 b./; 11 b./; 12 b./; 13 b./; 14 b./; 15 b./) ~ i.2 ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ │0 0│0 0│0 0│0 0│0 1│0 1│0 1│0 1│1 0│1 0│1 0│1 0│1 1│1 1│1 1│1 1│ │0 0│0 1│1 0│1 1│0 0│0 1│1 0│1 1│0 0│0 1│1 0│1 1│0 0│0 1│1 0│1 1│ └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ </code></pre> <p>How can I refactor the part in parentheses to remove the duplication?</p> <p><strong>clarification</strong>:</p> <p>The goal here isn't to produce the table, but rather to learn how to produce new verbs dynamically. In order to reduce the parenthesized expression, I would want to factor out the symbols <code>;</code> , <code>/</code> and <code>b.</code> , and then replace the numbers with <code>i.10</code>.</p> <p>The <code>;</code> symbol is easy enough:</p> <pre><code> ;/i.16 ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬──┬──┬──┬──┬──┬──┐ │0│1│2│3│4│5│6│7│8│9│10│11│12│13│14│15│ └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴──┴──┴──┴──┴──┴──┘ </code></pre> <p>But I'm having a hard time finding a way to produce a new verb from each element in the list.</p> <p>I think maybe I'm looking for some kind of higher-order combinators that allow using <code>&amp;</code> and <code>@</code> with something other than constants.</p> <p>For example, <code>nn leftBondEach v</code> might make an array of verbs equivalent to <code>n0 &amp; v; n1 &amp; v; ... ; nn &amp; v</code> :</p> <pre><code> bverbs =: (i.16)(leftBondEach)b. NB. would mean (0 b.; 1 b.; ...; 15 b.) 0 bverbs 0 ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐ │0│0│0│0│0│0│0│0│1│1│1│1│1│1│1│1│ └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘ 0 bverbs 1 ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐ │0│0│0│0│1│1│1│1│0│0│0│0│1│1│1│1│ └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘ </code></pre> <p>I think I need something similar in order to append the <code>/</code> to each function.</p> <p>Then again, this is J and there's probably a completely different way to approach these problems that I just haven't grokked yet. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload