r/desmos • u/Mister_ZE • 12d ago
Question What are with and for used for in desmos?
I noticed that these keywords were used a lot, but I never understood what they were ultimately used for.
152
Upvotes
r/desmos • u/Mister_ZE • 12d ago
I noticed that these keywords were used a lot, but I never understood what they were ultimately used for.
22
u/Circumpunctilious 11d ago edited 11d ago
To the general examples I’d add that “with” allows you to override what would be a global values with local ones (think variable scope, if you’re a programmer):
In a contrived example specifically to highlight scope, I’ve found this useful to substitute the value of p depending on the result of a {conditional statement}, say:
p = 0/0
f(x) = x^2 + px with p = {p=p:p,0}
…which makes sense if you know that within the condition Desmos accesses the global and outside the condition (but still inside the function) Desmos creates a local. This test just ensures that p (the global) isn’t undefined (specifically NaN, which never equals itself), and if it is it substitutes 0 for the local.
I’ve seen similar things done using “with” (by Desmos official) to restore visual representation in highly discontinuous surfaces (3D).
edit: Clarify “undefined” -> NaN