6.2.1675 HOLDS CORE EXT

( c-addr u -- )

Adds the string represented by c-addr u to the pictured numeric output string. An ambiguous condition exists if HOLDS executes outside of a <# #> delimited number conversion.

See:

Implementation:

: HOLDS ( addr u -- )
   BEGIN DUP WHILE 1- 2DUP + C@ HOLD REPEAT 2DROP ;

Testing:

T{ 0. <# S" Test" HOLDS #> S" Test" COMPARE -> 0 }T

ContributeContributions

GerryJacksonavatar of GerryJackson [61] Specification of HOLDS is ambiguousComment2018-06-27 15:59:05

The description doesn't make it clear that the string is prepended to the existing contents of the pictured output buffer. That can be deduced from the reference implementation but a user shouldn't have to do that.

Also the test does not make it clear. Suggest adding a test along the lines:

T{ <# 123 0 #S S" Number: " HOLDS #> " Number: 123" COMPARE -> 0  }T

GerryJacksonavatar of GerryJackson

Sorry the test should read:

T{ <# 123 0 #S S" Number: " HOLDS #> S" Number: 123" COMPARE -> 0  }T

BerndPaysanavatar of BerndPaysan

Yes, same issue with XHOLD; apparently everybody assumed that adding to the pictured numeric output buffer always means “before”, not after. That's why the language felt clear enough.

MitraArdronavatar of MitraArdron

I agree with Gerry, neither the test nor the description is unambiguous (only the implementation, which is great to see , but shouldn't be relied on). IMHO the spec should be clear about prepend v append

Reply New Version