Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.forth

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-20-2012, 12:43 PM
Albert van der Horst
Guest
 
Posts: n/a
Default Using a wid for formatting.

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

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 06-20-2012, 10:38 PM
JennyB
Guest
 
Posts: n/a
Default Re: Using a wid for formatting.

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


Reply With Quote
  #3 (permalink)  
Old 06-20-2012, 11:03 PM
Pablo Hugo Reda
Guest
 
Posts: n/a
Default Re: Using a wid for formatting.

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??
Reply With Quote
  #4 (permalink)  
Old 06-21-2012, 08:45 AM
Albert van der Horst
Guest
 
Posts: n/a
Default Re: Using a wid for formatting.

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

Reply With Quote
  #5 (permalink)  
Old 06-21-2012, 12:56 PM
Pablo Hugo Reda
Guest
 
Posts: n/a
Default Re: Using a wid for formatting.

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
Reply With Quote
  #6 (permalink)  
Old 06-23-2012, 02:09 AM
Krishna Myneni
Guest
 
Posts: n/a
Default Re: Using a wid for formatting.

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

Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 07:01 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.