Sort.....https://godoc.org/sort

Package sort provides primitives for sorting slices and user-defined collections.

What are primitives?

What are collections?

Strings sorts a slice of strings in increasing order.

What does increasing order mean? Does it have to do with alphabetizing?

For example, in https://play.golang.org/p/_xEYcrUjFoR it looks like the elements in the slice of string are alphabetized by sort.Strings(xs). Is that what’s happening?

I’ve gone 15 minutes over my allotted time without noticing til now

1 Like

In this case, most basic building blocks to work with.

Datatypes that can contain zero, one or many individual pieces of data like slices.

Increasing order means, lowest valued item first, highest value last, such that first <= last always is true.

Only kind of. Lowercase letters are much “greater” than their uppercase equivalents. Even greater than uppercase letters that are greater than the uppercase equivalent of the lowercase equivalent. ("A" < "Z" && "Z" < "a" is true!)

Basically strings are sorted by comparing them “rune by rune”, where each rune can be interpreted as a number which is equivalent to the unicode codepoints.

5 Likes

Interesting information which I will save.

are alphabetized by sort.Strings(xs). Is that what’s happening?

Only kind of. Lowercase letters are much “greater” than their uppercase equivalents. Even greater >.than uppercase letters that are greater than the uppercase equivalent of the lowercase equivalent. ( "A" < "Z" && "Z" < "a" is true !)

Basically strings are sorted by comparing them " rune by rune ", where each rune can be interpreted as a number which is equivalent to the unicode codepoints.

Extremely interesting.

1 Like

https://play.golang.org/p/NgkdtxrbZVW

Call me stupid, in sort.Sort is sort related to Sort? I need it spelled out

1 Like

In sort.Sort, the lowercased sort is the package qualifier, the uppercased Sort is the name of the function in that package.

2 Likes

In sort.Sort , the lowercased sort is the package qualifier

From Wikipedia, the free encyclopedia. In the C, C++, and D programming languages, a type qualifier is a keyword that is applied to a type, resulting in a qualified type. For example, const int is a qualified type representing a constant integer, while int is the corresponding unqualified type, simply an integer.

From stackoverflow, A qualifier adds an extra “quality”, such as specifying volatility or constness of a variable. They’re similar to adjectives: “a fickle man”, “a volatile int”, “an incorruptible lady”, “a const double”. With or without a qualifier, the variable itself still occupies the same amount of memory, and each bit has the same interpretation or contribution to the state/value. Qualifiers just specify something about how it may be accessed or where it is stored.

keywords are predefined reserved identifiers (arguably, see below) that the language itself assigns some meaning to, rather than leaving free for you to use for your own purposes (i.e. naming your variables, types, namespaces, functions…).

Examples

  • volatile and const are both qualifiers and keywords
  • if , class , namespace are keywords but not qualifiers
  • std , main , iostream , x , my_counter are all identifiers but neither keywords nor qualifiers

There’s a full list of keywords at http://www.cppreference.com/wiki/keywords/start. C++ doesn’t currently have any qualifiers that aren’t keywords (i.e. they’re all “words” rather than some punctuation symbols).

Am I on the right track?

the uppercased Sort is the name of the function in that package.

This I understand.

Thanks

1 Like

Maybe I’m using the term qualifier wrong here, but I’m used to it and most people understand it. My usage of that term stems from “fully qualified name”.

Just think of it as the packages name as assigned in the import.

1 Like

Getting more clear.

Don’t know what that means

1 Like

You know that when you want to use some external package, you need to import it, as in import ("sort").

You can also do it like this:

Import (
  s "sort"
)

Then you can use it’s functions as in s.Sort.

That’s what I mean by “it’s assigned name”.

2 Likes

Okay got it. Appreciate your patience

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.