File tree Expand file tree Collapse file tree 4 files changed +25
-23
lines changed Expand file tree Collapse file tree 4 files changed +25
-23
lines changed Original file line number Diff line number Diff line change 11
11
- The ` string_builder ` module loses the ` from_float ` function. Use ` float.to_string ` instead.
12
12
- Fixed the ` int.power ` and ` float.power ` functions by properly handling error cases.
13
13
- The grapheme iterator used by ` string.graphemes ` is now locale independent on target JavaScript.
14
+ - Unified ` io.debug ` to yield Gleam syntax to standard output (stdout) not just on JavaScript but also Erlang.
14
15
15
16
## v0.21.0 - 2022-04-24
16
17
Original file line number Diff line number Diff line change
1
+ import gleam/string
2
+
1
3
/// Writes a string to standard output.
2
4
///
3
5
/// If you want your output to be printed on its own line see `println`.
@@ -48,7 +50,7 @@ if javascript {
48
50
"../gleam_stdlib.mjs" "log"
49
51
}
50
52
51
- /// Prints a value to standard output using Erlang syntax.
53
+ /// Prints a value to standard output (stdout) yielding Gleam syntax.
52
54
///
53
55
/// The value is returned after being printed so it can be used in pipelines.
54
56
///
@@ -73,24 +75,9 @@ if javascript {
73
75
/// ```
74
76
///
75
77
pub fn debug ( term : anything) -> anything {
76
- debug_print ( term )
77
78
term
78
- }
79
-
80
- if erlang {
81
- fn debug_print ( term : anything) -> DoNotLeak {
82
- erlang_fwrite ( "~tp\n " , [ term ] )
83
- }
84
- }
79
+ |> string . inspect
80
+ |> println
85
81
86
- if javascript {
87
- external fn debug_print ( anything) -> Nil =
88
- "../gleam_stdlib.mjs" "debug"
89
- }
90
-
91
- if erlang {
92
- external type DoNotLeak
93
-
94
- external fn erlang_fwrite ( String , List ( a) ) -> DoNotLeak =
95
- "io" "fwrite"
82
+ term
96
83
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import gleam/list
6
6
import gleam/option . { None , Option , Some }
7
7
import gleam/order
8
8
import gleam/string_builder
9
+ import gleam/string_builder . { StringBuilder }
9
10
10
11
if erlang {
11
12
import gleam/result
@@ -824,17 +825,19 @@ pub fn capitalise(s: String) -> String {
824
825
}
825
826
}
826
827
827
- pub fn inspect ( value : a) -> String {
828
- do_inspect ( value )
828
+ /// Returns a `String` representation of values in Gleam syntax.
829
+ ///
830
+ pub fn inspect ( term : anything) -> String {
831
+ do_inspect ( term )
829
832
|> string_builder . to_string
830
833
}
831
834
832
835
if javascript {
833
- external fn do_inspect ( value : a ) -> string_builder . StringBuilder =
836
+ external fn do_inspect ( term : anything ) -> StringBuilder =
834
837
"../gleam.mjs" "inspect"
835
838
}
836
839
837
840
if erlang {
838
- external fn do_inspect ( value : a ) -> string_builder . StringBuilder =
841
+ external fn do_inspect ( term : anything ) -> StringBuilder =
839
842
"gleam_stdlib" "inspect"
840
843
}
Original file line number Diff line number Diff line change
1
+ if erlang {
2
+ import gleam/io
3
+ import gleam/should
4
+
5
+ pub fn debug_test ( ) {
6
+ "io.debug-test"
7
+ // prints to stdout, but EUnit will suppress that:
8
+ |> io . debug ( )
9
+ |> should . equal ( "io.debug-test" )
10
+ }
11
+ }
You can’t perform that action at this time.
0 commit comments