Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
/ IfElse.jl Public archive

Under some conditions you may need this function

License

Notifications You must be signed in to change notification settings

SciML/IfElse.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IfElse.jl

Build Status

Sometimes, it's good to have a function form of a conditional. Julia's Base defines ifelse for this, but... psyche, it's not defined in Base but in Core! While this rarely matters, if you're trying to define a new dispatch for Core.ifelse you will find an interesting error message:

julia> Base.ifelse(x::Array,y,z) = 2x
ERROR: cannot add methods to a builtin function
Stacktrace:
 [1] top-level scope at none:1

Thus no new methods can be added to this function in its current form, blocking symbolic libraries like ModelingToolkit.jl or vectorization libraries like LoopVectorization.jl from extending the operations of this function onto their own types.

To get around this issue, we need a separate version of ifelse that is extendable. This is difficult to do in the standard case without any inference issues, though it is being worked on in this PR. In the meantime, to allow for development of ifelse dispatches from a common platform, IfElse.jl has been created to hold this common definition.

Thus IfElse.jl does one thing: it defines IfElse.ifelse to call Core.ifelse on its fallbacks, but be free to extend. This way, all of the libraries that want to extend an ifelse function can do so on a common form. If and when #37343 is fixed, this function will be deprecated for an extendable Base.ifelse, but for now it will allow for the thriving package ecosystem to continue its development in this area.

About

Under some conditions you may need this function

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages