-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ysh exits after ctx push (&a) { true }
#1864
Comments
Thank you, this is now fixed! We forgot an error location.
You can get a new tarball here under |
I can see why there is confusiong between I guess this is what
|
This also suggests that our flag parser API could be
or
@PossiblyAShrub - there is some possible inconsistency between mutating a dict and rebinding a name Somehow I find But I can also take the @bar-g viewpoint and say that it is inconsistent :) I was trying to explain or emphasize mutability vs rebinding names. Kind of a subtle concept. I wish we didn't have that distinction. |
I basically wanted to save people from "declaring" spec, but maybe that's a false economy ??? This also has implications for Hay ! |
Hm, when compiling the tables in I my thought was to let Could that maybe also still and consistently save people from having to "declare" the var? My idea with that, though, initially was that I just wanted to save people from having to use special "place syntax" where ever it makes sense (and require the But as you mention it now, another nice aspect of both together could be that the mutating vs. rebinding difference may be practically gone. (People always pass places by default, when passing mutable ->things.) I think the mutating vs. rebinding difference would then merely remain relevant |
I prefer passing a place to For example -- and for fun :) -- we could make the spec a # args.ysh
proc flag (short, long) {
# We don't support `--indent -1` anymore?
json write --indent 0 ({'type': 'flag', short, long}) | tr --delete '\n'
echo # For a trailing newline
}
proc arg (name) {
json write --indent 0 ({'type': 'arg', name}) | tr --delete '\n'
echo
}
proc parser (; spec ;; block) {
call spec->setValue(block)
}
func parseArgs(spec, argv) {
try {
eval (spec) | python3 parser.py @argv | json read (&res)
}
if (_status !== 0) {
error "Bad Usage: See $0 --help" (status=2)
}
return (res)
}
parser (&spec) {
flag -v --verbose
arg file
}
var args = parseArgs(spec, :| --verbose README.md |)
= args # => (Dict) {"verbose":true,"file":"README.md"} # parser.py
import sys
import json
import argparse
nodes = [json.loads(l) for l in sys.stdin.readlines()]
parser = argparse.ArgumentParser()
names = []
for node in nodes:
if node['type'] == 'flag':
parser.add_argument(node['short'], node['long'],
action="store_true")
names.append(node['long'].removeprefix('--'))
elif node['type'] == 'arg':
parser.add_argument(node['name'])
names.append(node['name'])
# A bit of a pain to serialize the argparse.Namespace class...
args_namespace = parser.parse_args()
args = {}
for name in names:
args[name] = getattr(args_namespace, name)
json.dump(args, sys.stdout) I think that the "pass a place" pattern is a good practice for when you don't care about internal structure but will instead forward the value to another func/proc in the API. (This is a one way implication, there are other reasons why you'd want to pass by place. eg. Why shouldn't |
Hm, now I'm confused. That sounds as if it is not possible to create a place that points to an existing var, and as if If that's the case, couldn't Idea again is to using places in much more situations (everything with |
Hm very interesting ... I think there are two sides to this, technical and philosophical
BUT if that's the case, then this line means almost nothing:
You can argue it's just "noise". I think this is a pretty good argument for I am still a little bugged by Even Elixir has it I think We didn't invent that problem and |
Ha, yes. I think, you could be the first with a valuable |
Hm, I'm still pondering on this:
Or more precisely, if that would be technically possible for
And then, when calling [Precision added:]
|
The main reason the It has to be designed in the context of real code. |
That's only one of different design "methods". My gripes are rather principles like
|
oh, sorry commented at wrong thread, the ctx topic is now: |
I somehow wrongly used a place and ysh terminated:
The text was updated successfully, but these errors were encountered: