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.

GAD3R
  • 63,407
  • 31
  • 131
  • 192
Pierre B
  • 2,143
  • 6
  • 23
  • 38

1 Answers1

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).

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250