Jump to content

Recommended Posts

For the code

    flags= make static binary! sizepl
    flags-ptr: flags

    for-all flags-ptr 
    [ 
;        change flags-ptr 1 ; "change" has no value
        poke flags-ptr 0 1
    ]

I receive

** Script error: "for-all" does not work on types combination:
Parameter types:
1: static-binary! [flags-ptr
    [
     ...
2: expressions list block! [
    [
        poke f...
At: [
    for-all flags-ptr
    [
        poke flags-ptr 0 1
...
In: [
    count: 0
    i: 0
    flags= make static binary! si...
Near: [
    while iter <= 10
    [
        count: 0
        i: ...

 

  • Thanks 1
Link to comment
Share on other sites

4 minutes ago, Kaj de Vos said:

Thanks, made another fix.

now the compilations is getting error later on pick:

** Script error: cannot use pick on none! value
** Where: has-arguments any do if case either compile-expression foreach unless either compile-expression foreach unless either compile-expression foreach emit-C-program either do either either either -apply-
** Near: has-arguments third arguments-of code all [
    constant: se...

the code:

natural! [count i]

while iter <= 10 
[
    count: 0
    i: 0
    flags= make static binary! sizepl
    flags-ptr: flags

    for-all flags-ptr 
    [ 
;        change flags-ptr 1 ; "change" has no value
        poke flags-ptr 0 1
    ]

    i: 0
    while i <= size
    [
        p: pick flags i
        if p = 1 
        [
            prime: ( i * 2 ) + 3
            k: prime + i 
            while k <= size
            [
                poke flags k 0
                k: k + prime
            ]
            count: count + 1
        ]
        i: i + 1
    ]
    iter: iter + 1
]


 

  • Thanks 1
Link to comment
Share on other sites

24 minutes ago, Kaj de Vos said:

Should be fixed now.

Compiling file sieve.meta

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1248  100   344  100   904    246    647  0:00:01  0:00:01 --:--:--   895

** Script error: insert does not allow none! for its series argument
** Where: either do if case either compile-expression foreach unless either compile-expression foreach unless either compile-expression foreach emit-C-program either do either either either -apply-
** Near: either any [
    not has-arguments second arguments-of code

  • Thanks 1
Link to comment
Share on other sites

16 hours ago, ilmenit said:

if you see there any places to improve the code, would be great to get your hints here.

Here goes.

16 hours ago, ilmenit said:

iter: 1

iter is inferred as integer!. You could optimise it like this:

byte! iter

It wouldn't matter much for speed here, but it would make the executable a bit smaller. But you don't need iter, because you can just do:

repeat 10 [

 

16 hours ago, ilmenit said:

unsafe!!! constant reference volatile byte! [     ; OS     RTCLOK2= ~13     RTCLOK3= ~14 ]

Address assignments increment automatically, so you can write:

unsafe!!! constant reference volatile byte! [
    ; OS
    RTCLOK2= ~13
    RTCLOK3
]

 

16 hours ago, ilmenit said:

RTCLOK2: 0 RTCLOK3: 0

RTCLOK3: RTCLOK2: 0

is shorter, in source and possibly also in binary code, depending on the back-end.

 

The first

16 hours ago, ilmenit said:

i: 0

is superfluous.

 

You can fill the array with

change/repeat flags 1 sizepl

 

The second

16 hours ago, ilmenit said:

i: 0

is off by one.

 

16 hours ago, ilmenit said:

while i <= size

for starts with one by default to match series indexes. Just do

for i size [

 

16 hours ago, ilmenit said:

p: pick flags i         if p = 1

p is inferred as integer!. This is inefficient. But you don't need p:

if (pick flags i) = 1

Experienced REBOL programmers like to simplify this:

if 1 = pick flags i [

Unlike REBOL, Meta supports the C style of treating 0 as an option value, so you can just do

if pick flags i [

 

16 hours ago, ilmenit said:

( i * 2 ) + 3

This can be optimised as

i << 1 + 3

But watch out that you need to adjust for 1-indexing.

Whether this produces better code depends on the back-end.

 

16 hours ago, ilmenit said:

count: count + 1

The remaining increment can be optimised as

increment count

 

  • Thanks 1
Link to comment
Share on other sites

17 minutes ago, Kaj de Vos said:

You can fill the array with


change/repeat flags 1 sizepl

    flags= make static binary! sizepl    
    change/repeat flags 1 sizepl  

 


** Script error: "change/repeat" does not work on types combination:
Parameter types:
1: static-binary! [flags 1 sizepl
    fo...
2: byte! [1 sizepl
    for i si...
3: natural16! [sizepl
    for i size...
At: [
    change/repeat flags 1 sizepl
    for i size
    [
 ...
In: [
    count: 0
    flags= make static binary! sizepl
    ...
Near: [
    repeat 10
    [
        count: 0
        flags= mak...

 

Quote

Your indexing is off by one. Indexing in REBOL and Meta is 1-based. In the future, this will produce a bounds error.

It's a topic for a flame war, but are you sure it's good idea to follow 1-based indexing of Rebol? You are dropping compatbility with Rebol anyway.

Many algorithms working on arrays (esp. of more than 1 dimension) are much simpler with 0-based indexing (and if you are targeting 8bit machines then you will work with them primarily). Modern languages that primarily 1-based have ability to set arbitrary indices (Julia, Pascal). Also nowadays "a must" are bindings to different libraries... and most of them are done in 0-based languages.

Quote

 

This can be optimised as



i << 1 + 3

But watch out that you need to adjust for 1-indexing.

 

This one of examples why 1-based indexing is not that great idea.

 

Link to comment
Share on other sites

1 hour ago, ilmenit said:

Compiling file sieve.meta

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1248  100   344  100   904    246    647  0:00:01  0:00:01 --:--:--   895

** Script error: insert does not allow none! for its series argument
** Where: either do if case either compile-expression foreach unless either compile-expression foreach unless either compile-expression foreach emit-C-program either do either either either -apply-
** Near: either any [
    not has-arguments second arguments-of code

Made a partial fix.

 

Out of time for today.

Link to comment
Share on other sites

12 minutes ago, ilmenit said:

It's a topic for a flame war, but are you sure it's good idea to follow 1-based indexing of Rebol?

Yes, and yes, it's more human-friendly. We have plenty of unfriendly languages already.

13 minutes ago, ilmenit said:

Also nowadays "a must" are bindings to different libraries... and most of them are done in 0-based languages.

Doesn't matter, you just compensate.

14 minutes ago, ilmenit said:

This one of examples why 1-based indexing is not that great idea.

It's still math. Surely, a mathematically inclined person can easily adapt.

Link to comment
Share on other sites

23 minutes ago, Kaj de Vos said:

That's a comparison, you should not have a " = " in there.

No.

 

unsafe!!! constant reference volatile byte! [
  RTCLOK=  ~14
  P0PF=    ~2C0
  HPOSM0=  ~D004
  GRAFM=   ~D011
  COLPM0
  COLPM1
  COLBK=   ~D01A
  RANDOM=  ~D20A
  WSYNC=   ~D40A
  VCOUNT
]

this don't work, last assignment must have explicit address.

  • Thanks 1
Link to comment
Share on other sites

46 minutes ago, Kaj de Vos said:
1 hour ago, ilmenit said:

Also nowadays "a must" are bindings to different libraries... and most of them are done in 0-based languages.

Doesn't matter, you just compensate.

Why not give the programmer the option to set the base like some languages already do

Best of both worlds

 

Atari ST BASIC uses OPTION BASE  which can be 0 or 1

Edited by TGB1718
Update
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...