Maxim Savtchenko | 22 Apr 05:35
Picon

Named shufflers (rethought of "factor-way locals" idea)

Idea of local storage in more factor-way still looks interesting for
me. I have followed Slava's advice about "implement and play a
little". It was interesting and not-so-hard experience. Here are
results.

If I want to dismiss annoying "stack micro-management", there is no
need for additional named stacks. Instead of it I had come to
"stack-marking named shufflers" paradigm. I'd like to show it on
simple and common (for me) example from my dns library. What if we
need "virtual" stream that incapsulates some "real" stream and simply
counts number of symbols we are reading?

TUPLE: dns-stream counter ;

: <dns-stream> ( stream -- stream )
	0 dns-stream construct-boa tuck set-delegate ;

M: dns-stream stream-read
	tuck delegate stream-read dup length
	pick dns-stream-counter + rot set-dns-stream-counter ;

In realization of stream-read method we have four different shuffling
words - tuck, dup, pick and rot. It is simpliest solution I've found
with ordinal shufflers. Let's explain true meaning of used shufflers:

1) "tuck" - we need delegate of our stream, but we will need original
tuple in later processing, Lets store it for future use.
2) "dup" - we need length of data, but we also need to return data as
method exit value. Lets store it for future use.
3) "pick" - we need to recall previously saved tuple. But again, we
(Continue reading)

Eduardo Cavazos | 22 Apr 06:33
Picon

Re: Named shufflers (rethought of "factor-way locals" idea)

Hi Maxim,

I like your idea and think it's worth further exploration.

You're right that the stream-read method you show is a little more awkward 
than it should be.

Here's one way I might go about implementing stream-read:

	Use inheritance
	Factor out the counter update code
	Use new slot accessors

The 'adjust-counter' factor might look like this:

: adjust-counter ( dns-stream string -- string )
  tuck
  length
  over counter>> + >>counter drop ;

Or in terms of a slot changer:

: adjust-counter ( dns-stream string -- string )
  tuck length [ + ] curry change-counter ;

Then the 'stream-read' method becomes (using the new syntax):

METHOD: stream-read { integer dns-stream -- str/f }
  tuck
  stream-read
(Continue reading)

Maxim Savtchenko | 22 Apr 07:49
Picon

Re: Named shufflers (rethought of "factor-way locals" idea)

Thank you for reply. Slot changers are juisy.

Damn. It looks like I need git for all this beautiful bleeding-edge features.

On Tue, Apr 22, 2008 at 8:33 AM, Eduardo Cavazos
<wayo.cavazos@...> wrote:
> Hi Maxim,
>
> I like your idea and think it's worth further exploration.
>
> You're right that the stream-read method you show is a little more awkward
> than it should be.
>
> Here's one way I might go about implementing stream-read:
>
>        Use inheritance
>        Factor out the counter update code
>        Use new slot accessors
>
> The 'adjust-counter' factor might look like this:
>
> : adjust-counter ( dns-stream string -- string )
>  tuck
>  length
>  over counter>> + >>counter drop ;
>
> Or in terms of a slot changer:
>
> : adjust-counter ( dns-stream string -- string )
>  tuck length [ + ] curry change-counter ;
(Continue reading)

Maxim Savtchenko | 22 Apr 08:13
Picon

Re: Named shufflers (rethought of "factor-way locals" idea)

Oops. Mistyped a little.

">: foo" is synonim for "=: drop".

should be

">: foo" is synonim for "=: foo drop".

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Eduardo Cavazos | 22 Apr 09:20
Picon

Re: Named shufflers (rethought of "factor-way locals" idea)

Maxim Savtchenko wrote:

> Damn. It looks like I need git for all this beautiful bleeding-edge
> features.

If you have some more code which is more complicated than you'd like it to be, 
feel free to post it and we'll see if any new features can be used to 
simplify it.

> Thank you for reply. Slot changers are juisy.

Recently I wrote about unifying accessors on sequences, tables, and tuples. 
One part of that experiment is having a 'change' word which works across all 
of those:

	GENERIC: change ( collection key quot -- collection )

And some effect variants:

	GENERIC: change-at  ( collection quot key -- collection )
	GENERIC: changed-at ( collection quot key -- )

So the 'adjust-counter' would look like this:

: adjust-counter ( dns-stream string -- string )
  tuck length [ + ] curry :counter changed-at ;

There is an implementation benefit from having a general 'change' as opposed 
to slot specific changers generated for each slot: the image size is reduced.

(Continue reading)

Maxim Savtchenko | 22 Apr 15:47
Picon

Re: Named shufflers (rethought of "factor-way locals" idea)

On Tue, Apr 22, 2008 at 11:20 AM, Eduardo Cavazos
<wayo.cavazos@...> wrote:
> If you have some more code which is more complicated than you'd like it to be,
> feel free to post it and we'll see if any new features can be used to
> simplify it.

OK. This would be really helpful.

And about elemination of autogenerated accessors and predicates -
awesome! For me autogenerated words always looked unnatural solution.
Why should someone generate custom code for every possible case, while
there is so powerfull optimizer?..

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Adam | 22 Apr 20:39
Picon

Re: Named shufflers (rethought of "factor-way locals" idea)

Maxim,

The latest binary builds at http://factorcode.org/getfactor.fhtml have
the features you'd want.

On Tue, Apr 22, 2008 at 6:47 AM, Maxim Savtchenko <pdunan@...> wrote:
> On Tue, Apr 22, 2008 at 11:20 AM, Eduardo Cavazos
>
> <wayo.cavazos@...> wrote:
>
> > If you have some more code which is more complicated than you'd like it to be,
>  > feel free to post it and we'll see if any new features can be used to
>  > simplify it.
>
>  OK. This would be really helpful.
>
>  And about elemination of autogenerated accessors and predicates -
>  awesome! For me autogenerated words always looked unnatural solution.
>  Why should someone generate custom code for every possible case, while
>  there is so powerfull optimizer?..
>
>
>
>  -------------------------------------------------------------------------
>  This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>  Don't miss this year's exciting event. There's still time to save $100.
>  Use priority code J8TL2D2.
>  http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>  _______________________________________________
>  Factor-talk mailing list
(Continue reading)

Maxim Savtchenko | 22 Apr 22:33
Picon

Re: Named shufflers (rethought of "factor-way locals" idea)

Wow. That's something new. Haven't seen yet. I'll try, thank you.

On Tue, Apr 22, 2008 at 10:39 PM, Adam <hiatoms@...> wrote:
> Maxim,
>
>  The latest binary builds at http://factorcode.org/getfactor.fhtml have
>  the features you'd want.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

Gmane