Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 20 2019 22:59
    @dockimbel banned @SmackMacDougal
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:19
    @PeterWAWood banned @TimeSeriesLord
  • Aug 13 2016 03:23
    @PeterWAWood banned @Vexercizer
nedzadarek
@nedzadarek
@toomasv ah, I see, thank you
Nenad Rakocevic
@dockimbel

@hiiamboris

it's not a native!, how is it compiled?

native! are written in R/S, function! are written in Red, and the ones provided by the runtime (the so-called "mezzanines") are compiled, hence the difference.

@hiiamboris

moreover in all tests of compiled vs interpreted code I've tried - interpreted was faster by 20% or so ;)

That would be odd, I suspect something is flawed with your measurement method. Remember that blocks of code run by do cannot be compiled (by design, as it's the way to invoke the interpreter).

Vladimir Vasilyev
@9214
@nedzadarek you were interested in how to roll out your own event handlers, @dockimbel pointed out the direction in his message.
hiiamboris
@hiiamboris

@dockimbel cool! I didn't know we can reflect the source of compiled funcs.
And you're right, I was using loop N [do code] since the compiler won't let me compile loop N code, so that explains it all, thanks!
Just checked:

x: 0
f: does [x: x + 1]
t: [now/precise/time/utc]
t1: do t
loop 1000000 [f]
t2: do t
print t2 - t1

is really about 2x faster when compiled

hiiamboris
@hiiamboris
Imbued collecta bit with more magic :) Faster, less allocation-prone. Makes sense only for compiled code though or for small collections (n < 10) https://gist.github.com/hiiamboris/a624c3d767dfe4e4ed20f23bc96433ff
Nenad Rakocevic
@dockimbel
@hiiamboris Nice work! :+1:
hiiamboris
@hiiamboris
@dockimbel thanks :) the only drawback is that I can't meaningfully reflect it, not with the context parts...
nedzadarek
@nedzadarek
@hiiamboris I'm confused about your usage of also. Why not just body': body coll': coll' shoot :keep coll?
How do you modify an owner the series/object? noneing old's owner works fine but when I try to modify new series I get access violation at the last line (reverse/part r/a 2):
r: make object! [
    a: [1 2 3]
    b: [4 5 6]

    on-deep-change*: func [owner word target action new index part][
        print ['on-deep-change* tab word]
    ]

    on-change*: func [word old new][
        print ['on-change* tab word]

      unless all [block? :old block? :new same? head :old head :new][
              if any [series? :old object? :old][modify old 'owned none]
              if any [series? :new object? :new][modify new 'owned reduce [self word]]
      ]
    ]
]

reverse/part r/a 2
r/a: [3 2 1]       ; <-- set field to a new series which object does not 're-owns'
reverse/part r/a 2
Vladimir Vasilyev
@9214
@nedzadarek red/red#3393
nedzadarek
@nedzadarek
@9214 great, thank you
hiiamboris
@hiiamboris

@hiiamboris I'm confused about your usage of also. Why not just body': body coll': coll' shoot :keep coll?

also keeps the old value and restores it after leaving the next (...) scope, otherwise you'll break the recursive test

GiuseppeChillemi
@GiuseppeChillemi
could a function know its name ?
mynicename: func [arg1] [some code here]
Could "some code here" know its name is "mynicename"
nedzadarek
@nedzadarek
@GiuseppeChillemi as fair I remember functions are anonymous but you can create "function creator" that have function name, something like this:
named-func: func [_func-name spec body] [func spec bind body context [func-name: _func-name] ]
foo: named-func 'foo [a b] [probe a + b probe func-name]
foo 2 3
; 5
; foo
you can use set so you don't have to repeat yourself (foo: named-func 'foo):
named-func2: func [_func-name spec body] [set _func-name func spec bind body context [func-name: _func-name] ]
named-func2 'qux [a b] [probe a + b probe func-name]

qux 2 3
; 5
; qux
hiiamboris
@hiiamboris
@GiuseppeChillemi
>> myniceop: make op! func [name [set-word!] fn [function!]] [also set name :fn replace/all/deep body-of :fn 'func-name to-lit-word name]
>> mynicename: myniceop func [x y] [print [x y "from" func-name]]
>> mynicename 1 2
1 2 from mynicename
Vladimir Vasilyev
@9214
@GiuseppeChillemi functions are anonymous and can be referred by multiple words, so "name" is not the best term.
>> foo: has [dummy][print pick find body-of system/words context? 'dummy -1]
== func [/local dummy][print pick find body-of system/words context? 'dummy -1]
>> foo
foo
You can keep a word from context other than system/words to be more flexible.
githubnyn
@githubnyn
is there a way to initialize a word that is undefined ?
something like:
counter: function [][
    if not value? count [count: 0]
    count: count + 1
]
counter
Boleslav Březovský
@rebolek
there is default function in Rebol, that does exactly this:
>> ?? default
default: func [
    {Set a word to a default value if it hasn't been set yet.} 
    'word [word! set-word! lit-word!] "The word (use :var for word! values)" 
    value "The value"
][
    unless all [value? word not none? get word] [set word :value] :value
]
But your function won't work, count will be local, initialized to none and never set to 0.
Rudolf Meijer
@meijeru
The fact that "your function won't work" is merely due to the use of function instead of func, I think. If count were global, wouldn't it work? Of course it should be value? 'count as well...
Boleslav Březovský
@rebolek
@meijeru right, it's because function auto-collects set-word!s and makes them local. Another possibility is to use /extern count (and of course your fix).
nedzadarek
@nedzadarek
@githubnyn
@rebolek well, if he/she is using function then s/he can just check for none:
counter: function [] [
    if none? value [value: 0]
    probe value
]
Boleslav Březovský
@rebolek
@nedzadarek but then value would be none on each call.
nedzadarek
@nedzadarek
@rebolek before if?
Boleslav Březovský
@rebolek
@nedzadarek yes, all local words are initialized to none.
This would work:
counter: function [/extern count][
    if not value? 'count [count: 0]
    count: count + 1
]
nedzadarek
@nedzadarek
@rebolek but does it matters for him?
Boleslav Březovský
@rebolek
@nedzadarek if you are making counter, you do not expect it to return 0 on each call ;)
githubnyn
@githubnyn
thank you! @rebolek
Boleslav Březovský
@rebolek
@githubnyn You're welcome. See also https://github.com/red/red/wiki/Closures , because closure is what you want to use for such function.
nedzadarek
@nedzadarek
@rebolek ah, right
redredwine
@redredwine

call does not seem to work e.g call "notepad.exe" , using windows 10. am I calling it correctly ?
'''
red>> call explorer.exe
Script Error: call has no value Where: catch

red>> call/shell "notepad.exe"
Script Error: call has no value Where: catch

red>> help call
Word call is not defined

'''

nedzadarek
@nedzadarek
@redredwine you don't have call function (it's not even some other value). Does running call show the same error when you start up the console?
Boleslav Březovský
@rebolek
@redredwine If your prompt starts with red>> instead of >> you probably have very old version of Red (that had not call implemented yet). Please check with system/version which version do you have.
redredwine
@redredwine
red>> system/version
== "0.6.1"
nedzadarek
@nedzadarek
@redredwine the latest stable was 0.6.3
Boleslav Březovský
@rebolek
0.6.1 is more than one year old. You should upgrade.
redredwine
@redredwine
thank you, i am updating now :smile:
redredwine
@redredwine
@nedzadarek @rebolek , Thank you, it is working now with latest version :smile:
Boleslav Březovský
@rebolek
@redredwine you're welcome :)
nedzadarek
@nedzadarek
:)
Toomas Vooglaid
@toomasv
We can make tuple! from a block!. Is there a way to make block! from a tuple! as 1.1.1 => [1 1 1]?
Vladimir Vasilyev
@9214
>> load replace/all mold 1.2.3 dot space
== [1 2 3]
Toomas Vooglaid
@toomasv
@9214 OK! Seems expensive, but thanks!
Vladimir Vasilyev
@9214
>> collect [foreach byte to binary! 1.2.3 [keep byte]]
== [1 2 3]
Toomas Vooglaid
@toomasv
@9214 Thanks! Last one is quicker but uses more memory:
>> profile/count/show [[load replace/all mold 1.2.3 dot space][collect [foreach byte to binary! 1.2.3 [keep byte]]]] 10000
Count: 10000
Time         | Time (Per)   |      Memory | Code
0:00:00.116  | 0:00:00      |     9060352 | [collect [foreach byte to binary! 1.2.3 [keep byte]]]
0:00:00.703  | 0:00:00      |     4448256 | [load replace/all mold 1.2.3 dot space]
>> profile/count/show [[load replace/all mold 1.2.3 dot space][collect [foreach byte to binary! 1.2.3 [keep byte]]]] 10000
Count: 10000
Time         | Time (Per)   |      Memory | Code
0:00:00.114  | 0:00:00      |     9060352 | [collect [foreach byte to binary! 1.2.3 [keep byte]]]
0:00:00.698  | 0:00:00      |     2347008 | [load replace/all mold 1.2.3 dot space]
>> profile/count/show [[load replace/all mold 1.2.3 dot space][collect [foreach byte to binary! 1.2.3 [keep byte]]]] 10000
Count: 10000
Time         | Time (Per)   |      Memory | Code
0:00:00.113  | 0:00:00      |     9060352 | [collect [foreach byte to binary! 1.2.3 [keep byte]]]
0:00:00.725  | 0:00:00      |     2347008 | [load replace/all mold 1.2.3 dot space]
Vladimir Vasilyev
@9214
@toomasv load currently is implemented as mezzanine and is pretty slow, can you try to block! instead? I'm not sure if it will make any difference though.
Toomas Vooglaid
@toomasv
Strange. to-block is even worse memory-wise (to block! is same):
>> profile/count/show [[to-block replace/all mold 1.2.3 dot space][collect [foreach byte to binary! 1.2.3 [keep byte]]]] 10000
Count: 10000
Time         | Time (Per)   |      Memory | Code
0:00:00.112  | 0:00:00      |     9060352 | [collect [foreach byte to binary! 1.2.3 [keep byte]]]
0:00:00.717  | 0:00:00      |    31764480 | [to-block replace/all mold 1.2.3 dot space]
>> profile/count/show [[to-block replace/all mold 1.2.3 dot space][collect [foreach byte to binary! 1.2.3 [keep byte]]]] 10000
Count: 10000
Time         | Time (Per)   |      Memory | Code
0:00:00.111  | 0:00:00      |     9060352 | [collect [foreach byte to binary! 1.2.3 [keep byte]]]
0:00:00.7    | 0:00:00      |    33865728 | [to-block replace/all mold 1.2.3 dot space]
>> profile/count/show [[to-block replace/all mold 1.2.3 dot space][collect [foreach byte to binary! 1.2.3 [keep byte]]]] 10000
Count: 10000
Time         | Time (Per)   |      Memory | Code
0:00:00.112  | 0:00:00      |     9060352 | [collect [foreach byte to binary! 1.2.3 [keep byte]]]
0:00:00.7    | 0:00:00      |    33865728 | [to-block replace/all mold 1.2.3 dot space]