Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #19784 > unrolled thread

Can i (easily) implement cell+ and cells in an Forth83 - like dialect

Started bycybercow222@gmail.com
First post2013-02-18 04:57 -0800
Last post2013-02-24 13:33 -0800
Articles 20 on this page of 59 — 16 participants

Back to article view | Back to comp.lang.forth


Contents

  Can i (easily) implement cell+ and cells in an Forth83 - like dialect cybercow222@gmail.com - 2013-02-18 04:57 -0800
    Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-18 14:17 +0100
      Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-18 14:18 +0100
        Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-18 21:57 +0000
          Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 00:10 +0100
            Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 00:15 +0100
              Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-18 18:39 -0500
                Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Elizabeth D. Rather" <erather@forth.com> - 2013-02-18 22:04 -1000
                  Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-19 08:39 +0000
                    Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 13:21 +0100
                      Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-19 13:12 +0000
                        Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 14:29 +0100
                          Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 14:54 +0100
                            Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-19 16:25 +0000
                              Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 18:29 +0100
                                Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 19:16 +0100
                                  Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Mark Wills <forthfreak@gmail.com> - 2013-02-20 01:07 -0800
                                    Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 12:36 +0100
                                      Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Lars Brinkhoff <lars.spam@nocrew.org> - 2013-02-20 20:15 +0100
                                        Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 20:31 +0100
                                      Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-20 16:08 -0500
                                  Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-20 10:06 +0000
                                    Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 12:32 +0100
                                      Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-20 06:55 -0600
                                        Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 14:03 +0100
                                          Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-20 07:48 -0600
                                          Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-20 15:30 +0000
                            Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-19 18:08 -0500
                      Re: Can i (easily) implement cell+ and cells in an Forth83 - like   dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-19 16:55 +0000
                        Re: Can i (easily) implement cell+ and cells in an Forth83 - like   dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-19 18:42 +0100
                      Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-19 18:08 -0500
                        Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 00:20 +0100
                          Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-20 16:08 -0500
      Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-18 13:38 +0000
        Re: Can i (easily) implement cell+ and cells in an Forth83 - like  dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-18 15:39 +0100
          Re: Can i (easily) implement cell+ and cells in an Forth83 - like   dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-18 14:50 +0000
            Re: Can i (easily) implement cell+ and cells in an Forth83 - like   dialect "Elizabeth D. Rather" <erather@forth.com> - 2013-02-18 08:56 -1000
      Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Mark Wills <forthfreak@gmail.com> - 2013-02-18 06:38 -0800
    Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect cybercow222@gmail.com - 2013-02-18 06:00 -0800
      Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Matthias Koch <matthias.koch@hot.uni-hannover.de> - 2013-02-18 15:01 +0100
        Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Mark Wills <forthfreak@gmail.com> - 2013-02-18 06:40 -0800
        Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect awegel@arcor.de (Alex Wegel) - 2013-02-21 10:42 +0100
          Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-02-21 12:19 +0000
            Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-21 14:08 +0000
              Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-21 15:56 +0100
                Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Coos Haak <chforth@hccnet.nl> - 2013-02-21 16:31 +0100
      Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Elizabeth D. Rather" <erather@forth.com> - 2013-02-18 11:26 -1000
    Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect cybercow222@gmail.com - 2013-02-20 04:39 -0800
      Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-20 13:59 +0100
      Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-20 15:35 +0000
        Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Mark Wills <markrobertwills@yahoo.co.uk> - 2013-02-20 08:21 -0800
          Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Coos Haak <chforth@hccnet.nl> - 2013-02-21 01:06 +0100
            Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Mark Wills <markrobertwills@yahoo.co.uk> - 2013-02-20 23:04 -0800
          Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect awegel@arcor.de (Alex Wegel) - 2013-02-21 10:42 +0100
    Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2013-02-23 15:14 -0800
      Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Paul Rubin <no.email@nospam.invalid> - 2013-02-23 15:33 -0800
      Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Coos Haak <chforth@hccnet.nl> - 2013-02-24 00:46 +0100
        Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect Coos Haak <chforth@hccnet.nl> - 2013-02-24 01:00 +0100
          Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2013-02-24 13:33 -0800

Page 1 of 3  [1] 2 3  Next page →


#19784 — Can i (easily) implement cell+ and cells in an Forth83 - like dialect

Fromcybercow222@gmail.com
Date2013-02-18 04:57 -0800
SubjectCan i (easily) implement cell+ and cells in an Forth83 - like dialect
Message-ID<219790de-4f45-45da-9376-963833800ab7@googlegroups.com>
Hi all, i'm currently doing some simple Forth experimentation on an simple Forth dialect (threaded) that more or less conforms to Froth-83 and came across this page: http://onestepback.org/articles/poly/gp-forth.html which explains how to make simple class / object alike pragma in forth. I really would like to do this example training, but my Forth doesn't have cell+ and cells words. Is there any kind of work-around i can do to get this sample running ?

Thank you in advance!

[toc] | [next] | [standalone]


#19785

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-18 14:17 +0100
Message-ID<slrnki4e27.c4b.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19784
In comp.lang.forth, cybercow222@gmail.com wrote:

> Hi all, i'm currently doing some simple Forth experimentation on an simple
> Forth dialect (threaded) that more or less conforms to Froth-83 and came
> across this page: http://onestepback.org/articles/poly/gp-forth.html which
> explains how to make simple class / object alike pragma in forth. I really
> would like to do this example training, but my Forth doesn't have cell+
> and cells words. Is there any kind of work-around i can do to get this
> sample running ?

Do you know, how is your cell size? Say, it is 4 bytes (for 32-bit system):

: cells (n -- )   4 * ;
: cell+ ( -- )   4 + ;

-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


#19786

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-18 14:18 +0100
Message-ID<slrnki4e4m.c4b.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19785
In comp.lang.forth, Zbiggy wrote:

>: cells (n -- )   4 * ;

OK, a typo:
: cells ( n -- )   4 * ;

Now 100% correct. :)
-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


#19804

FromstephenXXX@mpeforth.com (Stephen Pelc)
Date2013-02-18 21:57 +0000
Message-ID<5122a378.498962240@192.168.0.50>
In reply to#19786
On 18 Feb 2013 14:18:40 +0100, Zbiggy
<zbigniew2011REMOVE@gmail.REMOVE.com> wrote:

>In comp.lang.forth, Zbiggy wrote:
>
>>: cells (n -- )   4 * ;
>
>OK, a typo:
>: cells ( n -- )   4 * ;
>
>Now 100% correct. :)

Nope. Please fix the stack comment.

Stephen


-- 
Stephen Pelc, stephenXXX@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads

[toc] | [prev] | [next] | [standalone]


#19805

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-19 00:10 +0100
Message-ID<slrnki5gpr.1u3.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19804
In comp.lang.forth, Stephen Pelc wrote:

>>: cells ( n -- )   4 * ;
>>
>>Now 100% correct. :)
>
> Nope. Please fix the stack comment.

: cells ( n -- m )   4 * ;

(Don't cane me, sir! ;)
-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


#19806

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-19 00:15 +0100
Message-ID<slrnki5h3l.1r2.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19805
Or maybe rather     : cells ( n -- n*4 )   4 * ;
-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


#19807

From"Rod Pemberton" <do_not_have@notemailnotz.cnm>
Date2013-02-18 18:39 -0500
Message-ID<kfue13$kn6$1@speranza.aioe.org>
In reply to#19806
"Zbiggy" <zbigniew2011REMOVE@gmail.REMOVE.com> wrote in message
news:slrnki5h3l.1r2.zbigniew2011REMOVE@Tichy.myhome.org...
> Or maybe rather     : cells ( n -- n*4 )   4 * ;

What if the cell size changes?  You've got the cell's size
hardcoded in both the code and the comment ...  For readability,
it's probably better to define "cell" or "cellsize" or somesuch.


RP



[toc] | [prev] | [next] | [standalone]


#19809

From"Elizabeth D. Rather" <erather@forth.com>
Date2013-02-18 22:04 -1000
Message-ID<QP6dnYcdGMeMr77MnZ2dnUVZ_rOdnZ2d@supernews.com>
In reply to#19807
On 2/18/13 1:39 PM, Rod Pemberton wrote:
> "Zbiggy" <zbigniew2011REMOVE@gmail.REMOVE.com> wrote in message
> news:slrnki5h3l.1r2.zbigniew2011REMOVE@Tichy.myhome.org...
>> Or maybe rather     : cells ( n -- n*4 )   4 * ;
>
> What if the cell size changes?  You've got the cell's size
> hardcoded in both the code and the comment ...  For readability,
> it's probably better to define "cell" or "cellsize" or somesuch.

The cell size is a property of the *system*, not the application. The 
system is supposed to provide these words, and if applications use them 
instead of hard-coded numbers they'll be more portable.

In this particular case, the OP is stuck with a system on which these 
words are not provided, and asked how to define them in order to use 
some code that he's been given. In essence, he's providing a portability 
layer, which is not uncommon. The portability layer itself doesn't need 
to be portable, and in fact can't be and still be useful.

Cheers,
Elizabeth

-- 
==================================================
Elizabeth D. Rather   (US & Canada)   800-55-FORTH
FORTH Inc.                         +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================

[toc] | [prev] | [next] | [standalone]


#19810 — Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2013-02-19 08:39 +0000
SubjectRe: Can i (easily) implement cell+ and cells in an Forth83 - like dialect
Message-ID<2013Feb19.093926@mips.complang.tuwien.ac.at>
In reply to#19809
"Elizabeth D. Rather" <erather@forth.com> writes:
>In this particular case, the OP is stuck with a system on which these 
>words are not provided, and asked how to define them in order to use 
>some code that he's been given. In essence, he's providing a portability 
>layer, which is not uncommon. The portability layer itself doesn't need 
>to be portable, and in fact can't be and still be useful.

In this particular case, it's easy to be portable and be just as
useful as the nonportable version:

here 0 , here swap - constant cell
: cell+ cell + ;
: cells cell * ;

BTW, this works even if the au is not a byte.

- 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 2013: http://www.euroforth.org/ef13/

[toc] | [prev] | [next] | [standalone]


#19813 — Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-19 13:21 +0100
SubjectRe: Can i (easily) implement cell+ and cells in an Forth83 - like dialect
Message-ID<slrnki6v5a.dts.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19810
In comp.lang.forth, Anton Ertl wrote:

> In this particular case, it's easy to be portable and be just as
> useful as the nonportable version:
> here 0 , here swap - constant cell
>: cell+ cell + ;
>: cells cell * ;
>
> BTW, this works even if the au is not a byte.

But what, if we've got no HERE? E.g. kForth has no HERE, neither , c, etc.

Therefore more reliable solution would be:

variable tmp
$ff tmp !
: cellSize ( -- n )  20 1 do tmp @ 8 lshift $ff + dup
  -1 = if drop i 1+ leave else tmp ! then loop ;

-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


#19814 — Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect

FromstephenXXX@mpeforth.com (Stephen Pelc)
Date2013-02-19 13:12 +0000
SubjectRe: Can i (easily) implement cell+ and cells in an Forth83 - like dialect
Message-ID<51237991.553771085@192.168.0.50>
In reply to#19813
On 19 Feb 2013 13:21:21 +0100, Zbiggy
<zbigniew2011REMOVE@gmail.REMOVE.com> wrote:

>But what, if we've got no HERE? E.g. kForth has no HERE, neither , c, etc.
>
>Therefore more reliable solution would be:
>
>variable tmp
>$ff tmp !
>: cellSize ( -- n )  20 1 do tmp @ 8 lshift $ff + dup
>  -1 = if drop i 1+ leave else tmp ! then loop ;

Why is this code formatted this way? 

Run CELLSIZE twice on a 32 bit system and display the results.
The second result is wrong.

Stephen

-- 
Stephen Pelc, stephenXXX@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads

[toc] | [prev] | [next] | [standalone]


#19815 — Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-19 14:29 +0100
SubjectRe: Can i (easily) implement cell+ and cells in an Forth83 - like dialect
Message-ID<slrnki7356.ktb.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19814
In comp.lang.forth, Stephen Pelc wrote:

>>variable tmp
>>$ff tmp !
>>: cellSize ( -- n )  20 1 do tmp @ 8 lshift $ff + dup
>>  -1 = if drop i 1+ leave else tmp ! then loop ;
>
> Why is this code formatted this way? 

To save the space. Maybe indeed it could be formatted somewhat better - but
consider the above "rough draft".

> Run CELLSIZE twice on a 32 bit system and display the results.
> The second result is wrong.

Before you run it second time, you need to "reload" transitional variable:

$ff tmp !

Do you suppose, it should be done within a word?
-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


#19816 — Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-19 14:54 +0100
SubjectRe: Can i (easily) implement cell+ and cells in an Forth83 - like dialect
Message-ID<slrnki74ju.lgk.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19815
OK - this one you'll like:

: cellSize ( -- n )
  $ff
  20 2 do
    dup 8 lshift $ff + dup -1 =
    if 2drop i leave else nip then
  loop
;

-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


#19818 — Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect

FromstephenXXX@mpeforth.com (Stephen Pelc)
Date2013-02-19 16:25 +0000
SubjectRe: Can i (easily) implement cell+ and cells in an Forth83 - like dialect
Message-ID<5123a5ea.565124042@192.168.0.50>
In reply to#19816
On 19 Feb 2013 14:54:29 +0100, Zbiggy
<zbigniew2011REMOVE@gmail.REMOVE.com> wrote:

>OK - this one you'll like:
>
>: cellSize ( -- n )
>  $ff
>  20 2 do
>    dup 8 lshift $ff + dup -1 =
>    if 2drop i leave else nip then
>  loop
>;

No, I don't like it. What is the DUP for inside the DO .. LOOP
when the item it produces is always discarded with no further
use. There are times when stack comments inside a word reveal
that the author changed his mind but did not minimise the
solution.

What is the stack effect of this word on a system whose cells are
so huge that CELLSIZE should return 20 or more?

I'm sorry to nag, but documentation is really important for
code that has to be understood by others.

Stephen


-- 
Stephen Pelc, stephenXXX@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads

[toc] | [prev] | [next] | [standalone]


#19820 — Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-19 18:29 +0100
SubjectRe: Can i (easily) implement cell+ and cells in an Forth83 - like dialect
Message-ID<slrnki7h7p.1ri.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19818
In comp.lang.forth, Stephen Pelc wrote:

>>: cellSize ( -- n )
>>  $ff
>>  20 2 do
>>    dup 8 lshift $ff + dup -1 =
>>    if 2drop i leave else nip then
>>  loop
>>;
>
> No, I don't like it. What is the DUP for inside the DO .. LOOP
> when the item it produces is always discarded with no further
> use.

init:     $ff
loop
dup:      $ff $ff
8 lshift: $ff $ff00
$ff +:    $ff $ffff
dup:      $ff $ffff $ffff
-1 = :    $ff $ffff
Still not "-1"?
nip       $ffff
loop
dup:      $ffff $ffff
... next iteration ...
"-1" at last?
2drop:    I leave

> There are times when stack comments inside a word reveal
> that the author changed his mind but did not minimise the
> solution.
>
> What is the stack effect of this word on a system whose cells are
> so huge that CELLSIZE should return 20 or more?

My assumption was, such systems do not exist. Am I wrong?

Well, in such case it'll return the false, huge value of
$FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Then if you're asking about stack effect alone - it'll be kept: a single
shall be returned (of wrong value, but still).

Well, it can be improved to count just any size of the cell - be it 20 or
200 - the question is, does there exist any need?

> I'm sorry to nag, but documentation is really important for
> code that has to be understood by others.

Then maybe that word isn't that bad?
-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


#19825 — Re: Can i (easily) implement cell+ and cells in an Forth83 - like dialect

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-19 19:16 +0100
SubjectRe: Can i (easily) implement cell+ and cells in an Forth83 - like dialect
Message-ID<slrnki7jv3.3h6.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19820
Another improvement:

: cellSize ( -- n )
  $ff
  99 2 do
    8 lshift $ff + dup -1 =
    if drop i leave then
  loop
  dup 99 > if abort" Can't calculate proper cell size" then ;

-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


#19837

FromMark Wills <forthfreak@gmail.com>
Date2013-02-20 01:07 -0800
Message-ID<76fb1365-ed26-43e7-8452-98579a49b5e0@hl5g2000vbb.googlegroups.com>
In reply to#19825
On Feb 19, 6:16 pm, Zbiggy <zbigniew2011REM...@gmail.REMOVE.com>
wrote:
> Another improvement:
>
> : cellSize ( -- n )
>   $ff
>   99 2 do
>     8 lshift $ff + dup -1 =
>     if drop i leave then
>   loop
>   dup 99 > if abort" Can't calculate proper cell size" then ;
>
> --
> It's us, the scobs.

My goodness! So much code to determine the cell size!

Why not simply: HERE 0 , HERE SWAP - .

That'll print 2 on a 16-bit system (so the cell size is 2 bytes, i.e.
16 bits) and 4 on a 32 bit system etc.

If you *really* want to count *bits* in a cell, just use a walking 1
and count shifts until you get zero:

: cell-size ( -- n)
  0 ( cell size) 1 ( walking 1)
  begin
    swap 1+ swap  2* dup 0=
  until drop ;

Works on my system (Forth 83, 16-bit) and G-Forth (32-bit) and
requires no extension word-sets. Simplicity always wins!

[toc] | [prev] | [next] | [standalone]


#19840

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-20 12:36 +0100
Message-ID<slrnki9gu3.76c.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19837
In comp.lang.forth, Mark Wills wrote:

> My goodness! So much code to determine the cell size!
>
> Why not simply: HERE 0 , HERE SWAP - .
>
> That'll print 2 on a 16-bit system (so the cell size is 2 bytes, i.e.
> 16 bits) and 4 on a 32 bit system etc.

Well, the assumption was, that there was end of the world, or end of Maya
calendar - or we are using kForth - and we've got no HERE at our disposal.
-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


#19852

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2013-02-20 20:15 +0100
Message-ID<85y5eiokyu.fsf@junk.nocrew.org>
In reply to#19840
Zbiggy wrote:
> Mark Wills wrote:
> > My goodness! So much code to determine the cell size!
> > Why not simply: HERE 0 , HERE SWAP - .
>
> we are using kForth - and we've got no HERE at our disposal.

And apparently 1 ALIGNED 0 ALIGNED - doesn't fly either.

I see the challenge here is relying on a minimum of system-provided
facilities, and assuming as little as possible about the number
representation.  Because of all those, you know, nines-complement
decimal machines out there.  (Seriously, those ClearPath mainfraimes
are not far away from that.)

My long-winded attempt is based on doing unsigned arithmetic on cell-
and char-sized values.  Unfortunately, it relies on numbers
overflowing the usual way, so it's not quite satisfactory.  Also, I
imagine there may be some Forths without unsigned arithmetic.


\ Apply xt on u1, and repeat on the result as long as it
\ keeps getting larger.  Return the next last result.
: maximise ( u1 xt -- u2 )
   >r 0 swap begin 2dup u< while
      nip dup  r@ execute
   repeat r> 2drop ;

\ Assume there is no :noname, so define these separately.
: 2*1+ ( u -- 2u+1 )   2* 1+ ;
variable temp
: c1+ ( c -- c+1 )   1+ temp c!  temp c@ ;

\ Compute the maximum unsigned value for a cell.
: ucell-max ( -- u )
   \ First, fill with binary ones.
   1 ['] 2*1+ maximise
   \ Second, make it work on grisly non-binary machines.
   ['] 1+ maximise ;

\ Compute the maximum (unsigned?) value for a cell.
: char-max ( -- u )   1 ['] c1+ maximise ;

\ Assume there is no um/mod, so simulate plain single-word division.
: u/ ( u1 u2 -- u1/u2 )   0 swap um/mod nip ;

\ Start with ucell-max, and repeatedly divide by char-max+1.
: /cell ( -- u )
   \ Doesn't work when cell-max = ucell-max, so check for that explicitly.
   char-max ucell-max = if 1 exit then
   char-max 1+ >r
   1 ucell-max begin dup r@ u> while
      r@ u/  swap 1+ swap
   repeat r> 2drop ;

[toc] | [prev] | [next] | [standalone]


#19853

FromZbiggy <zbigniew2011REMOVE@gmail.REMOVE.com>
Date2013-02-20 20:31 +0100
Message-ID<slrnkiacoa.am2.zbigniew2011REMOVE@Tichy.myhome.org>
In reply to#19852
Indeed: this must be final solution to the problem. ;)
-- 
It's us, the scobs.

[toc] | [prev] | [next] | [standalone]


Page 1 of 3  [1] 2 3  Next page →

Back to top | Article view | comp.lang.forth


csiph-web