Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ When implementing new language syntax, follow this two-phase approach:
- **Type Safety**: Leverage gogen's type information maintenance for semantic correctness
- **Testing**: Add comprehensive test cases in `cl/_testgop/` covering various usage scenarios

#### Phase 3: Documentation (Third Pull Request)
**Scope**: User-facing documentation updates
- **Quick Start Guide**: Add feature documentation to `doc/docs.md` with practical examples
- **Table of Contents**: Update TOC in quick start to include new feature section
- **Language Specification**: Update specification documents if needed (e.g., `doc/spec.md`)
- **Examples**: Provide clear, runnable code examples demonstrating the feature

### Communication Protocol
- When I request syntax additions, first confirm the exact grammar specification
- Always consider backward compatibility with existing Go code
Expand Down Expand Up @@ -70,3 +77,7 @@ When implementing new language syntax, follow this two-phase approach:
- Common usage scenarios
- Edge cases and error conditions
- Integration with existing type system
- **Phase 3**: Documentation validation
- Ensure all code examples in documentation are runnable and correct
- Verify documentation accurately reflects implemented behavior
- Check that TOC links work correctly
36 changes: 36 additions & 0 deletions doc/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Here is my `Hello world` program:
* [Error handling](#error-handling)
* [Functions](#functions)
* [Returning multiple values](#returning-multiple-values)
* [Optional parameters](#optional-parameters)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niupilot move Optional parameters before Variadic parameters.

Copy link
Contributor Author

@niupilot niupilot bot Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Section Reordering Complete ✓

The "Optional Parameters" section has been successfully moved before "Variadic parameters" as requested.

Changes made:

  • ✓ Updated table of contents to show "Optional parameters" before "Variadic parameters"
  • ✓ Moved the entire "Optional Parameters" section (including all examples and explanations) to appear before the "Variadic parameters" section in the document body

The documentation now presents optional parameters before variadic parameters, which provides a better logical flow for readers.

Commit: fc8d14f4 - Move Optional Parameters section before Variadic parameters


Job run: https://github.com/goplus/xgo/actions/runs/ | Branch: codeagent/claude/issue-2449-1760028800

* [Variadic parameters](#variadic-parameters)
* [Higher order functions](#higher-order-functions)
* [Lambda expressions](#lambda-expressions)
Expand Down Expand Up @@ -816,6 +817,41 @@ c, _ := foo() // ignore values using `_`
<h5 align="right"><a href="#table-of-contents">⬆ back to toc</a></h5>


### Optional parameters

XGo supports optional parameters using the `T?` syntax. Optional parameters must have zero values as their defaults.

```go
func greet(name string, count int?) {
if count == 0 {
count = 1
}
for i := 0; i < count; i++ {
println "Hello,", name
}
}

greet "Alice", 3 // prints "Hello, Alice" three times
greet "Bob" // prints "Hello, Bob" once (default behavior)
```

Optional parameters are denoted by adding `?` after the parameter type. The default value is always the zero value of that type (e.g., `0` for integers, `""` for strings, `false` for booleans).

```go
func connect(host string, port int?, secure bool?) {
if port == 0 {
port = 80
}
println "Connecting to", host, "on port", port, "secure:", secure
}

connect "example.com", 443, true // Connecting to example.com on port 443 secure: true
connect "example.com" // Connecting to example.com on port 80 secure: false
```

<h5 align="right"><a href="#table-of-contents">⬆ back to toc</a></h5>


### Variadic parameters

```go
Expand Down