julia - Julia 中的 Visual Basic "with block"等效项?

标签 julia

我知道在各种编程语言中都有一种 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/

相关文章:

methods - 函数可以在 Julia 中共享背景状态变量吗?

julia - 提取字符串、计数并将它们转置为数据框中的列

arrays - 在 Array 上使用 fill(),同时保持 Julia 的一般结构

types - 哪些工具可用于检查/探测 Julia 中的类型

julia - 是否可以在未评估的上下文中获取 Julia 函数的返回类型?

Julia - 有没有办法让这个就地赋值函数看起来更好

julia - 带邻接矩阵的 Dijkstra 算法

Julia - 全局变量可以在定义之前在函数中使用吗?

for-loop - Julia:具有大数据移动的并行 For 循环

string - 在Julia中截断字符串