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
@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]
Vladimir Vasilyev
@9214
@toomasv
a: [
    result: make block! size: length? bytes: to binary! 1.2.3
    loop size [append result take bytes]
]

b: [collect [foreach byte to binary! 1.2.3 [keep byte]]]

profile/show/count [a b] 10'000
Count: 10000
Time         | Time (Per)   | Memory      | Code
0:00:00.035  | 0:00:00      | 2510848     | a
0:00:00.125  | 0:00:00      | 9060352     | b
hiiamboris
@hiiamboris
t: 1.2.3 c: [also r: clear [] repeat i length? t [append r t/:i]]
;)
Vladimir Vasilyev
@9214
And so /help derails into masculine competition. Nice job everyone! :tada:
hiiamboris
@hiiamboris
reducers' ring :D
Toomas Vooglaid
@toomasv
@9214 Thanks! That's good.
@hiiamboris I tried that. It is a bit slower than collect and uses a bit less memory. Overall, more-or less the same. Thanks!
Toomas Vooglaid
@toomasv
Ah! Sorry! It's not quite the same as I tried.
hiiamboris
@hiiamboris
@9214 I see it rather differently: a bunch of fanatics offer tributes to the God of Reduction :)
Vladimir Vasilyev
@9214
Your reaction's kind of odd for a kid who loves to nod.