Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot work out how to run .scm (using guile or scm) files

I have created a abc.scm file and tried to compile it to a binary (or whatever guile scheme compiles to) using "guild compile", "scm" and "guile" commands in terminal in Ubuntu.

For "guild compile abc.scm", I get the output "wrote `/home/tarunmaganti/.cache/guile/ccache/2.0-LE-8-2.0/home/tarunmaganti/abc.scm.go'" I find the file and run like this - "./abc.scm.go" which says permission denied.
When I give the necessary permissions using "chmod 755" or "chmod 777", I get an error like - "bash: ./abc.scm.go: cannot execute binary file: Exec format error".

The "scm whatever-file-name.scm" just opens up the scm interpreter.

The "guile whatever-file-name.scm does nothing.

The link of official GNU/Guile Scheme isn't very helpful.

Please, help me. I would like to create a guile scheme script file. Compile it and run it as C/C++ program. Is it possible? If compilation isn't possible, I would like to know, how to at least run the script file of GNU/guile scheme or MIT-Scheme.

{Step-by-step is highly appreciated, I'm still a beginner in using Ubuntu and also in Scheme.}

Thanks in advance.

like image 878
Tarun Maganti Avatar asked Jun 12 '16 10:06

Tarun Maganti


1 Answers

You can use the shebang notation to create a Guile script (the -s is optional in newer versions of Guile):

#!/usr/bin/guile -s
!#
(display "Hello, world!\n")

Notice the !# on the second line. Guile treats the #! as the start of a block comment (similar to what #| is in standard Scheme), which has to be terminated using !# (similar to |# in standard Scheme).

If you want your script to pass any command-line options to Guile itself, then read about the meta switch. Here's an example of such:

#!/usr/bin/guile \
-e main -s
!#
(define (main args)
  (if (null? (cdr args))
      (format #t "Hello, world!~%")
      (for-each (lambda (name)
                  (format #t "Hello, ~a!~%" name))
                (cdr args))))
like image 132
Chris Jester-Young Avatar answered Sep 21 '22 12:09

Chris Jester-Young