0

First of all this might be really basic thing but I do not know how to proceed. I have Guile 2.0.9 and Libctl 3.2.2 installed on my Ubuntu 14.04.1 64-bit LTS. My aim is to write a source file in Scheme then have it interpret by Guile so I do not spend too much time on the prompt trying to correct some minor errors(correcting errors on a file is much easier). How can I have it read and execute the contents of my source file?

Vesnog
  • 773
  • 2
  • 16
  • 33
  • Also, you can use `(load "myfile.scm")` to evaluate a whole file. You don't have to make the file executable to do that. – C. K. Young Mar 07 '15 at 20:26

2 Answers2

4

If you want to run .scm source file as a command line program you have to add at the head of your file:

#!/usr/bin/guile -s
!#

where you must specify proper path to you guile executable. You can find location of guile by

which guile

and you will get something like /usr/bin/guile

And do not forget to make you file executable:

chmode +x file.scm

If you want to set particular entry point to your program than there is another way to start script file:

#!/usr/bin/guile \
-e main -s
!#

-e option specify a program entry point function name.

For example file.scm

#!/usr/bin/guile \
-e main -s
!#
(define (main args)
    (display "Hello ")
    (write (cdr args))
    (newline))

Now let run it

[root@tuxbox ~]# ./file.scm Jim
Hello ("Jim")
kkomash
  • 91
  • 1
  • 1
  • 3
  • A better example of "Hello Jim" would be to use `(format #t "Hello ~a~%" (cadr args))`. – C. K. Young Mar 07 '15 at 20:23
  • Thanks for the answer so it is essentially like a `bash` script? But why do we have the `!#` line? – Vesnog Mar 08 '15 at 01:06
  • The first line starts with `#!` to inform operation system how to interpret the script, but also it opens the multiple line comment block. So we have to add `!#` line to inform `guile` that comment block is closed. – kkomash Mar 10 '15 at 11:08
2

You will find that information in guile documentation.

rkrahl
  • 1,159
  • 12
  • 18