How to assign from a function which returns more than one value?

Still trying to get into the R logic… what is the “best” way to unpack (on LHS) the results from a function returning multiple values? I can’t do this apparently: R> functionReturningTwoValues <- function() { return(c(1, 2)) } R> functionReturningTwoValues() [1] 1 2 R> a, b <- functionReturningTwoValues() Error: unexpected ‘,’ in “a,” R> c(a, … Read more

How can I index a MATLAB array returned by a function without first assigning it to a local variable?

For example, if I want to read the middle value from magic(5), I can do so like this: M = magic(5); value = M(3,3); to get value == 13. I’d like to be able to do something like one of these: value = magic(5)(3,3); value = (magic(5))(3,3); to dispense with the intermediate variable. However, MATLAB … Read more

How to get the return value from a thread in Python?

The function foo below returns a string ‘foo’. How can I get the value ‘foo’ which is returned from the thread’s target? from threading import Thread def foo(bar): print(‘hello {}’.format(bar)) return ‘foo’ thread = Thread(target=foo, args=(‘world!’,)) thread.start() return_value = thread.join() The “one obvious way to do it”, shown above, doesn’t work: thread.join() returned None. 22 … Read more