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

Proposal: implement a macro system for YSH #1872

Open glyh opened 8 months ago

glyh commented 8 months ago

Macros are powerful tools for writing concise yet powerful codes. For now YSH doesn't seem to have one, however.

Pros

Cons

Macros or Reflections

Reflection is strictly a subset of lisp-style macros. For lisp people, reflection(code as data) is just an outcome of 'homoiconicity'. But sheer reflection is not enough for writing some useful language constructs as this would require us to introduce dynamic scoping, which is scary(perf penalty, spaghetti code). A proper macro system along with reflection can actually get the work done.

Implementatoin Issues

If I remember correctly, ysh parses the code staically, so there might be some modifications on the parser's side to delegate AST construction to the macro system. I personally prefer to have macro epansion as a single layer before execution, i.e. our macro system is more like racket's than common lisp's(main difference being whether you can expand a macro in runtime or not)

Inspirations

Further information

I would like to help implementing this if the maintainer is interested. For now I think we need to collect more opinons from developers and end-users.

glyh commented 8 months ago

Seems to be a duplicate of reflective system.

glyh commented 7 months ago

Reopened as only macros can solve scoping issues. https://oilshell.zulipchat.com/#narrow/stream/384942-language-design/topic/Semaphores.3F/near/431423521

I also refined the description with some information comparing macros and reflection.