Hi guilers! Inspired by wingo's recent blogage on wingolog in combination with my portings of racket and cl loop frameworks, I did some thinking about generators. Especially inlining.
1. Can we make stubs like this inlinable (iterate (generator g (iterate (for x in l-i-s-t) (when (even? x) (yield (f x))))) (collect (+ (next g) (next g)))) A generator would be somthing like (define-syntax-rule (generator _thunk) (lambda () (let ((thunk (lambda () (_thunk) (finish)))) (call-with-prompt tag thunk (lambda (k . l) (set! thunk k) (apply values l)))))) (define-syntax-rules (yield x) (abort-to-prompt tag x)) With this kind of generator, as wingo says, we will get what we want but slowly. Might matter sometimes and not somtimes. What we would have liked here is some way of noticing that the liveness of "tag" is somewhat lexical and cannot be hidden in f. With that information a compiler would be able to inline code quite efficiently and make extensive use of gotos. How? Let's see how finish is working (define-syntax-parameter finish) (define-syntax-rule (iterate c ...) (syntax-parametrize ((finish (syntax-rules () ((_ x) (apport-to-prompt tag2 x))))) (call-with-prompt (lambda () loop code) (lambda _ final code)))) This whole setup would then be identified to something like (seqence loop: (with-frame g (generator thunk) code ...) finish: finish-code) To make the compilation to glil simple we mean by with-frame that we can setup a stack area where we can inline the thunk code and then a call to g like (next g) == (g) we can identify that 1. if (g) returns it will be from the abort clause in the prompt because the next part will jump to the finish part in the section which is below the generator frame and then it's possible to mark that stack space void. 2 The usage of the continuation is that we overwrite the same stack space with continuos versions of k's e.g. this is a characterizatin that we can keep the stack as a storage for this continuation. 3 with-frame is not recursive in g e.g. g is not visible inside thunk 4 So we should be able to make this work with intelligent usage of gotos. No, (f x) will be a problem because that we cannot know how much stack-space that function is needing. 5 What is interesting with the rtl format is that function applications are setuped at the end of the stack frame. This means that imersion of a generator is pretty simple using gotos and for rtl we would be able to manage quite general iterators and inline them with quite simple means. My conclusion is that for wip-rtl we should really start working on a prompt ideom that is lexical. But is it general enough. probably, but if you If you consider the main use case to be inlinable code, then you would need to consider the following tree-il extension (lexical-rec-prompts (name thunk abort-lam) ...) where name ... is visible inside the thunk's and abort's sections. Of cause not all versions of this code will be possible to manage without long-jumps and old pompt like features. (to note, CL's tagbody seams to be a very similar notion) Am I out in the blue or do you agree? Cheers Stefan.