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

Hay Attr nodes could record procs defined within them #1179

Open andychu opened 2 years ago

andychu commented 2 years ago

I think this is kind of clever -- procs are a flat namespace. But you can at least attach the name to the Hay node.

I think it will be useful for proc annotations

andychu commented 2 years ago

Example:

hay define AnnotatedProc

AnnotatedProc {
  class = 'pure'

  proc foo {  # even though it's nested, it's registered in the flat proc namespace?
    echo 'foo'
  } 
}

And that evaluates to something like

{ "type": "AnnotatedProc",
  "args": [],
  "attrs": {"class": "pure"},
  "procs_defined": "foo",
}

And then you can read that JSON, read the annotations, and then re-execute proc with the $0 dispatch pattern.

Type Expressions

Or even something like

List = symbol()  # an atom where `[]` operator preserves the tree structure
Int = symbol()

AnnotatedProc foo {
  return_type = List[Int]

  proc foo {
    echo hi
  }
}