On Mar 1, 2020, at 12:43 PM, Ian Lance Taylor <i...@golang.org> wrote: > > On Sun, Mar 1, 2020 at 8:21 AM Warren Stephens > <wsteph...@prognoshealth.com> wrote: >> >> // I don't want to get into the specific syntax of the test code directly, >> // but a test would start execution here, supplying "lines" and "thing2" >> // >> mystep2 with: lines, thing2 // <---------- hide all local variables from >> above except for lines and thing2 >> >> mymap := make(map[string]int) >> for _, line := range lines { >> if strings.Contains(line, thing2) { >> count := strings.Count(line, thing2) >> mymap[line] = count >> } >> } >> >> // and the test would end here -- because the next line is another "with" >> (or return) statement >> // it would be able to do Asserts and such on the variables within the scope >> of this code segment >> >> Ian, >> >> An alternative approach would be to have: >> >> mystep2 with: lines, thing2 => mymap >> >> to specify all of the intermediate variables of interest for the test. >> >> These testable code chunks, delimited by with statements, act like hidden >> funcs. The actual call could be something like test_doSomeStuff@mystep2 > > To me this all seems very unlike anything else in the Go language. > There is nothing syntactically similar to this anywhere else. I think > it is extremely unlikely that Go would adopt this idea.
What Warren wants seems something like "Hoare Logic", where you have a notation such as P{C}R where P & R are assertions and C is a block of code. If precondition P is satisfied, after executing C the postcondition Q will be satisfied. This can be used to build up in a stepwise manner the correctness "proof" of a function. See C.A.R.Hoare's 1969 paper, "An Axiomatic Basis for Computer Programming" http://extras.springer.com/2002/978-3-642-63970-8/DVD3/rom/pdf/Hoare_hist.pdf You can already do the equivalent of this in Go today if you want. IMHO any additional syntax doesn't seem to buy anything. If my guess is wrong, perhaps Warren can try to clearly describe the exact *semantics* he wants? [Always a good idea!] -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/AF8FBEDE-9F72-4278-9172-5AD693D07DDB%40bitblocks.com.