fonsp / Pluto.jl

🎈 Simple reactive notebooks for Julia
https://plutojl.org/
MIT License
4.94k stars 285 forks source link

Feature request: a tool to auto-create a function from a cell's dependencies #338

Open stillyslalom opened 4 years ago

stillyslalom commented 4 years ago

The idea is to simplify the process of going from a reactive Pluto environment to a (frozen) reusable function. Let's say we've been playing around with data for a while, trying to find qux as a function of bar: image

It'd be great to have a way to leverage Pluto's DAG of cell dependencies to automatically create a new cell defining a method

function f_qux(bar)
    foo = rand(10)
    baz = sum(foo .+ sin(bar))
    return baz^2
end

I'd stipulate that the new function would only take variables created via @bind as arguments, with all other dependencies set within the function's scope. The user could then modify the function as needed.

This enables:

fonsp commented 3 years ago

@dralletje

dralletje commented 3 years ago

😏

fonsp commented 3 years ago

We are actually working on something very similar! https://www.notion.so/Notebooks-inside-notebooks-9e99d381c3014e40b310d4846c764a15

(Most of that document is a bit too specific about edge cases and the file format)

Let us know what you think!

stillyslalom commented 3 years ago

I feel like https://www.notion.so/Wrap-cell-code-inside-functions-2a53c3fc6de74bf0a3f9b741e10696f0 gets closer to what I was describing - I want to be able to select an output cell and, from it, generate a method that gets placed in a new cell. This would be a static, user-triggered process, rather than a reactive, continuous thing. The goal is to create ordinary Julia methods that can easily be used within other (Pluto-unaware) parts of the Julia ecosystem, like root-finders or optimization routines.