samer@4: % repl - Read-eval-print loop. samer@4: % samer@4: % repl :: samer@4: % string ~'command line prompt', samer@4: % E:struct ~'structure fields to put in current environment', samer@4: % -> {...}. samer@4: % samer@4: % Runs an embedded command interpreter much like the Matlab top-level. samer@4: % The second argument E is available as a value with the name E in the environment. samer@4: % The environment can be examined using WHO or WHOS as usual, but there will be samer@4: % some other variables visible that are internal to repl - they all end with two samer@4: % underscores so they can be easily recognised. samer@4: % The repl can return any number of values, but the values must be placed samer@4: % by calling the ret(...) function within the repl. samer@4: samer@4: function varargout=repl(pr__,E) samer@4: fprintf('\n\nEntering REPL. Type "return","exit", or "quit" to finish.\n'); samer@4: fprintf('The function ret(..) sets return values.\n\n'); samer@4: cont__=true; samer@4: returns__={}; samer@4: while cont__, samer@4: str__=input([pr__,'>> '],'s'); samer@4: if strcmp(str__,'quit') break; end samer@4: if strcmp(str__,'exit') break; end samer@4: if strcmp(str__,'return') break; end samer@4: try, eval(str__) samer@4: catch ex__ samer@4: fprintf('\n%s\n',getReport(ex__)); samer@4: end samer@4: end samer@4: varargout=returns__; samer@4: samer@4: function ret(varargin), returns__=varargin; cont__=false; end samer@4: end