1. 4
  1.  

  2. 2

    One question I’ve been puzzling over since your previous post: where does the “forkness” of ‘+/ % #’ lie? I’m probably being the fish asking what water is, but I’m used to languages having a well defined evaluation model with precedence. Like expanding inner expressions first, or applying operators from left to right. How does the ‘mean’ construction above know to pass its input to both ‘+/’ and ‘#’? Is it just hardcoded into a few operations (akin to Common Lisp special forms)? Or is there a way to construct hooks out of arbitrary operators?

    1. 2

      Or is there a way to construct hooks out of arbitrary operators?

      Any three verbs in a row are a (monadic) fork (there are also dyadic forks). Adverbs (e.g. /) are evaluated before verbs (e.g. %), so a verb is produced by the verb-adverb +/ and thus you get three verbs (plus-over, divide, tally) in a row and thus a fork.

      There’s no hard coding of it:

          plus =: +
          over =: /
          plusover =: plus over
          divide =: %
          tally =: #
          average =: plusover divide tally
          average i.4
      1.5
      
      1. 2

        Like @lorddimwit mentioned, any three verbs in a row form a fork. Forks and hooks do have well defined evaluation models. It’s spelled out pretty well on this page.

        In the case of mean, we’re looking at a “monadic fork” (a fork that takes a single argument). The evaluation model for monadic forks looks like this:

        (V0 V1 V2) Ny  is  (V0 Ny) V1 (V2 Ny)
        

        Subbing V0, V1, and V2 for +/, %, and # gives us:

        (+/ Ny) % (# Ny)
        

        Where Ny is your argument.