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

Add ternary operation in stockflow macro syntax #135

Merged
merged 6 commits into from
Oct 20, 2024

Conversation

neonWhiteout
Copy link
Collaborator

Allows use of the syntax A = B ? C : D in a dynamic variable, where B, C and D can be symbols or expressions. An expression of this form is converted into a function call cond(B,C,D) = B ? C : D

@neonWhiteout neonWhiteout requested a review from Saityi October 13, 2024 06:59
@neonWhiteout
Copy link
Collaborator Author

Probably wanna try actually running the differential equations on one of these. If you have an example which uses an if else in another software, try porting it.

@Saityi
Copy link
Collaborator

Saityi commented Oct 15, 2024

The changes look good to me, notwithstanding the current failing notebooks validation.

We should probably make sure the docstrings at https://github.com/AlgebraicJulia/StockFlow.jl/pull/135/files#diff-4e1b9ec77867b43e29dfce6850ad2d9cab1373bef6eed4a38ac4b5c29f94c2a7L5 and https://github.com/AlgebraicJulia/StockFlow.jl/pull/135/files#diff-4e1b9ec77867b43e29dfce6850ad2d9cab1373bef6eed4a38ac4b5c29f94c2a7L116 are kept up-to-date

(I.e., the module-level docstring and the docstring on the stock_and_flow macro.

@neonWhiteout
Copy link
Collaborator Author

@Saityi I did a few changes so || and && can be used as well. Just convert A || B to or(A, B) := A || B and A && B to and(A,B) := A && B

@neonWhiteout
Copy link
Collaborator Author

neonWhiteout commented Oct 18, 2024

@Saityi I did a few changes so || and && can be used as well. Just convert A || B to or(A, B) := A || B and A && B to and(A,B) := A && B

...Which is stupid, because || and && only allow bools. I guess we do:
or(A, B) := int(Bool(A) || Bool(B))

...Eh, guess we don't need that outer int wrap

@neonWhiteout
Copy link
Collaborator Author

...No, no, it might still work, since A < B should return a bool

@neonWhiteout neonWhiteout merged commit 57b3c8f into AlgebraicJulia:main Oct 20, 2024
9 checks passed
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

Successfully merging this pull request may close these issues.

2 participants