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

Add a way to get the current function name #1743

Closed
xdudi opened this Issue Oct 6, 2014 · 4 comments

Comments

Projects
None yet
6 participants
@xdudi

xdudi commented Oct 6, 2014

~> function test_func
       echo $_ $argv
   end
~> test_func (seq 10)
test_func 1 2 3 4 5 6 7 8 9 10
~> eval test_func (seq 10)
eval 1 2 3 4 5 6 7 8 9 10             # should be test_func
~> 

I would suggest to add %this as equivalent of $_ for return function/script name.

@kballard

This comment has been minimized.

Show comment
Hide comment
@kballard

kballard Oct 10, 2014

Contributor

What makes you say this is the wrong value?

$_ is set by the interactive reader. You'll notice that echo 'echo _="$_"' | fish or fish -c 'echo _="$_"' both print _=, because the $_ variable isn't even set there. Because there's no interactive reader.

Which is to say, when you run the line eval test_func (seq 10), the interactive reader assigns $_ = "eval", and then the job run by eval itself, by virtue of not being an interactive read, doesn't touch $_.

Which is to say, this is behaving correctly. $_ contains the name of the command typed by the user.

And %this would not be appropriate, as % is the process expansion token.

If you want a way to get the name of the currently-executing function, then the best bet is to teach status how to do that. But why do you even need this? Surely the test_func function already knows that its name is test_func.

Contributor

kballard commented Oct 10, 2014

What makes you say this is the wrong value?

$_ is set by the interactive reader. You'll notice that echo 'echo _="$_"' | fish or fish -c 'echo _="$_"' both print _=, because the $_ variable isn't even set there. Because there's no interactive reader.

Which is to say, when you run the line eval test_func (seq 10), the interactive reader assigns $_ = "eval", and then the job run by eval itself, by virtue of not being an interactive read, doesn't touch $_.

Which is to say, this is behaving correctly. $_ contains the name of the command typed by the user.

And %this would not be appropriate, as % is the process expansion token.

If you want a way to get the name of the currently-executing function, then the best bet is to teach status how to do that. But why do you even need this? Surely the test_func function already knows that its name is test_func.

@ridiculousfish ridiculousfish added this to the fish-tank milestone Nov 1, 2014

@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Sep 2, 2015

Member

No info in >6 months. Closing.

Member

faho commented Sep 2, 2015

No info in >6 months. Closing.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Oct 18, 2015

Any chances we can revive this?

See #2492

But why do you even need this? Surely the test_func function already knows that its name is test_func.

Because it is a good practice to not repeat oneself and I may be looking for a way to automate something like displaying a usage message, etc.

then the best bet is to teach status how to do that.

Any chance to teach a variable instead? 😄

ghost commented Oct 18, 2015

Any chances we can revive this?

See #2492

But why do you even need this? Surely the test_func function already knows that its name is test_func.

Because it is a good practice to not repeat oneself and I may be looking for a way to automate something like displaying a usage message, etc.

then the best bet is to teach status how to do that.

Any chance to teach a variable instead? 😄

@faho faho reopened this Oct 18, 2015

@faho faho removed the needs more info label Oct 21, 2015

@faho faho changed the title from "$_" has wrong value to Add a way to get the current function name May 21, 2016

@krader1961 krader1961 modified the milestone: fish-tank Nov 17, 2016

@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Mar 18, 2017

Contributor

Note that we already have status print-stack-trace (which includes the name of the current function) and status current-filename. Adding status current-funcname is not unreasonable and probably straightforward.

Contributor

krader1961 commented Mar 18, 2017

Note that we already have status print-stack-trace (which includes the name of the current function) and status current-filename. Adding status current-funcname is not unreasonable and probably straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment