Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #37687
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Is there a better way? |
| Date | 2015-03-27 06:03 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <mf2rql$js6$2@dont-email.me> (permalink) |
| References | <70a117c1-ba9f-474b-97f3-6440be3d4573@k20g2000vbj.googlegroups.com> <kh1rjc02oau@enews2.newsguy.com> |
WJ wrote: > Mark Wills wrote: > > > The following routine is checking to see if a string is "}}" i.e. > > consists of two consequtive right curly braces. > > > > : }}? ( addr len -- addr len flag) > > dup 2= if > > over dup c@ swap 1+ c@ 125 = swap 125 = and > > else > > false > > then ; > > > > As can be seen, the first check is the length; if the length is not > > exactly 2 then we just return false. If the length is 2 then we check > > to see if both characters are ASCII 125. That's the bit I am looking > > at and saying "Meh... seems a bit convoluted/lengthy. > > > > Is there a better way? > > > > I was thinking maybe: > > > > ... c@ 125 OR swap 1+ c@ 125 OR 125 XOR 0= > > > > Which is perhaps "cleverer" but not as clear as to the intention of > > the code and no shorter... > > Factor: > > "}}" "}}" = . > t > > "}}" "@@" = . > f Oforth: > "}}" "}}" == println -1 ok > "}}" "}" == println 0 ok > "}}" "}?" == println 0
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Re: Is there a better way? "WJ" <w_a_x_man@yahoo.com> - 2015-03-27 06:03 +0000
csiph-web