[Factor-talk] Macro puzzle

2009-02-14 Thread Matt Gushee
Hi, all-- Okay, so I am trying to understand how macros work in Factor. I wrote my first macro last night, which looks like this: MACRO: print-with-suffix ( str -- ) append print ; Then I can define a word in terms of the macro: : print-with-yeah ( str -- ) " yeah!" print-with-suffix ;

Re: [Factor-talk] Macro puzzle

2009-02-14 Thread Doug Coleman
Hi Matt, You don't need a macro to do what you're doing: : print-with-suffix ( str -- ) append print ; is correct as is. Macros are for expanding code at compile-time. In the UI, do "macros" about and read the docs. Some good examples of macros are in basis/generalizations and basis/combin

Re: [Factor-talk] Macro puzzle

2009-02-14 Thread Slava Pestov
Matt, Doug wrote a very detailed e-mail that explains everything; I'd just like to add a couple of minor points. If it wasn't for the compiler, then the following would be equivalent: MACRO: foo ( x -- ) bar ; : foo ( x -- ) bar call ; What the compiler does, then, is if it encounters a call to

Re: [Factor-talk] Macro puzzle

2009-02-15 Thread Matt Gushee
Doug Coleman wrote: > You don't need a macro to do what you're doing: > > : print-with-suffix ( str -- ) append print ; Oh, yeah ... I knew that, sort of. My example was derived from something I was recently working with in Scheme, which really did need to be a macro. I simplified it to try to

Re: [Factor-talk] Macro puzzle

2009-02-15 Thread Slava Pestov
On Sun, Feb 15, 2009 at 6:13 PM, Matt Gushee wrote: > BTW, I would still like to see a precise definition of "static stack > effect." This article explains the details, http://docs.factorcode.org/content/article-inference.html Slava -

Re: [Factor-talk] Macro puzzle

2009-02-15 Thread Alex Chapman
Hi Matt, > BTW, I would still like to see a precise definition of "static stack > effect." Briefly, a word with a static stack effect has the same stack effect every time it is run. For example, drop ( x -- ). This is in contrast to words with a dynamic stack effect, such as call, whose stack eff