Search code examples
maxima

Return an error if the parameters are empty


I have function for example:

bagman(a, b) := (c:length(a), b+c)

And I would like to check parameter 'a' whether is empty. If it is empty this return information for example:

print("Parameter a is empty")

I tried this:

bagman(a, b) := (if length(a) = 0 then return(print("anything")), c:length(a), b+c)

but not work.


Solution

  • return doesn't have the same effect in Maxima as it does in other languages.

    How about this:

    bagman(a, b) :=
      if length(a) = 0
        then print("anything")
        else (c:length(a), b+c);
    

    Note that I put the normal operation stuff (c:length(a), b+c) into the else so it doesn't get evaluated when length(a) = 0.