On Monday 10 December 2007 13:37, Daniel Ehrenberg wrote:

> I see the logic in doing this.

Cool.

> But the reason I tend to stay away from that is that
> I like to think of most words as having meaning alone.

What does that have to do with anything? And what do you mean by "having 
meaning alone"?

> An add-malloc word of stack effect ( alien -- alien ) does have meaning
> by itself

So, you stay away from using this technique because you like words "having 
meaning alone". But you then say that add-malloc has meaning alone. I'm 
confused.

> it wouldn't be consistent with the convention that
> words generally don't leave their arguments in place like that.

Aha, this I understand; it's clearly stated with no contradictions. It's 
another way of saying "that's not how we do things around here". The point of 
alot of my notes to this list is that, I'm doing something that is unusual or 
new. If I put something out there for folks to ponder over, I welcome 
interesting feedback. Maybe I made a mistake. Or perhaps there's a flaw in 
the technique. Some intelligent analysis is always welcome. But responding to 
tell me that "that's not the convention we follow here" is not helpful.

> To me, the data flow is more clear with a dup before the
> invocation of add-malloc. But everyone has their own preferences.

Minimizing the number of words in a definition is a generally accepted goal in 
crafting stack based code. I don't often hear folks argue for adding words so 
that the "data flow is more clear".

Sorry I took a while to respond to the thread.

Ed

> On Dec 9, 2007 5:52 PM, Eduardo Cavazos <[EMAIL PROTECTED]> wrote:
> > Hello,
> >
> > I'd say there's more than one style of code factoring. In one style,
> > you see a pattern that exists in multiple words. You name that
> > pattern, make a word, and replace the patterns with the name.
> >
> > There's another kind of factoring however. Factoring calls to shuffle
> > words. Here's a very simple example using the current source tree.
> >
> > Take a look at the add-malloc word in the libc vocab :
> > : add-malloc ( alien -- ) dup mallocs get-global set-at ;
> >
> > It's used by three words, malloc calloc realloc :
> > : malloc ( size -- alien ) (malloc) check-ptr dup add-malloc ;
> > :
> > : calloc ( count size -- alien ) (calloc) check-ptr dup add-malloc ;
> > :
> > : realloc ( alien size -- newalien )
> >
> >     over malloc-exists? [ realloc-error ] unless
> >     dupd (realloc) check-ptr
> >     swap delete-malloc
> >     dup add-malloc ;
> >
> > In each definition, find the call to add-malloc. What word is called
> > right before each call to add-malloc?
> >
> > This is an opportunity to factor out the shuffle word 'dup'. We can
> >
> > change add-malloc to be:
> > : add-malloc ( alien -- alien ) dup dup mallocs get-global set-at ;
> >
> > The stack effect has changed from
> >
> >     ( alien -- )
> >
> > to
> >
> >     ( alien -- alien )
> >
> > Now the three dependent words are:
> > : malloc ( size -- alien ) (malloc) check-ptr add-malloc ;
> > :
> > : calloc ( count size -- alien ) (calloc) check-ptr add-malloc ;
> > :
> > : realloc ( alien size -- newalien )
> >
> >     over malloc-exists? [ realloc-error ] unless
> >     dupd (realloc) check-ptr
> >     swap delete-malloc
> >
> > In each case, we just deleted the 'dup' preceding the 'add-malloc'.
> >
> > The net effect is, we added a 'dup' in one word and deleted three
> > 'dup' calls in other places. The factor pays for itself.
> >
> > Ed

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to