Hacker News new | past | comments | ask | show | jobs | submit login

This is a really bad idea. It's not even close to useful right now. For instance, you can't use variables in your shell invocation, so this doesn't work:

    (let [x "/usr/local"] (ls -l x))
And it clobbers so many things in the core namespace when 'use'd.

Good luck.

> And it clobbers so many things in the core namespace when 'use'd.

Yes the ...it indexes all the executables in your path... is different to the approach used by Perl's Shell.pm and I think Python sh.

These simply catch any undefined function calls and attempts to execute them in the shell (found in your $PATH).

  use 5.016;
  use warnings;
  use Shell;
  say cat("~/.vimrc");              # runs /bin/cat
  say incorrect_spelled_command();  # ERROR can't find in $PATH
However nothing is clobbered here:

  sub cat { "This is my cat()!" }

  use Shell;
  say cat('~/.vimrc');  # => "This is my cat()!"  
The best approach is to not use the lookup dispatch and instead tell it what executable you want to wrap...

  use Shell qw(cat);
Now incorrect_spelled_execute is never passed to Shell.pm and in fact will give a compilation error (Undefined subroutine). And any cat() subroutine will be overwritten but it does give redefined warning.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact