FAQ
I'm doing something a little cooky and I'm hoping I might just be missing
something in the reflect/runtime package.

I'm looking for a way to extract the value of a variable's arguments, if
the variable is a function type. So if I had:

var x = func("hello")

I want to extract blah's 0 argument value, "hello".

I can see how to get the type of the value using reflect.TypeOf(x).In(0),
but can't see a way to get the value.

I'm assuming that there isn't, but figured I'd ask before I moved onto
another method for what I'm doing.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Nodir Turakulov at Oct 19, 2015 at 12:26 am
    You can't get a value of an arg from a function type because a function
    type is not a function call (the func wasn't called yet).
    You also can't get a value of an arg from a return value of the func.

    `var x = func("hello")` is not valid Go.
    What is blah?

    Please provide more context.
    On Sun, Oct 18, 2015 at 5:21 PM John wrote:

    I'm doing something a little cooky and I'm hoping I might just be missing
    something in the reflect/runtime package.

    I'm looking for a way to extract the value of a variable's arguments, if
    the variable is a function type. So if I had:

    var x = func("hello")

    I want to extract blah's 0 argument value, "hello".

    I can see how to get the type of the value using reflect.TypeOf(x).In(0),
    but can't see a way to get the value.

    I'm assuming that there isn't, but figured I'd ask before I moved onto
    another method for what I'm doing.

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jesse McNelis at Oct 19, 2015 at 12:45 am

    On Mon, Oct 19, 2015 at 11:20 AM, John wrote:
    I'm doing something a little cooky and I'm hoping I might just be missing
    something in the reflect/runtime package.

    I'm looking for a way to extract the value of a variable's arguments, if the
    variable is a function type. So if I had:

    var x = func("hello")

    I want to extract blah's 0 argument value, "hello".

    I can see how to get the type of the value using reflect.TypeOf(x).In(0),
    but can't see a way to get the value.

    I'm assuming that there isn't, but figured I'd ask before I moved onto
    another method for what I'm doing.
    Yes, there is no way to do this.
    You can only do reflect on values and someFunc("hello") isn't a value,
    it's an expression.

    Perhaps if you told us why your want to do this we might be able to
    suggest a better way of achieving your goal.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • John Doak at Oct 19, 2015 at 12:54 am
    Thanks for the quick response. Not worth going into the details, I just
    wanted to confirm what I thought I already knew (I've got a few 100k lines
    of Go behind me, but I'm always surprised by something I didn't know which
    is really rewarding, the Func stuff in the runtime for example). In this
    real corner case, would have been nice, but its not the only way to skin
    the cat.

    Thanks, again.

    John
    On Sun, Oct 18, 2015 at 5:45 PM, Jesse McNelis wrote:
    On Mon, Oct 19, 2015 at 11:20 AM, John wrote:
    I'm doing something a little cooky and I'm hoping I might just be missing
    something in the reflect/runtime package.

    I'm looking for a way to extract the value of a variable's arguments, if the
    variable is a function type. So if I had:

    var x = func("hello")

    I want to extract blah's 0 argument value, "hello".

    I can see how to get the type of the value using reflect.TypeOf(x).In(0),
    but can't see a way to get the value.

    I'm assuming that there isn't, but figured I'd ask before I moved onto
    another method for what I'm doing.
    Yes, there is no way to do this.
    You can only do reflect on values and someFunc("hello") isn't a value,
    it's an expression.

    Perhaps if you told us why your want to do this we might be able to
    suggest a better way of achieving your goal.


    --
    John Doak
    www.obscuredworld.com

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 19, '15 at 12:21a
activeOct 19, '15 at 12:54a
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase