-
Notifications
You must be signed in to change notification settings - Fork 185
optval and module dependencies #574
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
Comments
I like the idea of using the pre-processor for internal use of
Would this not require the variables to be called exactly
Eventually fpm should tree-shake, i.e. build only the modules used by the project and not the whole stdlib, so this may in the future have an effect on fpm build as well. |
good point @ivan-pi
where result = $(myfunction( myvar1, myvar2, 0)}$ this would be available for all files if stored in |
Forgive me, I only glanced quickly through the fypp docs. I think the following macro is correct:
and can be called as follows:
producing the output
The downside is the assignment is hidden in the macro which makes it a bit cryptic. |
I see. And it can't be used in expressions, correct? |
Not in the form proposed by @ivan-pi because the macro will be replaced by the two lines before compilation. |
Correct, an expression implies having a function or using the F202X syntax:
This can in principle be wrapped in a macro:
which can be used as an expression using a similar syntax to the one Jeremie showed:
but IMO it doesn't feel worth the effort. I'm not sure if fypp macros can be overloaded, however you could pull both versions off in the same macro by using either the positional or keyword arguments that fypp supports. |
On the other side, are we not proposing a shortcut for a function ( |
Personally I'm not worried too much about the performance penalty. As long as not used in a performance-critical context I think it's handy. On the other hand with the new F202X conditional syntax I think The reason I wanted to suggest a preprocessor alternative was merely as a means of reducing inter-dependencies between modules, allowing users to "pick-n-play". You could argue that downloading three modules (kinds, optval, selection) instead of two (kinds, selection) is not a big difference. |
So there have been a few discussions about optval before:
merge
but create anotheroptval
? #448The former thread established the performance implications of sprinkling
optval
here and there are likely negligible. The latter thread established thatmerge
cannot be used as a replacement due to it's behavior interacting with thepresent
function, and also being unsuitable for variables of typecharacter(:), allocatable
. However, I think one comment from @zoziha is worthy of more attention:In my opinion the stdlib modules should be as independent as reasonably possible. This enables users to simply copy the sources of the modules they want to use, without having to climb up the module dependency tree. Now I realize this is a non-issue for those using stdlib via fpm, but some users might prefer to preserve their current build methods.
For source files that require the preprocessor anyways, it would be straightforward to provide a preprocessor version of optval instead:
An alternative variation is
however this one can result in some false positive warning about non-initialized arguments.
[Edit: hopefully the macros are correct now...]
The text was updated successfully, but these errors were encountered: