Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.forth Subject: Re: WITHIN Date: Sun, 09 Mar 2014 01:24:22 -0800 Organization: Nightsong/Fort GNOX Lines: 33 Message-ID: <7xob1fbu7t.fsf@ruckus.brouhaha.com> References: <52e54d17.461102185@news.demon.co.uk> <7xha7hiv3w.fsf@ruckus.brouhaha.com> <7xr46lruq1.fsf@ruckus.brouhaha.com> <7x7g8cvagd.fsf@ruckus.brouhaha.com> <2014Mar6.190908@mips.complang.tuwien.ac.at> <2014Mar7.135132@mips.complang.tuwien.ac.at> <7x7g85him2.fsf@ruckus.brouhaha.com> <2014Mar8.170211@mips.complang.tuwien.ac.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx05.eternal-september.org; posting-host="d94d289a4df6ae47ea4d4f8b2ae808e7"; logging-data="28408"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2UINqatHZFxTNFX306BwU" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:WTFSrbaYvu+reLmWmsDau2/9gBg= sha1:LIWyke8q8VLkI+D/DZQlLakw8Uc= Xref: csiph.com comp.lang.forth:28992 anton@mips.complang.tuwien.ac.at (Anton Ertl) writes: >> : endpoints { n a b -- a<=n n> : outside ( n a b -- flag ) endpoints or ; \ precondition: a > b >> : inside ( n a b -- flag ) endpoints and ; \ precondition: a <= b > > Looks overfactored to me. In particular, I don't see ENDPOINTS as > representing a concept. Hmm, I thought the idea was to avoid duplicating code. I guess I could have called it CHECKBOUNDS, since it compares the test point against the two boundary points A and B. > In any case, I think that the proper WITHIN is superior in every way. I'd agree it's a better implementation for 2's complement integers. It seems to me there are plausible use cases for floats, strings, bignums, and various other types. There was even a Forth-like cpu that used ternary instead of binary for integers: http://brokestream.com/daf.txt http://en.wikipedia.org/wiki/Setun > If you have trouble following it, see it as an incentive to learn > about modulo arithmetics. In my case it made sense after it became clear (from Andrew's post) what the function was actually supposed to do. It was more obscure in the ANS glossary, in part because of the stack juggling in the reference implementation, and in part because the verbosity of the documentation made it sound more complicated than it was. The ANS glossary might not be a place for it, but in a tutorial I think it would be clearer exposition to present the generic version first, then the optimized version.