member
Accesses a given member of a given structure, or creates a function that accesses a given member of its argument.
Syntax
-
member(s)
-
s
is a string
-
-
member(S, s)
-
S
is a structure -
s
is a string
-
Description
If S
is a structure and s
a string, then member(S, s)
returns the value of the member named s
in S
.
If s
is a string, then member(s)
returns the function S ↦ member(S, s)
.
Examples
person ≔ (fn, ln, role) ↦ struct("FirstName": fn, "LastName": ln, "role": role); L ≔ '(person("Albus", "Dumbledore", "headmaster"), person("Minerva", "McGonagall", "teacher"), person("Severus", "Snape", "teacher"), person("Pomona", "Sprout", "teacher"), person("Filius", "Flitwick", "teacher"), person("Horace", "Slughorn", "teacher"), person("Harry", "Potter", "student"), person("Ronald", "Weasley", "student"), person("Hermione", "Granger", "student"), person("Remus", "Lupin", "teacher"), person("Rubeus", "Hagrid", "teacher"), person("Luna", "Lovegood", "student"))
(FirstName: Albus, LastName: Dumbledore, role: headmaster) (FirstName: Minerva, LastName: McGonagall, role: teacher) (FirstName: Severus, LastName: Snape, role: teacher) (FirstName: Pomona, LastName: Sprout, role: teacher) (FirstName: Filius, LastName: Flitwick, role: teacher) (FirstName: Horace, LastName: Slughorn, role: teacher) (FirstName: Harry, LastName: Potter, role: student) (FirstName: Ronald, LastName: Weasley, role: student) (FirstName: Hermione, LastName: Granger, role: student) (FirstName: Remus, LastName: Lupin, role: teacher) (FirstName: Rubeus, LastName: Hagrid, role: teacher) (FirstName: Luna, LastName: Lovegood, role: student)
frequencies(L @ member("role"))
(headmaster, 1) (teacher, 7) (student, 4)
SortBy(L, member("LastName"))
(FirstName: Albus, LastName: Dumbledore, role: headmaster) (FirstName: Filius, LastName: Flitwick, role: teacher) (FirstName: Hermione, LastName: Granger, role: student) (FirstName: Rubeus, LastName: Hagrid, role: teacher) (FirstName: Luna, LastName: Lovegood, role: student) (FirstName: Remus, LastName: Lupin, role: teacher) (FirstName: Minerva, LastName: McGonagall, role: teacher) (FirstName: Harry, LastName: Potter, role: student) (FirstName: Horace, LastName: Slughorn, role: teacher) (FirstName: Severus, LastName: Snape, role: teacher) (FirstName: Pomona, LastName: Sprout, role: teacher) (FirstName: Ronald, LastName: Weasley, role: student)
ApplyIf(GroupBy(L, member("role"), "role"), IsStructure, member("LastName"), 3)
(role: headmaster, members: (Dumbledore)) (role: student, members: (Weasley, Granger, Potter, Lovegood)) (role: teacher, members: (Lupin, Hagrid, McGonagall, Snape, Sprout, Flitwick, Slughorn))