我知道在各种编程语言中都有一种 block 语法来简化对对象的字段有太多引用的表达式
例如在 VB 中,可以使用 with block 并带有以下描述:
By using With...End With, you can perform a series of statements on a specified object without specifying the name of the object multiple times. Within a With statement block, you can specify a member of the object starting with a period, as if the With statement object preceded it.
我想在 Julia 中做这样的事情:
With theCustomer
.Name = "Coho Vineyard"
.URL = "http://www.cohovineyard.com/"
.City = "Redmond"
End With
或者也许:
@With data .a=.b+c*d
在 Julia 中是否有等效的 With block ?
最佳答案
没有,但您可以只创建一个具有短名称的变量。如果您还想以与上述相同的方式限制范围,您可以这样做,例如
let c = theCustomer
c.Name = "Coho Vineyard"
c.URL = "http://www.cohovineyard.com/"
c.City = "Redmond"
end
没有更多的冗长,也不需要特殊的语法。
关于julia - Julia 中的 Visual Basic "with block"等效项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33228762/