How do I transfer string status into a check code?

Exactly how should I do this?

foo_call_this_command:
check ${_foo_string_to_append}
_foo_string_to_append:
u "const a=5;
 a=[$1,$2];
 b=[3,4];
 set('var',avg(a););
 a[0]>b[0]&&a[1]<b[1];
 "

Here’s why, I have a big block of code that can be reused in two different command, and it is in this form. So, how would I do this? So, the only way this can work is copy and pasting, but I’d rather reuse it.

Some thoughts:

  • ${_foo_string_to_append} won’t call the command named _foo_string_to_append but will return the value of the variable names _foo_string_to_append (which is not what you want here, as this variable is probably empty).
  • You probably meant ${-_foo_string_to_append}.
  • I would expect that your command _foo_string_to_append returns a boolean value (0 or 1), which is not the case here : currently, it returns a string.

Probable fix:

foo_call_this_command:
  check ${"-_foo_string_to_append arg0,arg1"}

_foo_string_to_append:
  u {"const a = 5;
      a = [ $1,$2 ];
      b = [ 3,4 ];
      set('var',avg(a)); # Useless here, as that will be a local variable to your command.
      a[0]>b[0] && a[1]<b[1];"}
1 Like

I think that I have a better idea, and I remember you can set '{}' in set(), so you can pass var.

Recall that this would allow variable length arguments and define where to put this:

foo_ab:
a,b="1,2,3,4","5"

I would like to be able to return “1,2,3,4”,“5” from the alternate command.

Here:

foo_ab:
a,b=${-foo_alternate}
foo_alternate:
check "set('{}',v2s(_'\"',[1,2,3,4],_'\"',_',',_'\"',[5],_'\"'));1"

Yes, it has to be like this though, and yes I was using check.

Right now, v2s() creates a lot of zeros, which I don’t want.

The other approach is to use set() on two different variable, and concatenate it. It doesn’t work either because it is treated as 5 variables.