Skip to content

Commit e466054

Browse files
committed
Update README.md
1 parent 87f1e92 commit e466054

1 file changed

Lines changed: 73 additions & 19 deletions

File tree

README.md

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,79 @@ for i := 0; i < len(s); i++ {
178178
}
179179
```
180180

181+
### Types
182+
TypeShell supports the definition of types. However, types which result in slices are not supported yet.
183+
184+
```golang
185+
// Define a type.
186+
type myType int
187+
188+
var a myType
189+
a = myType(24)
190+
```
191+
192+
```golang
193+
// Define an alias.
194+
type myType = int
195+
196+
var a myType
197+
a = 24
198+
```
199+
200+
```golang
201+
// Define a struct.
202+
type myStruct struct {
203+
a string
204+
b string
205+
c, d int
206+
}
207+
```
208+
209+
### Structs
210+
```golang
211+
// Define a simple struct.
212+
type myStruct struct {
213+
greeting string
214+
planet string
215+
}
216+
217+
// Define a new struct variable.
218+
var s myStruct = myStruct{greeting: "Hello", planet: "World"}
219+
220+
// Assign a value to a struct field.
221+
s.planet = "Mars"
222+
223+
// Retrieve values from the struct.
224+
print(s.greeting, s.planet)
225+
```
226+
227+
Nested structs are also supported.
228+
```golang
229+
// Define structs.
230+
type myNestedStruct struct {
231+
planet string
232+
}
233+
234+
type myStruct struct {
235+
greeting string
236+
info myNestedStruct
237+
}
238+
239+
// Define a new struct variable.
240+
var s myStruct = myStruct{
241+
greeting: "Hello",
242+
info: myNestedStruct{
243+
planet: "World",
244+
},
245+
}
246+
247+
// Assign a value to a nested struct field.
248+
s.info.planet = "Mars"
249+
250+
// Retrieve values from the structs.
251+
print(s.greeting, s.info.planet)
252+
```
253+
181254
### Programs/Scripts
182255
```golang
183256
// Programs/Scripts are called by stating the name preceded by an @.
@@ -230,25 +303,6 @@ import (
230303
gocode.SomeFunction()
231304
```
232305

233-
### Type declarations
234-
TypeShell supports the declaration of types. However, types which result in slices are not supported yet.
235-
236-
```golang
237-
// Define a type.
238-
type myType int
239-
240-
var a myType
241-
a = myType(24)
242-
```
243-
244-
```golang
245-
// Define an alias.
246-
type myType = int
247-
248-
var a myType
249-
a = 24
250-
```
251-
252306
### Builtin
253307
```golang
254308
// Returns the length of a slice or a string.

0 commit comments

Comments
 (0)