Number ranges in edits (was Re: EDIT Quiz)

Kenneth Brody kenbrody at spamcop.net
Wed Aug 24 15:03:31 PDT 2011


On 8/24/2011 12:50 PM, Kenneth Brody wrote:
[...]
> On a related note, how would you write an edit for:
>
>     Allow only two-digit numbers from "01" through "12", removing the
>     leading zero, if any.

Well, the "obvious" method is the "simple":

     Remove a leading zero, and allow a digit "1" through "9".
     -or-
     Allow a "1" followed by a "0", "1", or "2".

     ( !0! ("1"-"9") ) | ( "1" ( "0"-"2") )

You did remember the "-" range specifier, didn't you?  (Yes, it's been in 
since 1.0, and it's been documented since then as well, in addition to being 
used in several filePro-supplied global edits.)  That makes "1" through "9" 
a lot easier to specify, doesn't it?

Of course, that doesn't scale well, which is why I asked part 2 of this 
question:

> Additionally, what about:
>
>     Allow only three-digit numbers from "165" to "433".  (Yes, those _are_
>     just pulled out of the hat.  What about it?  Who says real life needs
>     have to be round numbers?)

I'd hate to write an edit that took that brute-force method:

     Allow a "1",
         Followed by a "6" and then "5"-"9".
         - or -
         Followed by "7"-"9", followed by a digit.
     - or -
     Allow a "2" or "3", followed by two digits.
     - or -
     Allow a "4",
         Followed by ("0"-"2"), followed by a digit.
         - or -
         Followed by "3", followed by "0"-"3".

(Remember that you can use the "N" edit for "a digit" to help "simplify" 
this monstrosity.)

So, how would I do it?

Well, as I told someone else who asked privately, I would write an edit that 
turns out to be only 17 characters long.  :-)

At first you might say "now that I've been reminded of the range specifier, 
why not just use this edit?"

     "165"-"433"

Well, that sounds good at first.  But, you need to realize that "3-D" fits 
that edit.

You need to restrict the edit to only digits.  That's where another 
"available, and documented, since 1.0" feature -- "&" -- comes along.  You 
need to say "within this range _and_ only digits":

     "165"-"433"&N N N


Did anyone remember the "-" range specifier?  What about the "&" operator?


BTW, my solution to Nancy's edit was:

     { ( ("01"-"12")&((!0!|N)N) ) ( @ | <,> ) }

-- 
Kenneth Brody


More information about the Filepro-list mailing list