vlad_tepesch
vlad_tepesch

Reputation: 6883

octave history command - variable as filename

i want to write little helper functions that stores and loads the octave session.

function restoreSession(filename)
  history -r strcat('./states/',filename,'.history');
  load("-binary", strcat('./states/',filename,'.data')) 
endfunction


function saveSession(filename)
  history -w strcat('./states/',filename,'.history');
  save("-binary", strcat('./states/',filename,'.data')) 
endfunction

The save/load command works well. My Problem is that the history command seems not to evaulate the argument. it prodces the following error:

  syntax error

>>>   history -r strcat('./states/',filename,'.history');
                                                       ^

I already tried to use a temporary var for the path but in this case it only interprets the variable name as filename and complains about the missing file.

Does anybody has an idea how to solve this?

Upvotes: 1

Views: 437

Answers (1)

carandraug
carandraug

Reputation: 13091

Use history with the function syntax instead of a command.

history ("-r", strcat ("./states/", filename, ".history"));

All commands are actually functions. The command syntax (when you don't use parentheses) is available to all functions, it just happens that for some it looks more natural. When you omit the parentheses, all the arguments are interpreted as strings, even variable names. If you want to do something fancier, call them as functions.

Upvotes: 2

Related Questions