Skip to content

Add :print directive for customizable repl printing - #3478

Merged
hdgarrood merged 3 commits into
masterfrom
configure-repl-print
Dec 30, 2018
Merged

Add :print directive for customizable repl printing#3478
hdgarrood merged 3 commits into
masterfrom
configure-repl-print

Conversation

@hdgarrood

Copy link
Copy Markdown
Contributor

Refs #3177. The command

> :print MyModule.print

will replace the repl's printing function (by default:
PSCI.Support.eval) with MyModule.print, if the latter exists and appears
to work. The referenced function should have a type of the form

forall a. (C a) => a -> Effect _

i.e., it should accept a wide variety of input types, and return
an Effect T for some type T, whose effects involve printing the
argument to the console. The T value is discarded.

It is not yet possible to configure the repl's printing function from
the .purs-repl file.

@hdgarrood

Copy link
Copy Markdown
Contributor Author

I've decided to leave the .purs-repl parsing code alone for now, since I'm not certain I'll be able to update that to handle :print commands in a non-breaking way, and of course smaller commits are easier to review anyway.

@hdgarrood

Copy link
Copy Markdown
Contributor Author

Reviewing can probably wait until #3471 is merged, as I'll probably want to rebase this once that has happened.

@hdgarrood
hdgarrood force-pushed the configure-repl-print branch 2 times, most recently from dd93308 to 8fa82d3 Compare December 15, 2018 22:35
[ImportedModule]
[P.Declaration]
[(P.Module, P.ExternsFile)]
(P.ModuleName, P.Ident)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Neither here nor there, but why not use record syntax for this rather than writing hand written selectors?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I suspect this is the way it is because we don’t want to allow updating the fields directly but we do want to allow reading them. Come to think of it we could do something like declaring this as a record with fields prefixed with an underscore eg _psciImportedModules, and not expose the fields but continue to expose the functions (which only allow reading, not updating).

Comment thread src/Language/PureScript/Interactive/Directive.hs Outdated
Comment thread src/Language/PureScript/Interactive/Types.hs
@natefaubion

Copy link
Copy Markdown
Contributor

I think the code looks good. In testing it out, the only comment I have is that it might be good to have a way to easily restore the default. I don't think most people would know where the default as.

@hdgarrood

Copy link
Copy Markdown
Contributor Author

Being able to reset it does indeed sound sensible. Perhaps the :reload command should do that?

@hdgarrood

Copy link
Copy Markdown
Contributor Author

Actually come to think of it, that might be annoying if you weren’t expecting it to do that. I’ll have a think.

@natefaubion

Copy link
Copy Markdown
Contributor

Maybe calling :print without any arguments resets it? I don't have a better suggestions that doesn't involve another command.

@hdgarrood

Copy link
Copy Markdown
Contributor Author

I think if just :print alone without arguments reset it, it might be too easy to accidentally reset it when you didn't intend to. What if calling :print without arguments told you what it's currently set to and what the default is?

> :print MyModule.eval
> :print
The interactive print function is currently set to `MyModule.eval`
The default can be restored by entering `:print PSCI.Support.eval`

@natefaubion

Copy link
Copy Markdown
Contributor

👍

Refs #3177. The command

    > :print MyModule.print

will replace the repl's printing function (by default:
PSCI.Support.eval) with MyModule.print, if the latter exists and appears
to work. The referenced function should have a type of the form

    forall a. C a => a -> Effect _

i.e., it should accept a wide variety of input types, and return
an `Effect T` for some type `T`, whose effects involve printing the
argument to the console. The `T` value is discarded.

It is not yet possible to configure the repl's printing function from
the .purs-repl file.
Entering either `:print` (without arguments) or `:show print` at the
repl will now display information about the repl's currently configured
printing function.

I've also removed the (unused) `hasArgument` function.
@hdgarrood
hdgarrood force-pushed the configure-repl-print branch from a0e6754 to 8491907 Compare December 28, 2018 03:34
@hdgarrood

Copy link
Copy Markdown
Contributor Author

I've realised that the existing :show command is probably suitable for this, so I've added :show print for showing the currently configured repl function. I've made :print without arguments do the same thing (as discussed above), in the hope that this will improve discoverability.

@natefaubion natefaubion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

New changes look good!

@hdgarrood
hdgarrood merged commit f729a14 into master Dec 30, 2018
@hdgarrood
hdgarrood deleted the configure-repl-print branch December 30, 2018 10:23
@garyb garyb mentioned this pull request Jan 12, 2019
3 tasks
dariooddenino pushed a commit to dariooddenino/purescript that referenced this pull request Jan 18, 2019
Refs purescript#3177. The command

    > :print MyModule.print

will replace the repl's printing function (by default:
PSCI.Support.eval) with MyModule.print, if the latter exists and appears
to work. The referenced function should have a type of the form

    forall a. C a => a -> Effect _

i.e., it should accept a wide variety of input types, and return
an `Effect T` for some type `T`, whose effects involve printing the
argument to the console. The `T` value is discarded.

It is not yet possible to configure the repl's printing function from
the .purs-repl file.

Entering either `:print` (without arguments) or `:show print` at the
repl will display information about the repl's currently configured
printing function.

I've also removed the (unused) `hasArgument` function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants