Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeedt0.toon.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail
From: Ralph Schleicher <rs+usenet@nunatak.allgaeu.org>
Newsgroups: comp.soft-sys.matlab
Subject: Re: running other applications
Date: Fri, 06 Jul 2007 22:25:35 +0200
Organization: Development Proletcult Cadre #23
Lines: 61
Message-ID: <87tzshcm9s.fsf@bravo.nunatak.allgaeu.org>
References: <ef5c942.0@webcrossing.raydaftYaTP> <ef5c942.1@webcrossing.raydaftYaTP> <ef5c942.2@webcrossing.raydaftYaTP> <f6lh2p$4ie$1@fred.mathworks.com> <1183731582.111910.293480@w3g2000hsg.googlegroups.com> <ef5c942.6@webcrossing.raydaftYaTP> <muy3b01qvfh.fsf@G99-Boettcher.llan.ll.mit.edu>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.t-online.com 1183754707 01 28991 bMFx6N5JLMR0ky4 070706 20:45:07
X-Complaints-To: usenet-abuse@t-online.de
X-ID: bo0P9iZrge42TXk-E2CyHFEN1yhaLR8eOwsLep9cG4+zwAiLCi5H4J
X-Face: &_l@,v,={27&f~U1u&T}}@PiTrV\4A7due$J*se+PiDvOWS][xPeQt/3_5MBC6]tT}a;0te%<^Tv]Qog%#OsE;AeVgoye>u/9@!Z`$>v[(=ps'%<XU:rR5C&EGM#$R~mH2[#Z;
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)
Cancel-Lock: sha1:kcyI51rnDNZgY/iyMIxR7xhhhjg=
Xref: news.mathworks.com comp.soft-sys.matlab:417660



Peter Boettcher <boettcher@ll.mit.edu> writes:

> Code that passes through CSSM that uses eval usually indicates one of
> several problems:

Real programmers require eval because of:

- Command/function duality, i.e. 'foo bar [1 2; 3 4]' should be
  equal to foo('bar', [1 2; 3 4]).  Therefore,

    function foo(a, b)
      a = foo_eval(a);
      b = foo_eval(b);
      % More stuff...

    function val = foo_eval(arg)
      if exist(arg)
        val = arg;
      else
        val = evalin('base', arg, 'arg');
      end

- Feature checking:

    if ~ eval('foo(''bar'')', '0')
      error('Require at least Foo version 2.0');
    end

  There is no existin:

    if ~ evalin('base', sprintf('exist(''%s'', ''var'')', var))
      error(sprintf('Variable ''%s'' does not exist in the Matlab workspace', var));
    end

- Parsing tricks:

    str = getenv('PATH');
    str = strrep(str, '''', '''''');
    str = strrep(str, ':', '''; ''');
    str = eval(['{''', str, '''}']);

  And another one, a Matlab lexer:

    function tok = mlex(str)
      eval(['mlex1 ', str, ' ;']);
      % It's magic!
      tok = ans;

    function arg = mlex1(varargin)
      arg = varargin;

The lexer is my favorite, took me some time to work it out.

> So there have it.  Computationally slow,

I like eval, but this is probably related to my Lisp background.

-- 
Ralph

Lisp programmers know the value of everything and the cost of nothing.