Open
Conversation
Right now, `-w` (write-decls-and-statements) is only used when gomacro
is called with file arguments. But it might be useful to save a
record of what was run for interactive mode as well. For instance,
you might want to play around with some code interactively, save the
results, and then use that as the basis of writing a script.
This PR makes it so `-w` is respected when run as a REPL. In the
existing (file-based) usage, the output of `-w` is based on the
filename. For the new, REPL case there's nothing to base the ouptut
filename on, so I just hard-code a name.
Test plan:
I ran the following:
```
gomacro% go run . -w
// Welcome to gomacro. Type :help for help, :copy for copyright and license.
// This is free software with ABSOLUTELY NO WARRANTY.
gomacro> func() { return 5; }
repl.go:1:8: expected 'IDENT', found '{'
gomacro> func a() { return 5; }
return: expecting 0 expressions, found 1: return 5
gomacro> a := func() int { return 5 }
gomacro> :exit
gomacro% cat repl.go
// -------------------------------------------------------------
// DO NOT EDIT! this file was generated automatically by gomacro
// Any change will be lost when the file is re-generated
// -------------------------------------------------------------
// REPL run: 2023-09-21T13:42:27-07:00
package main
func a() { return 5 }
var a = func() { return 5 }
var a = func() int { return 5 }
```
which shows that the declarations are being saved and emitted as
expected.
Author
I didn't know what the best behavior here might be -- I'm happy to do here whatever you think is best. |
csilvers
commented
Sep 21, 2023
|
|
||
| var set, clear Options | ||
| var repl, forcerepl = true, false | ||
| repl, forcerepl := true, false |
Author
There was a problem hiding this comment.
Sorry, this was my editor auto-fixing things. I can revert if you have strong feelings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Right now,
-w(write-decls-and-statements) is only used when gomacro is called with file arguments. But it might be useful to save a record of what was run for interactive mode as well. For instance, you might want to play around with some code interactively, save the results, and then use that as the basis of writing a script.This PR makes it so
-wis respected when run as a REPL. In the existing (file-based) usage, the output of-wis based on the filename. For the new, REPL case there's nothing to base the ouptut filename on, so I just hard-code a name.Test plan:
I ran the following:
which shows that the declarations are being saved and emitted as expected.