New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce definition of external functions #310

Closed
oliver---- opened this Issue Jul 6, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@oliver----
Copy link
Member

oliver---- commented Jul 6, 2017

We want to be able to expose a new function implemented in a cell something like

myfun = function(x:int, y:int)
return x+y
@nokome

This comment has been minimized.

Copy link
Member

nokome commented Jul 14, 2017

I think that this should be a fairly high priority so that we can define built in Mini functions using this approach.

To be be able to specify the external language, and to specify the type of the return value, the syntax needs to be something like this (which is very similar to Typescript's typing syntax):

myfunc = function js(x:int, y:int):int
return x+y

Do we need to allow type specification to be optional? What are the pros/cons of making it optional or not? e.g.

myfunc = function js(x, y)
return x+y

Multiple dispatch will be very useful for keeping a tidy function namespace in Mini and should be implemented as part of this. See src/js-context/functions/types/_multifunc.js for our current implementation of that.

@nokome

This comment has been minimized.

Copy link
Member

nokome commented Jul 26, 2017

Thinking some more about how Mini function definitions would actually be defined...

A user defined R function like this

myfunc = function r(x:int, y:int):int
return x + y

Could be implemented as a Mini function in Javascript as:

const myfunc = {
  name: 'myfunc',
  inputs: [
    {
      name: 'x',
      type: 'int'
    },{
      name: 'y',
      type: 'int'
    },
  ],
  output: {
    type: 'int'
  },
  language: 'r',
  code: 'return x + y'
}

A builtin Mini function with some additional documentation could look something like:

const sum = {
  name: 'sum',
  description: 'Adds up some numbers',
  inputs: [
    {
      name: 'values',
      type: '[number]',
      description: 'The numbers to add up'
    }
  ],
  output: {
    type: 'number'
  },
  language: 'js',
  code: function(values) { return stdlib.sum(values) }
}
@nokome

This comment has been minimized.

Copy link
Member

nokome commented Aug 30, 2017

Another proposal for moving ahead with this...

We should treat functions just like other parts of the platform and make them "first class citizens" just like Documents and Sheets. We would define a Function data model using an XML schema (as we are doing for Sheets, and will do for Documents) and UI components that would allow editing of functions as standalone entities along the lines of what @michael proposed here.

In the short term, I don't think we should do any UI for Functions and instead just focus on:

  • defining a data model
  • wrapping existing Javascript functions (e.g. from stdlib) to quickly establish functionality in Mini (although we should be careful not to rush naming!).
  • we might also want to wrap some functions in R and Python to test generality of the data model

In the longer term, we can add UI Components allowing users to do basic CRUD on Functions.

1.5 years ago (around January 2016 😮) we put a fair bit of thought into functions - and were moving towards making them first class citizens - both user defined functions and reflection of existing functions. See discussion at #96. We don't need to be bound by this prior work, but some of it could be useful for avoiding reinventing our own wheels :):

c8b8a5fe-c0a0-11e5-9928-742660a16c3a

@michael and @oliver---- : I think we all agreed this issue should be a high priority (it's needed to be able to do anything useful with sheets!) and it's something that could be developed in parallel to the ongoing work on the sheets UI. Let me know you thoughts and we can coordinate on who will do what, when.

@nokome

This comment has been minimized.

Copy link
Member

nokome commented Aug 30, 2017

Also of relevance is #172 regarding our previous approach to implementing Excel functions using R and which provides a list of the most commonly used Excel functions.

@nokome nokome referenced this issue Aug 30, 2017

Closed

Implement spreadsheet compatibility functions for R #172

0 of 33 tasks complete

@nokome nokome added the what:funcs label Aug 31, 2017

@nokome nokome referenced this issue Sep 8, 2017

Closed

WIP: Functions #336

@oliver----

This comment has been minimized.

Copy link
Member

oliver---- commented Sep 22, 2017

Closing this, because we are taking a totally different approach (#351) than proposed here.

@oliver---- oliver---- closed this Sep 22, 2017

nokome added a commit that referenced this issue Sep 27, 2017

Adds additional descriptive elements to schema
Based on [our initial work on defining functions](#310 (comment))
which was in turn informed by things like [JsDoc](http://usejsdoc.org/) and
[R function documentation](https://cran.r-project.org/doc/manuals/R-exts.html#Rd-format);

  - `<summary>` : short one sentence summary suitable for use in tooltips etc (like JsDoc `@summary`)
  - `<relateds>` : names of related functions (like JsDoc `@see`)
  - `<examples>` : examples of usage (like JsDoc `@example`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment