|
|||
|
Last we discussed the usage of format strings,
best illustrated with an example. "AAP" 123 "number=%d DIER=%s" FORMAT TYPE number=123 DIER=AAP OK This can be implemented by having words d and s that are evaluated. Now nobody wants to have short global names like s and d defined, so they are best hidden in a wordlist (using NAMESPACE) NAMESPACE _FORMAT-WORDLIST GET-CURRENT ' _FORMAT-WORDLIST >WID SET-CURRENT : d ... ; : s ... ; SET-CURRENT \ Pop the wid again Now we can use SEARCH-WORDLIST and EXECUTE (rather than EVALUATE) Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst |
|
|
||||
|
||||
|
|
|
|||
|
On Wednesday, 20 June 2012 13:43:05 UTC+1, Albert van der Horst wrote:
> Last we discussed the usage of format strings, > best illustrated with an example. > > "AAP" 123 "number=%d DIER=%s" FORMAT TYPE > > number=123 DIER=AAP OK > > This can be implemented by having words d and s that are > evaluated. > Now nobody wants to have short global names like s and d defined, so > they are best hidden in a wordlist (using NAMESPACE) > > NAMESPACE _FORMAT-WORDLIST > GET-CURRENT ' _FORMAT-WORDLIST >WID SET-CURRENT > : d ... ; > : s ... ; > SET-CURRENT \ Pop the wid again > > Now we can use SEARCH-WORDLIST and EXECUTE (rather than EVALUATE) From memory: : SERVANT ( wid xt ++ ) CREATE 2, DOES> ( c-addr u -- ? ) 2@ >R SEARCH-WORDLIST IF R> DROP EXECUTE ELSE R> EXECUTE THEN ; The action taken if the token is not found may itself be a SERVANT |
|
|||
|
Albert:
I implement format string, I do things like dup "tos=%d" print cr or "hi" 3.4 "value=%f str=%s" mprint | to memory one problem I have with this is when need a double print (format string) 23 "hvalue=%h" mprint "result=%s" print when deal with database is usual and only I fix in the first parameter mprint work in the first free memory and discart later and I check if the first parameter is the memory work and then I use other address. how you deal with this situation?? |
|
|||
|
In article <8b21be3c-8bbe-4b89-a3ef-56322b9f37e6@j25g2000yqn.googlegroups.com>,
Pablo Hugo Reda <pabloreda@gmail.com> wrote: >Albert: > >I implement format string, I do things like > >dup "tos=%d" print cr > >or > >"hi" 3.4 "value=%f str=%s" mprint | to memory > >one problem I have with this is when need a double print (format >string) > >23 "hvalue=%h" mprint "result=%s" print > >when deal with database is usual and only I fix in the first parameter >mprint work in the first free memory and discart later and I check if >the first parameter is the memory work and then I use other address. > >how you deal with this situation?? A avoid B 23 "hvalue=%h" mprint PAD $! PAD $@ "result=%s" print C Beyond that, you will need the ALLOCATE wordset. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst |
|
|||
|
On 21 jun, 05:45, Albert van der Horst <alb...@spenarnc.xs4all.nl>
wrote: > In article <8b21be3c-8bbe-4b89-a3ef-56322b9f3...@j25g2000yqn.googlegroups..com>, > Pablo Hugo Reda *<pablor...@gmail.com> wrote: > > > > > > > > > > >Albert: > > >I implement format string, I do things like > > >dup "tos=%d" print cr > > >or > > >"hi" 3.4 "value=%f str=%s" mprint | to memory > > >one problem I have with this is when need a double print (format > >string) > > >23 "hvalue=%h" mprint "result=%s" print > > >when deal with database is usual and only I fix in the first parameter > >mprint work in the first free memory and discart later and I check if > >the first parameter is the memory work and then I use other address. > > >how you deal with this situation?? > > A > avoid > > B > 23 "hvalue=%h" mprint PAD $! > PAD $@ "result=%s" print > > C > Beyond that, you will need the ALLOCATE wordset. > > Groetjes Albert > > -- > -- > Albert van der Horst, UTRECHT,THE NETHERLANDS > .growth -- being exponential -- ultimately falters. > albert@spe&ar&c.xs4all.nl &=nhttp://home.hccnet.nl/a.w.m.van.der.horst ok... then current implementation is better thks |
|
|||
|
On Jun 20, 7:43*am, Albert van der Horst <alb...@spenarnc.xs4all.nl>
wrote: > Last we discussed the usage of format strings, > best illustrated with an example. > > "AAP" 123 *"number=%d *DIER=%s" FORMAT TYPE > > number=123 DIER=AAP OK > > This can be implemented by having words d and s that are > evaluated. > Now nobody wants to have short global names like s and d defined, so > they are best hidden in a wordlist (using NAMESPACE) > > NAMESPACE _FORMAT-WORDLIST > GET-CURRENT ' _FORMAT-WORDLIST >WID SET-CURRENT > : d ... ; > : s ... ; > SET-CURRENT \ Pop the wid again > > Now we can use SEARCH-WORDLIST and EXECUTE (rather than EVALUATE) > I recommend trying our modules framework (link below) for creating a library of formatting words. This will save you the need to manually fiddle with the search order, while providing private definitions which are found earlier in the search order. Cheers, Krishna -- ftp://ccreweb.org/software/gforth/modules.fs |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|