in goLang, who to understand *var.Type

huangapple go评论71阅读模式
英文:

in goLang, who to understand *var.Type

问题

func Map(value string) list.List {
}
例如上面的代码。
"list"是变量名,List是goLang内置类型。
我如何理解
list.List?
它是一个名为list的List指针吗?
另外,如果我的理解是正确的,这个list中的元素类型是什么?它没有定义。
谢谢。

英文:
 11 func Map(value string) *list.List {
 12 }

for example as above.
"list" is var name, List is goLang built-in type.
how do I understand *list.List ?

Is it a List pointer that with name list?

Also, if my understanding is right, what is the element's type in this list? It is not defined.

Thanks,

答案1

得分: 3

《Go编程语言规范》

函数类型

函数类型表示具有相同参数和结果类型的所有函数的集合。未初始化的函数类型变量的值为nil。

FunctionType = "func" Signature .
Signature = Parameters [ Result ] .
Result = Parameters | Type .
Parameters = "(" [ ParameterList [ "," ] ] ")" .
ParameterList = ParameterDecl { "," ParameterDecl } .
ParameterDecl = [ IdentifierList ] [ "..." ] Type .

在参数或结果列表中,名称(IdentifierList)要么全部存在,要么全部不存在。如果存在,每个名称代表指定类型的一个项(参数或结果),并且签名中的所有非空名称必须是唯一的。如果不存在,每个类型代表该类型的一个项。参数和结果列表始终用括号括起来,除非只有一个未命名的结果,可以将其写为未括起来的类型。

包列表

import "container/list"

包list实现了一个双向链表。

类型Element

type Element struct {

        // 存储在此元素中的值。
        Value interface{}
        // 包含已过滤或未导出的字段
}

Element是链表的元素。

类型List

type List struct {
        // 包含已过滤或未导出的字段
}

List表示一个双向链表。List的零值是一个空列表,可以立即使用。

list是一个包名。结果类型*list.List是指向类型list.List的指针。类型list.List的元素是类型list.Element。例如,

package main

import "container/list"

func Map(value string) *list.List { return nil }

func main() {}
英文:

> The Go Programming Language Specification
>
> Function types
>
> A function type denotes the set of all functions with the same
> parameter and result types. The value of an uninitialized variable of
> function type is nil.
>
> FunctionType = "func" Signature .
> Signature = Parameters [ Result ] .
> Result = Parameters | Type .
> Parameters = "(" [ ParameterList [ "," ] ] ")" .
> ParameterList = ParameterDecl { "," ParameterDecl } .
> ParameterDecl = [ IdentifierList ] [ "..." ] Type .
>
> Within a list of parameters or results, the names (IdentifierList)
> must either all be present or all be absent. If present, each name
> stands for one item (parameter or result) of the specified type and
> all non-blank names in the signature must be unique. If absent, each
> type stands for one item of that type. Parameter and result lists are
> always parenthesized except that if there is exactly one unnamed
> result it may be written as an unparenthesized type.


> Package list
>
> import "container/list"
>
> Package list implements a doubly linked list.
>
>
> type Element
>
>
> type Element struct {
>
> // The value stored with this element.
> Value interface{}
> // contains filtered or unexported fields
> }
>
> Element is an element of a linked list.
>
>
> type List
>
>
> type List struct {
> // contains filtered or unexported fields
> }
>
> List represents a doubly linked list. The zero value for List is an
> empty list ready to use.


list is a package name. The result type *list.List is a pointer to type list.List. The elements of type list.List are of type list.Element. For example,

package main

import "container/list"

func Map(value string) *list.List { return nil }

func main() {}

huangapple
  • 本文由 发表于 2014年5月15日 21:58:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/23680431.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定