3

How can I run a Scheme expression from the command-line using neither a script saved in a file, nor starting the interactive shell?

The equivalent in Python would be: python -c "print 1+1". scheme (+ 1 1) just starts the interactive shell and shows the result inside it.

2

I installed guile and was able to have it execute code four ways:

1

$ guile <<< "(+ 1 1)"
GNU Guile 2.0.9
Copyright (C) 1995-2013 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
$1 = 2
$ 

2

$ echo "(+ 1 1)" | guile
GNU Guile 2.0.9
Copyright (C) 1995-2013 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
$1 = 2
scheme@(guile-user)>
$ 

3

$ echo "(+ 1 1)" > guile.script
$ guile < guile.script
GNU Guile 2.0.9
Copyright (C) 1995-2013 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
$1 = 2
$ 

4

Thanks to GAD3R for this one:

$ guile -c "(display (+ 1 1)) (newline)"
2
$

In all cases, I'm returned to my original shell prompt (indicated by the bare $ lines).

  • 1
    Thanks, @GAD3R! I've incorporated your addition. – Jeff Schaller Jan 5 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.