You are not logged in.

#1 2006-12-02 04:04:26

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

TinyScheme help needed

I'm having some problems using the new Scheme interpreter (TinyScheme) in Gimp 2.3.13. What I'm trying to do is to loop through a block of code based around a file glob pattern. In the old Scheme interpreter this use to work:

(define (skottish-test pattern)
  (let* ((filelist (cadr (file-glob pattern 1))))
  (while filelist
          (let* ((filename (car filelist))
                (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
                (drawable (car (gimp-image-get-active-layer image)))
     
          so on...

I have a directory of image files, so I would simply pass (say) *.png to the script and the variable 'filelist' fills up with all the "png" files in the directory. Then the 'while' loop would execute the code inside until it reached the end of the list.

The problem is the 'while' command does not work in this version of TinyScheme. I'm finding references that say to replace the 'while' loop with a 'do' loop, but there are no examples. So my question is: how do I write a 'do' loop that the condition of the loop is the contents of the file glob pattern?

---------------------------EDIT----------------------------

Let me narrow the paramaters. How do I make a 'do' loop do anything? This is my test case, and it is not working:

(set! x 1)
(do ((x x 3)
(write x)
(set! x (+ x 1 ))))

'x' is setting fine, but the 'write x' is never reached. So basically there is something wrong either with my 'do' loop, or the interpreter itself (which is very possible).

Offline

#2 2006-12-03 00:15:52

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: TinyScheme help needed

It looks like it goes

(do vars end-test ...)

Assuming it's similar to the better-documented MIT Scheme, vars should be

(variable init-form step-form)

So init-form initializes your variable, and step-form takes care of updating it. In a perfect world, do would evaluate its step forms in order, obviating the need for your second let* form, but Scheme doesn't seem to have anything like Common Lisp's do*.

I think you can use filelist as your variable, the contents of (let* ((filelist... as your init-form, and (not filelist) as your end-test. You omitted the part of the code that updates filelist, right? That would be your step-form.

Offline

#3 2006-12-03 00:58:19

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: TinyScheme help needed

pauldonnelly wrote:

You omitted the part of the code that updates filelist, right? That would be your step-form.

Yeah. It goes like:

(set! filelist (cdr filelist))))))

Thanks for your help. Hopefully I'll be able to get it running now.

Offline

#4 2006-12-04 06:15:08

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: TinyScheme help needed

I hope it works for you. Your step form, by the way, should probably just be (cdr filelist).

Offline

Board footer

Powered by FluxBB