<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>End-user development via sheet-defined functions</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Peter Sestoft</string-name>
          <email>sestoft@itu.dk</email>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Jonas Druedahl Rask</string-name>
        </contrib>
      </contrib-group>
      <abstract>
        <p>We have developed an implementation of sheet-de ned functions, a mechanism that allows spreadsheet users to de ne their own functions, using only spreadsheet concepts such as cells, formulas and references, and no external programming languages. This position paper presents the motivation and vision of this work, describes the features of our prototype implementation, and outlines future work.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Spreadsheets</kwd>
        <kwd>end-user development</kwd>
        <kwd>functional programming</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>We have implemented this idea in the form of sheet-de ned
functions. A user may de ne a function F simply by
declaring which (input) cells will hold F's formal parameters and
which (output) cell will compute F's result, as a function of
the input cells. The function de nition may involve
arbitrary additional cells, spreadsheet formulas, calls to built-in
functions, and calls to other sheet-de ned functions.
Figure 1 shows an example. In the example, values are referred
to by cell (such as B25). A mechanism that allows for
symbolic names (such as \periods") instead could be added, but
Nardi speculates that end user developers would not
necessarily nd that better [7, page 44].</p>
      <p>
        Augustsson et al. from Standard Chartered Bank provide
further support for the utility of such abstraction
mechanisms, saying about the traditional combination of Excel
and externally de ned functions that \change control, static
type checking, abstraction and reuse are almost completely
lacking" [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
      </p>
    </sec>
    <sec id="sec-2">
      <title>2. THE VISION</title>
      <p>The ultimate goal of this work is to allow spreadsheet users
themselves to develop and evolve libraries of user-de ned
functions to support sophisticated spreadsheet models. De
ning a function requires only well-known spreadsheet concepts
such as cell, cell reference and function, and no external
programming languages. Therefore experimentation and
adaptation of user-de ned functions remain under the control of
the spreadsheet users and domain experts, who need not
wait for an IT department to understand, describe,
implement and test the desired changes.</p>
      <p>Any spreadsheet computation can be turned into a
sheetde ned function. This ensures conceptual and notational
simplicity. Moreover, it means that new user-de ned
functions may arise by refactoring of a spreadsheet model as
it evolves. As a spreadsheet model becomes more re ned
and complex, it may be observed that the same cluster of
formulas appears again and again. Such a cluster of
formulas may then be encapsulated in a sheet-de ned function,
and each formula cluster replaced by a call to that function.
This both simpli es the spreadsheet model and improves its
maintainability, because a bug- x or other improvement to
the function will automatically a ect all its uses, unlike the
traditional situation when there are multiple copies of the
same cluster of formulas.</p>
      <p>Sheet-de ned functions may be shared with other users in
the same department or application domain, without
preventing them from making their own improvements |
because the domain knowledge is not locked into the notation
of a \real" programming language, but one that presumably
is familiar to users and that they are (more) comfortable
experimenting with.</p>
      <p>
        Sheet-de ned functions support end-user \tinkering" to
develop models and work ows that are appropriate within
their application domain [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. Clearly not all spreadsheet
users will be equally competent developers of sheet-de ned
functions, and clearly not all software should be developed
in this way. However, judging from the huge popularity
of spreadsheets within banks, nance, management, science
and engineering, the immediate response and the user
control o ered by spreadsheets are attractive features. Also,
from anecdotal evidence, structured use of spreadsheets is a
exible, fast and cheap alternative to \big bang" professional
IT projects.
      </p>
    </sec>
    <sec id="sec-3">
      <title>3. THE FUNCALC PROTOTYPE</title>
      <p>
        We have created a prototype implementation of sheet-de ned
functions, called Funcalc. The implementation is written in
C#, is quite compact (12,000 lines of code) and compiles
sheet-de ned functions to .NET bytecode [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] at run-time.
As shown by Table 1 execution e ciency is very good; this
is due both to local optimizations performed by our function
compiler and to Microsoft's considerable engineering e ort
in the underlying .NET just-in-time compiler.
      </p>
      <p>
        Funcalc features include:
a \normal" interpretive spreadsheet implementation;
a compiled implementation of sheet-de ned functions;
recursive functions and higher-order functions;
functions can accept and return array values in
addition to numbers and string;
automatic specialization, or partial evaluation [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ];
facilities for benchmarking sheet-de ned functions.
Because Funcalc supports higher-order functions, the value
contained in a cell, say A42, may be a function value. This
value may be called as APPLY(A42,0.053543,4) using
builtin function APPLY.
      </p>
      <p>Function values are built by applying a sheet-de ned
function to only some of its arguments, the absent arguments
being given as NA(); the resulting function value will
display as NOMINAL(#NA,4) or similar.</p>
      <p>
        Such a function value may be specialized, or partially
evaluated, with respect to its available (non-#NA) arguments.
The result is a new function value with the same behavior
but potentially better performance because the available
argument values have been inlined and loops unrolled in the
underlying bytecode. For more information, see [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] and [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ].
Specialization provides some amount of incremental
computation and memoization, and we do not currently have other
general mechanisms for these purposes.
      </p>
      <p>
        A forthcoming book [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ] gives many more details of the
implementation, more examples of sheet-de ned functions, and
a manual for Funcalc. A previously published paper [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ]
presents a case study of reimplementing Excel's built-in
nancial functions as sheet-de ned functions.
      </p>
      <p>
        A comprehensive list of US spreadsheet patents is given in
a forthcoming report [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ].
      </p>
    </sec>
    <sec id="sec-4">
      <title>4. INTEGRATION WITH EXCEL</title>
      <p>
        In ongoing work [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] we integrate sheet-de ned functions
with the widely used Microsoft Excel spreadsheet program,
rather than our Funcalc prototype, as illustrated in Figures 2
and 3. This enables large-scale experimentation with
sheetde ned functions because they can be de ned in a context
that is familiar to spreadsheet users and provides charting,
auditing, and so on.
      </p>
      <p>
        The main downside is that calling a sheet-de ned function
from Excel is much slower than from the Funcalc
implementation (yet apparently faster than calling a VBA function);
see Table 2. However, the sheet-de ned function itself will
execute at the same speed as in Funcalc. This work uses the
Excel-DNA runtime bridge between Excel and .NET [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
    </sec>
    <sec id="sec-5">
      <title>5. FUTURE WORK</title>
      <p>
        So far we have focused mostly on functionality and good
performance. We emphasize performance because we want
sheet-de ned functions to replace not only user-de ned
functions written in VBA, C++ and other external languages,
but to replace built-in functions also. Domain experts in
nance, statistics and other areas of rather general interest
should be able to develop well-performing high-quality
functions themselves and not have to rely on Microsoft or other
vendors to do so.
However, a well-performing implementation of sheet-de ned
functions is just the beginning: one should investigate
additional infrastructure and practices to support their use.
For instance, how can we extend the natural collaboration
around spreadsheet development [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] in a community of users
to cover also libraries of sheet-de ned functions; how can we
support versioning and merging of such libraries in a way
that does not preclude individual users' tinkering and
experimentation; how can we support systematic testing; and
so on.
      </p>
      <p>
        Our concept of sheet-de ned functions should be subjected
to a systematic usability study; the study conducted by
Peyton-Jones, Blackwell and Burnett [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] assumed that
functions could not be recursive, whereas ours can.
      </p>
      <p>
        Finally, sheet-de ned functions lend themselves well to
parallelization, because they are pure (yet strict, an unusual
combination) so that computations can be reordered and
performed speculatively, and often exhibit considerable
explicit parallelism. In fact, they resemble data ow languages
such as Sisal [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. Presumably some of the 1980es techniques
used to schedule data ow languages [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ] could be used to
perform spreadsheet computations e ciently on modern
multicore machines. The result might be \supercomputing for
the masses", realizing Chandy's 1984 vision [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
      </p>
    </sec>
    <sec id="sec-6">
      <title>6. CONCLUSION</title>
      <p>We have presented a prototype implementation of
sheetde ned functions and outlined some future work. Our hope
is that such functionality will become available in widely
used spreadsheet programs, or via a full-featured version of
the plugin described in Section 4, and will enable
spreadsheet users to develop their own computational models into
reusable function libraries, without loss of computational
e ciency and without handing over control to remote IT
departments or software contractors. Moreover, there seems
to be a technological opportunity to harness the power of
multicore machines through spreadsheet programming.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>L.</given-names>
            <surname>Augustsson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Mansell</surname>
          </string-name>
          , and
          <string-name>
            <given-names>G.</given-names>
            <surname>Sittampalam. Paradise</surname>
          </string-name>
          :
          <article-title>A two-stage DSL embedded in Haskell</article-title>
          .
          <source>In International Conference on Functional Programming (ICFP'08)</source>
          , pages
          <fpage>225</fpage>
          {
          <fpage>228</fpage>
          . ACM,
          <year>September 2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>M.</given-names>
            <surname>Chandy</surname>
          </string-name>
          .
          <article-title>Concurrent programming for the masses. (PODC 1984 invited address)</article-title>
          .
          <source>In Principles of Distributed Computing</source>
          <year>1985</year>
          , pages
          <fpage>1</fpage>
          <lpage>{</lpage>
          12. ACM,
          <year>1985</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Ecma</given-names>
            <surname>TC39 TG3. Common Language Infrastructure (CLI). Standard</surname>
          </string-name>
          ECMA-
          <volume>335</volume>
          . Ecma International, sixth edition,
          <year>June 2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <surname>Excel</surname>
            <given-names>DNA</given-names>
          </string-name>
          <string-name>
            <surname>Project. Homepage</surname>
          </string-name>
          . At http://exceldna.codeplex.
          <source>com/ on 28 February</source>
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>N. D.</given-names>
            <surname>Jones</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Gomard</surname>
          </string-name>
          , and
          <string-name>
            <given-names>P.</given-names>
            <surname>Sestoft</surname>
          </string-name>
          .
          <article-title>Partial Evaluation and Automatic Program Generation</article-title>
          . Prentice Hall,
          <year>1993</year>
          . At http://www.itu.dk/people/sestoft/pebook/pebook.html on
          <issue>9</issue>
          <year>June 2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>J.</given-names>
            <surname>McGraw</surname>
          </string-name>
          et al. Sisal.
          <article-title>Streams and iteration in a single assignment language</article-title>
          .
          <source>Language reference manual, version 1</source>
          .2.
          <string-name>
            <surname>Technical</surname>
            <given-names>report</given-names>
          </string-name>
          , Lawrence Livermore National Labs,
          <year>March 1985</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>B. A.</given-names>
            <surname>Nardi</surname>
          </string-name>
          <article-title>A small matter of programming. Perspectives on end user programming</article-title>
          . MIT Press,
          <year>1993</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>B. A.</given-names>
            <surname>Nardi</surname>
          </string-name>
          and
          <string-name>
            <given-names>J. R.</given-names>
            <surname>Miller</surname>
          </string-name>
          <article-title>Twinkling lights and nested loops: distributed problem solving and spreadsheet development</article-title>
          .
          <source>International Journal of Man-Machine Studies</source>
          ,
          <volume>34</volume>
          :
          <fpage>161</fpage>
          {
          <fpage>184</fpage>
          ,
          <year>1991</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>S. Peyton</given-names>
            <surname>Jones</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Blackwell</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Burnett</surname>
          </string-name>
          .
          <article-title>A user-centred approach to functions in Excel</article-title>
          .
          <source>In ICFP '03: Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming</source>
          , pages
          <volume>165</volume>
          {
          <fpage>176</fpage>
          . ACM,
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>J. D.</given-names>
            <surname>Rask</surname>
          </string-name>
          and
          <string-name>
            <given-names>S. E.</given-names>
            <surname>Timmermann</surname>
          </string-name>
          .
          <article-title>Integration of sheet-de ned functions in Excel using C#. Master's thesis</article-title>
          , IT University of Copenhagen,
          <year>2014</year>
          . (
          <issue>Expected June 2014</issue>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>V.</given-names>
            <surname>Sarkar</surname>
          </string-name>
          and
          <string-name>
            <given-names>J.</given-names>
            <surname>Hennessy</surname>
          </string-name>
          .
          <article-title>Compile-time partitioning and scheduling of parallel programs</article-title>
          .
          <source>In ACM SIGPLAN '86 Symposium on Compiler Construction</source>
          , pages
          <volume>17</volume>
          {
          <fpage>26</fpage>
          ,
          <year>June 1986</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>P.</given-names>
            <surname>Sestoft</surname>
          </string-name>
          .
          <article-title>Online partial evaluation of sheet-de ned functions</article-title>
          . In A.
          <string-name>
            <surname>Banerjee</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          <string-name>
            <surname>Danvy</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          <string-name>
            <surname>Doh</surname>
          </string-name>
          , and J. Hatcli , editors,
          <source>Semantics, Abstract Interpretation, and Reasoning about Programs</source>
          , volume
          <volume>129</volume>
          <source>of Electronic Proceedings in Theoretical Computer Science</source>
          , pages
          <volume>136</volume>
          {
          <fpage>160</fpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>P.</given-names>
            <surname>Sestoft</surname>
          </string-name>
          .
          <source>Spreadsheet Implementation Technology. Basics and Extensions</source>
          . MIT Press,
          <year>2014</year>
          .
          <source>ISBN 978-0-262-52664-7. (Expected August</source>
          <year>2014</year>
          ). 313 pages.
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>P.</given-names>
            <surname>Sestoft</surname>
          </string-name>
          .
          <article-title>Spreadsheet patents</article-title>
          .
          <source>Technical Report ITU-TR-2014-178</source>
          , IT University of Copenhagen,
          <year>2014</year>
          .
          <source>ISBN 978-87-7949-317-9</source>
          . (To appear).
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>P.</given-names>
            <surname>Sestoft</surname>
          </string-name>
          and
          <string-name>
            <surname>J. Z.</surname>
          </string-name>
          <article-title>S rensen. Sheet-de ned functions: implementation and initial evaluation</article-title>
          . In Y. Dittrich et al., editors,
          <source>International Symposium on End-User Development</source>
          ,
          <year>June 2013</year>
          , volume
          <volume>7897</volume>
          of Lecture Notes in Computer Science, pages
          <volume>88</volume>
          {
          <fpage>103</fpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>