Is it possible to write a function in CL that takes a numerical parameter (or even multiple) and returns a string?
Like if I have variables a=-3 and b=4 that I want to send to it and return some sort of string (intending to send more than one variable to the same function).
function(input):
when input < 0 "${input}"
when input >0 "+${input}"
otherwise ""
function(a) would return “-3”
function(b) would return “+4”
I know how to do this by defining two separate variables but wondering if there is a more efficient way with a function like this?
Sorry - not yet. For functions like “format these numbers to output an equation”, there’s also a good chance that could be a built-in function within CL. There are a lot of tricky conditions like “leave this term out if the coefficient is zero” and “leave out the “+” if all the previous terms were left out”. I’d be interested in seeing what you’re working on / trying to do.
I used to have something when I did script work in some google apps scripts around coefficients for equations to try and clean up the math. I had one function for coefficients that would rewrite expressions to subtraction when there were negative coefficients present, eliminate the coefficient when the value was 1 and leave nothing if the constant value was zero. I feel like it’d be super helpful to have a function like that to avoid having to anticipate so many scenarios for outcomes if that makes sense.
This is the code I had in google apps script that did what I’m talking about: