-
-
Notifications
You must be signed in to change notification settings - Fork 777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debug printing feature in language #2535
Comments
I'm a fan of |
I like
What behavior would it degrade to? |
Big fan of |
Printing in the syntax of the native target. JS or Erlang |
I'd like both Where could it be used? Would it work like debug returning its rhs? peek peek foo
// print foo twice?
bar(peek foo)
// print foo?
foo
|> peek bar
// print bar? |
Having it return the value sounds good. We'd need to decide if it has any special pipes support as I suspect folks will want to pipe into it. |
Just call it |
No seriously though I would prefer it just be called debug or dbg or debug_print or something to that effect. I think the ideal syntax would be for it to work in a pipe and for Edit: I no longer think this syntax is a good idea, I would much prefer something like a global function. |
We're not breaking the stdlib, and there's lots of other contexts in which the word debug is more appropriate and already taken, such as logging libraries. I don't think |
|
|
? foo
|> ? bar
|> ? quux(? batz) I like it :) |
but are we really prying... into the vm runtime value? |
My personal favorites are |
I'm just a silent reader on discord, but I'll chime in for bike shedding 😆 What about Apparently that even has some precedent in ActionScript: https://open-flash.github.io/mirrors/as2-language-reference/global_functions.html#trace() |
Seems like we don't want to do anything that would overlap w/proper logging ( |
Does it have to be a keyword? Something that worked more like a global function would be a lot more composable w/gleam syntax in my opinion, and you wouldn't have to adopt a whole new style of control flow for a single keyword. Tbh this feels so clearly like a function I think it would be extremely strange to have it be a keyword as described above. |
It is to do things that a function cannot do. I'm not sure making it look a bit like a function would be beneficial given it couldn't be one. |
that's the reason I like |
No semantic difference here, just about how they feel, look, and any connotations from other languages. |
hm, echo would write a string to the output buffer in php.
I think the question mark with a space is a good thing, ... a word kind of pollutes the screen/attention and makes it harder to follow the code with the debug printing included. |
Ah yeah "looks like a function but isn't a function" is actually a bad outcome I suppose 🤔 |
If I hadn’t been poisoned by previous language experience I would think |
I doubt we'll ever use |
I would like |
Could gleam publish fail if there are debug commands in the code? |
Yes! That's one of the things covered above |
Let's keep in mind goal 2. Including a "tag" in the output in order to label the thing being printed can be extremely helpful in aiding debugging. I don't think any of the syntax proposals so far include such tagging. How about something like the following? value
|> process
|> :tee "my tag"
|> more_processing This potentially does the following:
I think the question of where to write the output (stdout or stderr) is perhaps another consideration. I would lean towards stderr so that injecting Alternative syntaxes for the
|
We could also reuse the "as" used by todo and panic: foo
|> bar
|> echo as "tag"
|> baz It would be a bit more awkward when used as a function though: // maybe? I have no idea how it should look
echo foo as "tag" |
I think it should print to stderr. If required later For words, short 1-word-1-syllable If we need tagging for the question mark, if we do prefixing, it could look like this: // Regular
? var as "tag1"
// Piped
? foo as "tag2"
|> ? bar as "tag3"
|> ? quux(? batz as "tag4") as "tag5" ...or if it is suffixed like this: // Regular
var ? "tag1"
// Piped
foo ? "tag2"
|> bar ? "tag3"
|> quux(batz ? "tag4") ? "tag5" |
|
Inspect is not an option, it is already taken. We have gone with echo, the discussion is the design now. |
|
@lpil, as mentioned above, I'd suggest output go to stderr, not stdout, to avoid potential interference with intentional program output. Does that make sense? |
Definitely. This is also what io.debug does today. |
If this doesn't make it into 1.0 would it be sensible to reserve |
It was reserved in v0.34.0 |
What about |
We can't use |
Goals:
gleam publish
so you can't publish code that uses itWhat should the syntax be?
Update: The keyword is echo.
One annoyance is that the anything-to-string code is in the standard library, not in core. Perhaps it could gracefully degrade if stdlib isn't available.
The text was updated successfully, but these errors were encountered: