Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Force string value?

65 views
Skip to first unread message

Yurii Rashkovskii

unread,
Jul 22, 2010, 4:59:42 PM7/22/10
to
Hi,

Is there any way to force GT.M not to treat a string with a canonical
number as a number? I.e. if I do SET x("380")="",x("3791")="", instead
of this order:

x(380)=""
x(3791)=""

I would like to get this one:

x("3791")=""
x("380")=""

I know the most obvious solution — prepend these key values with some
non-numeric character, but it will certainly cause some logical
complication for setting/reading/indexing. Is there any better
solution?

JJ

unread,
Jul 22, 2010, 8:47:27 PM7/22/10
to

Just curious but *why* would you want to do this?
--
JJ

dahakon

unread,
Jul 22, 2010, 10:47:09 PM7/22/10
to

You can define a custom collation sequence and use it for globals and
local variables.

For more details, see the internationalization chapter of the
programmer's guide:
http://tinco.pair.com/bhaskar/gtm/doc/books/pg/UNIX_manual/chapter13.htm
l


Yurii Rashkovskii <yra...@gmail.com> wrote in news:3f18d6b8-af2f-4e43-
afad-128...@q21g2000prm.googlegroups.com:

Yurii Rashkovskii

unread,
Jul 23, 2010, 2:13:02 AM7/23/10
to
On Jul 22, 5:47 pm, JJ <jeffersonjj.nos...@hotmail.com> wrote:

> > x("380")=""
>
> > I know the most obvious solution   prepend these key values with some
> > non-numeric character, but it will certainly cause some logical
> > complication for setting/reading/indexing. Is there any better
> > solution?
>
> Just curious but *why* would you want to do this?

Phone prefixes. They aren't numbers, they are essentially strings that
happen to consist of numbers, therefore 3791 goes before 380.

Yurii Rashkovskii

unread,
Jul 23, 2010, 2:14:22 AM7/23/10
to
On Jul 22, 7:47 pm, dahakon <n...@valid.com> wrote:

> You can define a custom collation sequence and use it for globals and
> local variables.
>
> For more details, see the internationalization chapter of the
> programmer's guide:http://tinco.pair.com/bhaskar/gtm/doc/books/pg/UNIX_manual/chapter13.htm
>

Yeah, I know about this (didn't try it yet, though), but isn't it a
region-wide setting? I just need this kind of "string enforcement"
only for some very few subscripts.

Yurii Rashkovskii

unread,
Jul 23, 2010, 3:08:06 AM7/23/10
to
On Jul 22, 11:14 pm, Yurii Rashkovskii <yra...@gmail.com> wrote:

>
> Yeah, I know about this (didn't try it yet, though), but isn't it a
> region-wide setting

Or it can be global-wide, but can't be enforced on a particular
subscript or a value.

Yurii Rashkovskii

unread,
Jul 23, 2010, 7:21:08 AM7/23/10
to
On Jul 22, 7:47 pm, dahakon <n...@valid.com> wrote:
> You can define a custom collation sequence and use it for globals and
> local variables.
>
> For more details, see the internationalization chapter of the
> programmer's guide:http://tinco.pair.com/bhaskar/gtm/doc/books/pg/UNIX_manual/chapter13.htm
> l

So I did this, quick-n-dirty version of the source code is available
at https://gist.github.com/7187e3c76ad7e39a49fd

The only problem with it is that even though it seems to work
perfectly well for storage & retrieval (you just have to prepend
subscript with $c(255)), any explicit or implicit ordering (say, $o)
has no idea about that and will effectively disrupt proper workflow,
UNLESS the key used in it is prepended with $c(255) itself so the
value becomes a "forced string" as well. Otherwise it will consider
provided key a number and next key will be the very first string key,
which is clearly not what what you want to get in this scenario. In my
case, I can workaround this by always prepending keys with that
$c(255) as I always have that information on whether this particular
subset of the global is a forced string or not. Also, as a side
effect, ZWR will hang on globals with forced strings.

So, I have mixed feelings about this solution. On one hand, it works,
on the other hand it causes some inconvenience (or, what's worse,
potentially hanging GT.M when the key is not prepended with that
prefix).

Anyway, thanks for the help everybody!

Julius Kavay

unread,
Jul 23, 2010, 8:43:57 AM7/23/10
to

if you really want this order (3791 followed by 380) then
just append zeros or blanks to a fixed length.

Assuming, the longest prefix is 8 character long:

Variante a)
-----------
Kill ^Prefix
Set nul="00000000"
For pref=3791,380 Set ^Prefix($e(pref_nul,1,8)_$l(pref))=""

Set pref=""
For Set pref=$O(^Prefix(pref)) Quit:pref="" Write $e(pref,1,pref#10),!

^Prefix(379100004)=""
^Prefix(380000003)=""


Variante b)
-----------
Kill ^Prefix
Set spc=" "
For pref=3791,380 Set ^Prefix($e(pref_spc,1,8))=""

Set pref=""
For Set pref=$o(^Prefix(pref)) Quit:pref="" Write $p(pref," "),!

^Prefix("3791 ")=""
^Prefix("380 ")=""

Just for the curiosity, long time ago, I worked on a MUMPS system
where numbers with leading zeros were sorted by their length and
not by their value:

0,1,2,..8,9,00,01,02,..08,09,10,11,12,...98,99,000,001,002,..008,
009,010,011,012,...098,099,100,101,102 and so on.

It was perfect for article- or itemnumbers, bank accounts etc.

Regards and
have a nice day
Julius


--
(my real mail address ends with a .net tld)

Maury Pepper

unread,
Jul 23, 2010, 11:48:41 AM7/23/10
to

"Julius Kavay" <ka...@gmx.net.valid.address.changed.to.invalid> wrote in message news:8ath4e...@mid.individual.net...

A single space on the end will work and often is just what you want for output - if not, it's easy to remove.

0 new messages