go - Early or late argument evaluation in golang? -


in program series of sequential checks in manner:

var value int  if !(parseorfail(inputstrval, &value) &&      validate(value)) {     return someerr } 

i know validate called if parseorfail returns true, i'm not sure whether in such scenarios updated value.

is correct so? or must pass pointer validate ?

playground link: https://play.golang.org/p/l6xhbgqjfs

the go programming language specification

expressions

an expression specifies computation of value applying operators , functions operands.

operands

operands denote elementary values in expression. operand may literal, (possibly qualified) non-blank identifier denoting constant, variable, or function, method expression yielding function, or parenthesized expression.

order of evaluation

at package level, initialization dependencies determine evaluation order of individual initialization expressions in variable declarations. otherwise, when evaluating operands of expression, assignment, or return statement, function calls, method calls, , communication operations evaluated in lexical left-to-right order.

calls

given expression f of function type f,

f(a1, a2, … an) 

calls f arguments a1, a2, … an. except 1 special case, arguments must single-valued expressions assignable parameter types of f , evaluated before function called. type of expression result type of f. method invocation similar method specified selector upon value of receiver type method.

logical operators

logical operators apply boolean values , yield result of same type operands. right operand evaluated conditionally.

&&    conditional ,    p && q   "if p q else false" ||    conditional or     p || q   "if p true else q" !     not                !p       "not p" 

the behavior of code defined in go programming language specification.

var value int  if !(parseorfail(inputstrval, &value) && validate(value)) {     return someerr  } 

or, in pseudocode,

parseorfail arguments evaluated parseorfail called if parseorfail == true     validate arguments evaluated     validate called 

that is, in example (https://play.golang.org/p/l6xhbgqjfs), late evaluation.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -