Support evaluating just an expression #222

Open
opened 2025-12-30 01:22:27 +01:00 by adam · 4 comments
Owner

Originally created by @odenix on GitHub (Oct 19, 2024).

Occasionally it can be useful to evaluate just an expression.
Currently, pkl eval -x requires to also specify a module.
A cross-platform workaround is pkl eval pkl:base -x.
However, it would be nice if pkl eval -x just worked.

Originally created by @odenix on GitHub (Oct 19, 2024). Occasionally it can be useful to evaluate just an expression. Currently, `pkl eval -x` requires to also specify a module. A cross-platform workaround is `pkl eval pkl:base -x`. However, it would be nice if `pkl eval -x` just worked.
Author
Owner

@bioball commented on GitHub (Oct 21, 2024):

Curious: what are the use-cases for this? I've found myself rarely ever wanting to run just an expression unless I'm testing something, and in those cases, I fire up the REPL.

@bioball commented on GitHub (Oct 21, 2024): Curious: what are the use-cases for this? I've found myself rarely ever wanting to run just an expression unless I'm testing something, and in those cases, I fire up the REPL.
Author
Owner

@odenix commented on GitHub (Oct 21, 2024):

I’m used to this feature from other scripting languages, hence requiring a module after -x feels surprising and unnecessary to me. That said, some of the ad-hoc scripting use cases I had in mind are better served by reading a source module from stdin (-). Perhaps @HT154 has something to add.

@odenix commented on GitHub (Oct 21, 2024): I’m used to this feature from other scripting languages, hence requiring a module after -x feels surprising and unnecessary to me. That said, some of the ad-hoc scripting use cases I had in mind are better served by reading a source module from stdin (`-`). Perhaps @HT154 has something to add.
Author
Owner

@HT154 commented on GitHub (Oct 21, 2024):

I do this because I'm REPL-averse (it's a personal failing, not Pkl's) and have a ton of jq muscle memory. Most of what I actually use this for are quick "how does Pkl handle XYZ?" checks that are probably served equally well by the REPL.

@HT154 commented on GitHub (Oct 21, 2024): I do this because I'm REPL-averse (it's a personal failing, not Pkl's) and have a ton of jq muscle memory. Most of what I actually use this for are quick "how does Pkl handle XYZ?" checks that are probably served equally well by the REPL.
Author
Owner

@bioball commented on GitHub (Oct 21, 2024):

FWIW: you can also eval from stdin too. In that case, you need to provide a module, rather than an expression.

echo "foo = 1" | pkl eval -

I don't think this ask is unreasonable, but I'd like to wait for more feedback on the need for this before adding support for it.

@bioball commented on GitHub (Oct 21, 2024): FWIW: you can also eval from stdin too. In that case, you need to provide a module, rather than an expression. ``` echo "foo = 1" | pkl eval - ``` I don't think this ask is unreasonable, but I'd like to wait for more feedback on the need for this before adding support for it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#222