oils-for-unix / oils

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.85k stars 159 forks source link

Move procs to variable namespace #2028

Closed PossiblyAShrub closed 4 months ago

PossiblyAShrub commented 4 months ago

Supersedes: #2025

Redoing the implementation now that we know more about the design and possible issues.

PossiblyAShrub commented 4 months ago

This is ready for a review.

PossiblyAShrub commented 4 months ago

This is ready for another review.


Btw, I did find that my changes have this behavior:

$ hello() {
>   echo hello
> }
$ var hello = 'hi'
$ hello
"hello"

I'm not sure if this is what we want to do here. Should this be correct?

andychu commented 4 months ago

This is ready for another review.

Btw, I did find that my changes have this behavior:

$ hello() {
>   echo hello
> }
$ var hello = 'hi'
$ hello
"hello"

I'm not sure if this is what we want to do here. Should this be correct?

OK I guess what's happening is that

Hm I guess the exact rules are up for debate ...

You could argue that if the name is found in the var namespace, it could show an error "not a proc"


This would possibly have some annoying consequences like:

var ls = 42
ls   # external ls should still work ???   

I don't think the behavior you showed is bad though, I guess because it doesn't make sense to call the string "hi" anyway

I think we can leave it as is for now, and perhaps iterate

PossiblyAShrub commented 4 months ago

I think we can leave it as is for now, and perhaps iterate

Sounds good.

Are there any other blockers on this PR before we merge?

andychu commented 4 months ago

Looks good, thanks!

I merged, though now that I think about it, if Del() is only for sh_funcs, then I think GetNames() should be too

I think we should change declare -F and compgen -A function to only list shell functions

procs are now something "different" ... I think we might have compgen -A proc and so forth


Actually declare -F like is dir() ! I remember I wanted to write a blog post about how I used dir() and getattr() to learn Python, not reading the docs

We want that property too

It also reminds me that our object model is too weak ... maybe we should be able to have


If you agree about excluding procs out of GetNames(), please send a follow-up

andychu commented 4 months ago

I am also thinking of things about our "meta-object model", like Python has

I think we might want something like __invoke__

All these things can be "invoked" like a command: