Elixir 编程:结构体、高阶函数与列表操作
1. 结构体的使用
1.1 结构体变量的创建
在 Elixir 中,可以使用记录语法创建结构体变量,并与默认值进行交互。以下是不同创建方式的示例:
- 使用默认值创建 tower1 :
# 仅使用默认值创建 tower1
tower1 = %Tower{}
- 创建带有位置信息的
tower2:
# 创建 tower2,指定 location,其他使用默认值
tower2 = %Tower{location: "Some Place"}
- 覆盖部分默认值创建
tower3:
# 覆盖 location、height 和 name 的默认值,planemo 使用默认值
tower3 = %Tower{location: "NYC", height: 241, name: "Woolworth Building"}
- 覆盖所有默认值创建
tower4: <
超级会员免费看
订阅专栏 解锁全文
8

被折叠的 条评论
为什么被折叠?



