Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a guile Scheme script using shebang notation?

I have created a guile Scheme script using shebang notation.

Here is the code:

#!/usr/local/bin/guile \
-e main -s
!#
(define (fact-iter product counter max-count)
    (if (> counter max-count)
         product
         (fact-iter (* counter product) (+ counter 1) max-count)))
(define (factorial n)
    (fact-iter 1 1 n))
(define (main args) 
    (factorial args)
)

File Name: factScheme.guile

I tried running it directly in the terminal "factScheme.guile" and I got bash factScheme.guile: command not found

If I used "./factScheme.guile" and I got Permission Denied .

I would be obliged if anyone can tell me how to actually run a guile scheme script in the terminal of an ubuntu step-by-step.

I have guile in the directory mentioned in the code. I

like image 953
Tarun Maganti Avatar asked Dec 03 '25 17:12

Tarun Maganti


1 Answers

You need to make your factScheme.guile file executable:

chmod +x factScheme.guile

Your program has other issues: you need to transform the first (non-program-name) argument into a number, and you need to display the result. Thus:

(display (factorial (string->number (cadr args))))

P.S. Guile programs typically use a .scm file suffix.

like image 106
Chris Jester-Young Avatar answered Dec 06 '25 12:12

Chris Jester-Young