Skip to content

Commit c7d4720

Browse files
committed
Add example
1 parent b06d640 commit c7d4720

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

basic/builtin_/printfunc.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package builtin_
2+
3+
import "fmt"
4+
5+
// PrintFunc は、ビルドイン関数のprintとfmt.Printの違いについてのサンプルです.
6+
func PrintFunc() error {
7+
// ------------------------------------------------------------
8+
// ビルドイン関数の print() と fmt.Print() の違い
9+
//
10+
// ビルドイン関数の print(), println() は標準エラーに出力する
11+
// fmt.PrintXX は、標準出力に出力する
12+
//
13+
// ビルトイン関数の方は、fmtパッケージをimportする必要がないため
14+
// アプリのブート時やデバッグ目的に利用すると便利。
15+
//
16+
// ただし、ビルドイン関数である print(), println() のコメントには
17+
// 以下の一文が記載されている。(builtin/builtin.goより)
18+
// "it is not guaranteed to stay in the language."
19+
// ------------------------------------------------------------
20+
var (
21+
message = "helloworld"
22+
)
23+
24+
// fmtパッケージの方は標準出力に出力する
25+
fmt.Println("[fmt ]", message)
26+
27+
// ビルトインの方は標準エラーに出力する
28+
println("[builtin]", message)
29+
30+
return nil
31+
}

lib/mapping.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/devlights/try-golang/advanced/reflection"
77
"github.com/devlights/try-golang/advanced/sets"
88
"github.com/devlights/try-golang/basic/array_"
9+
"github.com/devlights/try-golang/basic/builtin_"
910
"github.com/devlights/try-golang/basic/comments"
1011
"github.com/devlights/try-golang/basic/constants"
1112
"github.com/devlights/try-golang/basic/defer_"
@@ -46,6 +47,7 @@ func NewSampleMapping() SampleMapping {
4647

4748
// MakeMapping は、マッピング生成します
4849
func (m SampleMapping) MakeMapping() {
50+
m["builtin_print"] = builtin_.PrintFunc
4951
m["error_basic"] = error_.Basic
5052
m["error_sentinel"] = error_.Sentinel
5153
m["error_typeassertion"] = error_.TypeAssertion

0 commit comments

Comments
 (0)