On Sat, May 20, 2023 at 1:17 PM Dexter Plameras <[email protected]> wrote:
>
> As per the requirement before putting together a proposal, a discussion on 
> LHS inference for type assertions
>
> Currently, type assertions take the form of:
>
> //
> // Pre assertion
> //
> var original string = "Hello Type Assertions"
> var data interface{} = original // or "var data any"
>
> //
> // Assertions
> //
>
> // fails compiler checks
> destInt := data.(int)
>
> // passes compiler checks
> destString := data.(string)
>
> Proposal:
> Instead of a RHS type assertion, I'd like to propose a language change that 
> would take the type assertion as an inference from the LHS, potentially using 
> a new assignment operator.
>
> //
> // Pre assertion
> //
> original := "Hello Type Assertions"
> var data interface{} = original  // or var data any
>
> // LHS inference of the int type. Compiler checks fail. (notice the ".=" 
> assignment operator, it could be variation of the assignment operator that 
> makes it clearer)
> var destInt int .= data
>
> // LHS inference of the string type.
> var destString string .= data
> // or
> var destString string
> destString .= data
>
> This could potentially work with multiple RHS returns too.
> var data string
> var err error
> data, err .= function()
>
> I'm certainly no programming language expert but does this hold any value?

You didn't explain why the new syntax is better.  It doesn't seem any
clearer to me, so I don't see what we gain.  Thanks.

Ian

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVZt5LqwcnfjOFg%3DZOKjsSEe8gp2PY_jOxLPod2YNmnXQ%40mail.gmail.com.

Reply via email to