Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.

Commit 50fc43e

Browse files
authored
0.3 ftd changes - Records (#39)
* updated record * refactored user -> programmer
1 parent 367eeca commit 50fc43e

File tree

1 file changed

+67
-13
lines changed

1 file changed

+67
-13
lines changed

record.ftd

+67-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,72 @@
1010

1111
Before a record can be used it must be declared using the `record` syntax:
1212

13-
-- ft.code: declaring a record
13+
-- ft.code: Declaring a Person record
1414
lang: ftd
1515

1616
\-- record person:
17-
name: caption
18-
age: integer
19-
bio: optional body
17+
caption name:
18+
integer age:
19+
optional body bio:
2020

2121
-- ft.markdown:
2222

2323
Here we are creating a record. The name of the record is `person`. It has three
2424
fields: `name`, `age` and `bio`.
2525

26+
-- ft.code: Declaring a Company record
27+
lang: ftd
28+
29+
\-- record company:
30+
caption name:
31+
person list employees:
32+
33+
-- ft.markdown:
34+
35+
In this case, the name of the record is `company`. It has two fields:
36+
caption `name` and list of `employees` of `person` type.
37+
38+
-- ft.h1: Declaring a `record` with default values
39+
40+
Sometimes, the programmer might want to provide default values to the record
41+
fields, in case if he/she doesn't specify those during initialization.
42+
43+
-- ft.code: Declaring a Person record with default field values
44+
lang: ftd
45+
46+
\-- record person:
47+
caption name: Undefined
48+
integer age:
49+
optional body bio: Not specified
50+
51+
\;; << Alternative way >>
52+
\-- record person:
53+
caption name: Undefined
54+
integer age:
55+
56+
\-- optional body person.bio:
57+
58+
No bio is specified for this person.
59+
60+
-- ft.code: Declaring a Company record with default field values
61+
lang: ftd
62+
63+
\-- record company:
64+
string name: FifthTry
65+
66+
\-- person list company.employees:
67+
68+
\-- person:
69+
name: Arpita
70+
age: 22
71+
72+
\-- person:
73+
name: Abrar
74+
age: 24
75+
76+
\-- end: company.employees
77+
78+
2679
-- ft.h1: Field Types
2780

2881
Fields can be either one of the [built-in types](built-in-types/),
@@ -49,19 +102,20 @@ so it's not a problem. Had it been `body` the above would not have been valid.
49102

50103
-- ft.h1: Record Field Update Syntax
51104

105+
The field which needs to be updated has to be mutable before updating its value.
52106
An individual field of a record can be updated using a syntax like this:
53107

54108
-- ft.code:
55109
lang: ftd
56110

57-
\-- person john-snow: John Snow
58-
age: 14
111+
\-- person $john-snow: John Snow
112+
$age: 14
59113

60-
\-- john-snow.age: 15
114+
\-- $john-snow.age: 15
61115

62116
-- ft.markdown:
63117

64-
Here we have used `-- john-snow.age: 15` to update a single field of a record.
118+
Here we have used `-- $john-snow.age: 15` to update a single field of a record.
65119

66120
This also works if the field is a list:
67121

@@ -72,12 +126,12 @@ lang: ftd
72126
caption name:
73127
string list alias:
74128

75-
\-- person john-snow: John Snow
129+
\-- person $john-snow: John Snow
76130

77-
\-- john-snow.alias: Aegon Targaryen
78-
\-- john-snow.alias: Lord Crow
79-
\-- john-snow.alias: The White Wolf
80-
\-- john-snow.alias: The Prince That Was Promised
131+
\-- $john-snow.alias: Aegon Targaryen
132+
\-- $john-snow.alias: Lord Crow
133+
\-- $john-snow.alias: The White Wolf
134+
\-- $john-snow.alias: The Prince That Was Promised
81135

82136

83137
-- ft.h1: Reading A Record From Rust

0 commit comments

Comments
 (0)