Skip to content
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

Evaluating Bass code from stdin #258

Open
DrPyser opened this issue Nov 22, 2022 · 1 comment
Open

Evaluating Bass code from stdin #258

DrPyser opened this issue Nov 22, 2022 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@DrPyser
Copy link

DrPyser commented Nov 22, 2022

Hi, this is a very interesting project which I'm just starting to learn.

One useful pattern of interaction with a script interpreter is to be able to provide script input through stdin.

Currently, when I try to provide input to bass through piping to its stdin, it fails with an error about inappropriate ioctl:

❯ echo '($ echo hello)' | bass
inappropriate ioctl for device

Is it an expected current limitation? Is there currently a way for a bass script to evaluate stdin input as bass expressions?
Looking at the reference in the documentation, it seems there is no public API for parsing bass code, or more generally s-expressions.
Perhaps this would be exposed through a :bass protocol for read, and the ability to change the protocol associated with the stdin source(currently fixed to json as I understand).

Thanks @vito for this nice work, looking forward to making more use of bass!

@vito
Copy link
Owner

vito commented Nov 22, 2022

Hiya, thanks, glad it caught your eye!

Currently, when I try to provide input to bass through piping to its stdin, it fails with an error about inappropriate ioctl:

Good catch, this is probably something that should "just work" as nearly every other scripting language supports it.

I believe right now it's just trying to pop into an interactive REPL because no script was given and failing because stdin isn't a tty. It should instead detect if stdin is a regular file/pipe and just evaluate its io.Reader. I think this would be a pretty minor change somewhere around here:

if flags.NArg() == 0 {

Looking at the reference in the documentation, it seems there is no public API for parsing bass code, or more generally s-expressions.
Perhaps this would be exposed through a :bass protocol for read, and the ability to change the protocol associated with the stdin source(currently fixed to json as I understand).

While I'm totally sympathetic to the cause of reading S-exprs as a protocol, I would prefer to decouple that from this issue as it seems slightly different. 🙂 This issue is for native interpretation of Bass code, whereas reading them as data using Bass is something more dynamic. Let's wait until someone has a more precise use case for that.

@vito vito added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Nov 22, 2022
@vito vito changed the title Reading bass expression from stdin Evaluating Bass code from stdin Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants