dundalek / closh

Bash-like shell based on Clojure
Eclipse Public License 1.0
1.61k stars 65 forks source link

Fix: exit (/quit) should allow zero arguments call #100

Closed jeroenvandijk closed 5 years ago

jeroenvandijk commented 5 years ago

Like the doc string and to prevent unexpected behaviour

ArityException Wrong number of args (0) passed to: builtin/exit  clojure.lang.AFn.throwArity (AFn.java:429)

I also find this inconsistent with bash:

$ exit 2
ClassCastException java.lang.String cannot be cast to java.lang.Number  closh.zero.platform.process/exit (process.clj:18)

I would say if it's an alias to a bash function it's should behave like a bash function? WDYT?

dundalek commented 5 years ago

You are totally right, these are bugs.

The command mode passes arguments as strings, therefore exit 2 passes string which fails, but (exit 2) reads it as a number and is ok. I think that can be fixed by trying to cast the string to a number.

jeroenvandijk commented 5 years ago

Would something like this be handy https://github.com/wilkerlucio/spec-coerce/ ?

I read that parsing issue of an ip address was a reason to fork tools.reader. This is a different issue, but also related to coercing. Maybe it is/will be a recurring theme?

dundalek commented 5 years ago

Turns out the reader already does coercion, but then the shell argument expansion stringifies things. So I think I will be able to come with a fix for it in a better place.

dundalek commented 5 years ago

The coercion should be fixed with this: https://github.com/dundalek/closh/commit/8d90aec84c20e297332d8d269cab7ca30de3be8a