Skip to content

Commit d76e2f1

Browse files
committed
grrr
1 parent 4fe9297 commit d76e2f1

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

docs/document/Articles/docs/Language Thoughts.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Foo {
2929

3030
## Conversion operator
3131

32-
Should happens between nonminal types.
32+
Should happens between nominal types.
3333

3434
```ts
3535
let foo = Foo {} as Bar
@@ -87,8 +87,6 @@ It should offer benefits:
8787
- If each unit type is nominal, we will have `m*m` conversion explosion.
8888
- Another way is extension upon the data type, but it's just a problem of form.
8989

90-
91-
9290
```ts
9391
let foo = 360deg
9492
let bar = 6.28rad // for literal
@@ -160,3 +158,54 @@ type Foo = {
160158
}
161159
type Bar = Foo with { foo: double, baz: any } // [!code highlight]
162160
```
161+
162+
## Constant members
163+
164+
Constants as special members, including functions and fields.
165+
166+
```ts
167+
// should be evaluated at compile-time
168+
function foo(): const string { // implies the function returns const
169+
return "I am an constant"
170+
}
171+
172+
type Foo {
173+
foo: const string = foo() // only constant can be assigned from an constant generator function
174+
bar: const string = "I am also an constant"
175+
fn = (): const string => "foo"
176+
}
177+
178+
_ = Foo::foo // use :: to access constant members
179+
_ = Foo::fn() // this evaluates to an constant too
180+
181+
```
182+
183+
### Reflection constants
184+
185+
Some reflection properties should be just constants.
186+
Any type should have some default constant members like `name`, `fullName`, `namespace`(if we do plan to design the module system like this)
187+
Which means they're preserved constants.
188+
189+
```ts
190+
191+
type Bar {
192+
typeName: any // preserved member name can not be set // [!code error]
193+
}
194+
// Use `::` as constant accessor.
195+
_ = Foo::typeName // -> `Foo`
196+
_ = Bar::name
197+
```
198+
199+
## Default parameter mutation
200+
201+
```ts
202+
type Person {
203+
name: string
204+
age: uint
205+
}
206+
function foo(arg: Person = { name = "John", age = 18 }): void {
207+
208+
}
209+
// use `default` to represent the default value of the parameter
210+
foo(default with { name = "jane" })
211+
```

docs/document/Articles/docs/String nature in .NET.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In .NET, the string pool (also known as the intern pool) is a special area of me
88

99
We are able to mutate the string in pool in `unsafe` block to demonstrate this characteristic.
1010

11-
```c#
11+
```cs
1212
string text = "abc";
1313

1414
unsafe
@@ -26,7 +26,7 @@ Console.Write("abc"); // dbc
2626
For string from external resources, we may need to registered it into string pool using `string.Intern(str: string): string`.
2727
This approach is the same as declaring a string literal, they will all exist during application domain.
2828

29-
```c#
29+
```cs
3030
string url = /* ... */;
3131
HttpResponseMessage response = await httpClient.GetAsync(url);
3232
string responseBody = await response.Content.ReadAsStringAsync();

0 commit comments

Comments
 (0)