Skip to content

Commit

Permalink
[doc/proc-func] Update with block arg as expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Apr 13, 2024
1 parent 610e5e6 commit 645b28c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
17 changes: 8 additions & 9 deletions doc/proc-func.md
Expand Up @@ -465,8 +465,7 @@ This table shows simpler, more common cases.
Like funcs, procs have 2 kinds of typed args/params: positional and named.

But they may also have **string aka word** args/params, and a **block**
arg/param. (The block param is passed as a typed, positional arg, although
this detail usually doesn't matter.)
arg/param.

In general, a proc signature has 4 sections, like this:

Expand All @@ -479,14 +478,19 @@ In general, a proc signature has 4 sections, like this:
echo 'body'
}

In general, a proc call looks like:
In general, a proc call looks like this:

var pos_args = [3, 4]
var named_args = {foo: 'bar'}

p /bin /tmp (1, 2, ...pos_args; n1=43, ...named_args) {
echo 'block'
}

The block can also be passed as an expression after a second semicolon:

p /bin /tmp (1, 2, ...pos_args; n1=43, ...named_args; block)

<!--
- Block is really last positional arg: `cd /tmp { echo $PWD }`
-->
Expand Down Expand Up @@ -604,7 +608,7 @@ Some simpler examples:
<td>

proc my-cd (dest; ; ; block) {
cd $dest (block)
cd $dest (; ; block)
}

</td>
Expand Down Expand Up @@ -788,9 +792,6 @@ In summary:
is wrong.
* and they take blocks.
One issue is that procs take block arguments but not funcs. This is something
of a syntactic issue. But I don't think it's that high priority.
-->

## Summary
Expand Down Expand Up @@ -823,9 +824,7 @@ code shared. This code is mostly in [ysh/func_proc.py]($oils-src).
- [Block Literals](block-literals.html) (in progress)

<!--
TODO: any reference topics?
-->

<!--
Expand Down
1 change: 0 additions & 1 deletion ysh/func_proc.py
Expand Up @@ -17,7 +17,6 @@
from core import state
from core import vm
from frontend import lexer
from frontend import location
from frontend import typed_args
from mycpp import mylib
from mycpp.mylib import log, NewDict
Expand Down

0 comments on commit 645b28c

Please sign in to comment.