Skip to content

Proposal: FileIO.save keyword argument syntax (FileIO.kwsave ?) #324

@JonasIsensee

Description

@JonasIsensee

I've added a new syntax to JLD2 and I'm wondering if this could be made compatible with FileIO.

Current example using FileIO:

x = 1
y = 2
z = 42
save("test.jld2", "x", x, "y", "zebra", z)
# or
save("test.jld2", Dict("x" => x, "y" => y, "zebra" => z))

This is clearly very verbose, particularly when variable names are long.
However, this could be made much cleaner if we use keyword argument syntax instead

using JLD2
jldsave("test.jld2"; x, y, zebra=z)

What's great about this, is that we use standard julia syntax and let the parser do the work of extracting
variable names. Until now this was only possible using the @save and @load macros from e.g. BSON, JLD, or JLD2
but these macros introduce odd (and limited) syntax and keep being misunderstood by newcomers.

I'm aware that kwarg stuff is typically not type-stable but this is rarely important when IO is involved.

The problem:
There already is a single-positional-argument method for FileIO.save that returns an anonymous function
to be used with pipes.

What do you think?
Is this interface idea useful enough to add it to FileIO in some way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions