thanks

yes, i think i have understood. as you said, fn is a value not a function 
call, the thing that we defer a function call means it will be called 
later. if we defer a fn not a fn(), the compile doesn't know you want to 
call a function later 



On Monday, January 29, 2018 at 12:29:56 AM UTC+8, Michael Jones wrote:
>
> Flying, another way to think of it is that fn is not a function call, it 
> is a function pointer value--a value just like 3.14 or "true." It would not 
> make sense to defer a value, since defer is about "defer the invocation of 
> a function." We make the function value fn become a function invocation by 
> appending the "()" to it. This is the reason. As others have said, this is 
> also good because it gives you a place to pass the parameters that usually 
> are needed "defer close(file)" and because the meaning of this can be 
> subtle (when do you record the value of file so that you can know it when 
> close is eventually called.)
>
> On Sun, Jan 28, 2018 at 12:39 AM, Doğan Kurt <kultig...@gmail.com 
> <javascript:>> wrote:
>
>> how will you pass parameters if its defer fn?
>>
>>
>> On Sunday, January 28, 2018 at 3:42:03 AM UTC+1, Flying wrote:
>>>
>>> example :
>>> fn := func() {
>>>      fmt.Println(10)
>>> }
>>> defer fn()
>>>
>>>
>>> my question is why use defer fn() not defer fn
>>>
>>>
>>> when we use fn() here doesn't it mean call it now ???
>>>
>> -- 
>> 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...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Michael T. Jones
> michae...@gmail.com <javascript:>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to