load with arguments and value returning.

Skip to first unread message

Kaz Kylheku

Jun 12, 2023, 12:28:24 PMJun 12
I've experimented with a feature and shipped it.

What if the load function could pass arguments to the loaded file?

I designed it like this.

1. Extra arguments in load get implicitly bound to a special variable
called *load-args*.

2. If all the forms (or compiled forms) in the file are are evaluated,
and terminate normally, load returns nil.

3. The loaded file can evaluate (return-from load) to prevent the
remaining forms from being evaluated. Control passes to load.
If (return-from load <value>) is specified, load will return
that value, otherwise nil.

This may seem like a trifling thing, of no consequence, but it's looking
like a "game changer". Loaded files can be functions now, and they can be
procedures that modify their behavior based on arguments. It's looking
very convenient for build scripting; doing the cruft around getting a
multi-component system constructed.

You can do a recursive load across a tree of files, while telling those
recursive loads to do different things: compile files, clean, ...

TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazi...@mstdn.ca
Reply all
Reply to author
0 new messages