Tarun Maganti
Tarun Maganti

Reputation: 3076

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

Upvotes: 3

Views: 1166

Answers (1)

C. K. Young
C. K. Young

Reputation: 222973

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.

Upvotes: 4

Related Questions