Is smartness the problem?

  • Follow


Recently we had a discussion about formatting.
The basic idea is:

AVAILABLE "HOST" GET-ENV
"The computer %s has %d bytes available"  FORMAT&TYPE

What FORMAT&TYPE does is
1. split at the % , collect first part
2. identify a word e.g. s , use it as a formatter
3. EXECUTE s , which gives a string, collect that string
4. repeat at step 1 until format string exhausted
5. TYPE the string thus collected

Similarly we have FORMAT&EVAL

We make a wordlist with formatters s and d.

Alternative implementations are now
1. once you find the string  "s" or "d"  evaluate it
   with the formatters at the top of the search order.
2. Use SEARCH-WORD-LIST and EXECUTE

I've been bitten hard by a problem caused by using 1
and the existance of STATE. There is no smart
word in sight, but it smells the same.

I want to add the phrase
" ^%s @ %d  +" to a method definition, where at %s
the name of the class is to be filled in and at %d
the offset of the field where the method is supposed to
work.
The string e.g. "^VECTOR @  4 + " has to be evaluated in
compilation mode.

However I got the string "^ @ +". It took me some time
to realize that evaluating "s" in compilation mode,
merely added s to the current definition, and did nothing
to end up in the collected string.

So, I wonder what wise lessons concerning STATE I missed
to get into this trouble.

(I solve this by method 2 and using a lightweight
SEARCH-WORDLIST . My two screen mini-objects is now
a one screen mini-objects plus a one screen formatter, which
is independantly useful.
An alternative is stacking STATE and switching to execution
mode. )

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

0
Reply albert37 (2989) 7/14/2012 11:25:16 AM

Albert van der Horst <albert@spenarnc.xs4all.nl> writes:
>Recently we had a discussion about formatting.
>The basic idea is:
>
>AVAILABLE "HOST" GET-ENV
>"The computer %s has %d bytes available"  FORMAT&TYPE
>
>What FORMAT&TYPE does is
....
>3. EXECUTE s , which gives a string, collect that string
....
>Alternative implementations are now
>1. once you find the string  "s" or "d"  evaluate it
>   with the formatters at the top of the search order.
>2. Use SEARCH-WORD-LIST and EXECUTE

In 3. you say that you EXECUTE it, so EVALUATE (1.) is out.

>I've been bitten hard by a problem caused by using 1
>and the existance of STATE. There is no smart
>word in sight, but it smells the same.
>
>I want to add the phrase
>" ^%s @ %d  +" to a method definition, where at %s
>the name of the class is to be filled in and at %d
>the offset of the field where the method is supposed to
>work.
>The string e.g. "^VECTOR @  4 + " has to be evaluated in
>compilation mode.
>
>However I got the string "^ @ +". It took me some time
>to realize that evaluating "s" in compilation mode,
>merely added s to the current definition, and did nothing
>to end up in the collected string.
>
>So, I wonder what wise lessons concerning STATE I missed
>to get into this trouble.

EVALUATE does not work in general for most of the things that people
want to do with it (but it appears to work for simple cases), because
it uses a lot of context that people do not want in general (at least
not at EVALUATE run-time, when it is used by EVALUATE).  STATE is
among that context.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2012: http://www.euroforth.org/ef12/
0
Reply anton (5254) 7/14/2012 11:53:07 AM


Albert van der Horst wrote:

> Recently we had a discussion about formatting.
> The basic idea is:
> 
> AVAILABLE "HOST" GET-ENV
> "The computer %s has %d bytes available"  FORMAT&TYPE

We have SUBSTITUTE, which implements macro-replacement.  I've added that 
to Gforth, and you can actually define your own macros, which access 
values on the stack (standard SUBSTITUTE only replaces text macros).  So 
you can write

macros-wordlist set-current  ok         
: d tuck dabs <# #s rot sign #> ;  ok
definitions  ok
1234. s" Number %d%" pad 100 substitute drop type Number 1234 ok

A standard way of doing that would be

: d tuck dabs <# #s rot sign #> ;
1234. d s" d" replaces
1234. s" Number %d%" pad 100 substitute drop type Number 1234 ok

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

0
Reply bernd.paysan (2408) 7/14/2012 1:26:51 PM

2 Replies
49 Views

(page loaded in 0.247 seconds)

Similiar Articles:













7/23/2012 10:07:31 AM


Reply: