22 Apr 05:35
Named shufflers (rethought of "factor-way locals" idea)
From: Maxim Savtchenko <pdunan@...>
Subject: Named shufflers (rethought of "factor-way locals" idea)
Newsgroups: gmane.comp.lang.factor.general
Date: 2008-04-22 03:36:43 GMT
Subject: Named shufflers (rethought of "factor-way locals" idea)
Newsgroups: gmane.comp.lang.factor.general
Date: 2008-04-22 03:36:43 GMT
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)
RSS Feed