Skip to content
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

Save expressions to .jl? #253

Open
ChrisRackauckas opened this issue Feb 6, 2020 · 6 comments
Open

Save expressions to .jl? #253

ChrisRackauckas opened this issue Feb 6, 2020 · 6 comments

Comments

@ChrisRackauckas
Copy link

I would like to just do save(filename, ::Expr) with ModelingToolkit.jl generated code. Would it be right to add this as a standard FileIO.jl thing?

@timholy
Copy link
Member

timholy commented Feb 6, 2020

This may already work if filename ends in .jld or .jld2 (I haven't tested recently). Or are you thinking of a dedicated serialization format?

EDIT: Oh, from the title you mean as a loadable .jl file? That's easy if you just wrap in an eval but I'd guess you want it to have a readable & editable result? That would be interesting. I assume you know about https://docs.julialang.org/en/latest/devdocs/ast/ and would only be interested in the surface syntax?

@ChrisRackauckas
Copy link
Author

Yeah, I am thinking it would be a nice helper to allow for just saving expressions to files, just doing write("function.jl", string(func)). It's nothing big but something that felt missing.

@timholy
Copy link
Member

timholy commented Feb 6, 2020

It would be excellent to make that easy. I've wanted something like that for a while.

If you've not done this before, I just submitted a PR myself (#254) so there are "fresh" models available. I guess this is a case, though, where you'd want save but not load support. We also couldn't have magic bytes, it will have to be detected entirely by the ".jl" file extension. So really it's not very similar to my recent PRs.

@ChrisRackauckas
Copy link
Author

load could take a Julia file and make an array of Expr from it. 99.99% of the time you'd want include though.

@timholy
Copy link
Member

timholy commented Feb 7, 2020

Very dim memories clamoring for attention: https://github.com/timholy/MacroExpandJL.jl. Steal anything you find useful.

@ViralBShah
Copy link
Contributor

@ChrisRackauckas Do you still want this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants