by

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
Vladimir Vasilyev
@9214

@nedzadarek so, now you disagree with technical details and objective facts? Whatever.
https://www.youtube.com/watch?v=b47wP_yMCf4

Words and variables are different both in their implementations and at conceptual level. Words can serve as variables in a very, very special sense (to the degree that you can't just call them "variables" without wasting your breath on 1-2 hour explanation of difference between the two) , but they are not variables, neither technically (they differ in implementations) nor conceptually (we use "words" and "bindings" for a reason!).

Vladimir Vasilyev
@9214
@redredwine or maybe your rule will keep something that is not a timestamp, can't remember the details of log format now.
hiiamboris
@hiiamboris
@9214 I've found your explanation of words vs variables enlightening.. esp. that graph :+1:
Vladimir Vasilyev
@9214
@hiiamboris you're welcome! I hope I didn't spread any BS or misinformation here. :)
hiiamboris
@hiiamboris
@9214 can a word have absolutely no context? not even refer to system/words?
as an illustration:
>> system/words = context? first [pewpew]
== true
Boleslav Březovský
@rebolek
it can in Rebol3, not sure about Red
Vladimir Vasilyev
@9214
@hiiamboris it cannot in Red, at least for now, but that might change with modules.
All any-word!s are bound to system/words ("global context") on load phase and are unset (there's no value associated with them). Then, at run-time, words are rebound by functions to other contexts, change their values in the available conexts, or remain untouched.
Basically, this is how Redbol fakes lexical scoping - nesting round of redbindings create an illusions of scopes, while in fact it's just a bunch of words, each and every referring to its context.
Vladimir Vasilyev
@9214
@hiiamboris a common case is when a word has a context, but it is not available anymore.
hiiamboris
@hiiamboris
but only function contexts can become unavailable, right?
Vladimir Vasilyev
@9214
@hiiamboris correct, because once function leaves the call stack its context disappears too.
>> foo: has [x][x: 42 'x]
== func [/local x][x: 42 'x]
>> foo
== x
>> get foo
*** Script Error: context for x is not available
*** Where: get
*** Stack:
Vladimir Vasilyev
@9214
"redbindings", huh, nice typo.
Toomas Vooglaid
@toomasv
Just teasing
>> x: 'whatever rebind :foo system/words get foo
== 42
>> rebind :foo :foo get foo
*** Script Error: context for x is not available
*** Where: get
*** Stack:
Boleslav Březovský
@rebolek
Ha, so it's possible!
Toomas Vooglaid
@toomasv
Ah, yes
>> x
== 42
Vladimir Vasilyev
@9214
Shouldn't foo rebind its local words on each function call?
Toomas Vooglaid
@toomasv

Seems not

>> x: 'whatever rebind :foo system/words get foo
== 42
>> foo
== x
>> get foo
== 42

It binds on creation only

Vladimir Vasilyev
@9214
R2 is even weirder in this regard:
>> foo: has [x][x: 42 'x]
>> get foo
== 42
>> x
** Script Error: x has no value
** Where: halt-view
** Near: x
Uh-huh...
>> probe bind? foo
make object! [
    x: 42
]
@toomasv I'm not sure whenever it's by design or not :confused:
Probably by design, rebinding on each call induces too much overhead.
DideC
@DideC
What I found funny is that I'm using Rebol / red since nearly 20 years. I understand the "basic" of binding. But I nether have to torture things as you do in my programs :smile:. I have sometime to rebind things, but it does not go far.
lepinekong
@lepinekong_twitter
@9214 when you are underaverage you have to use crutches :smile:
Read preprocessor doc https://doc.red-lang.org/en/preprocessor.html but seems I failed to understand how it works :
>> #do [simulate-external?: true]
== [simulate-external?: true]
>> #either simulate-external? [true][false]
*** Script Error: simulate-external? has no value
*** Where: catch
*** Stack:
hiiamboris
@hiiamboris
you forgot expand
Vladimir Vasilyev
@9214
@lepinekong_twitter
>> expand-directives [#do [foo: yes]]
== []
>> expand [print #either foo ["yes"]["no"]]
[print "yes"]
== [print "yes"]
lepinekong
@lepinekong_twitter
@nedzadarek in some special context print doesn't print, had to add do-events/no-wait:
.Call-Powershell: function[.powershell-command /out /silent][

    powershell-command: to-powershell .powershell-command

    either not out [
        call powershell-command 
    ][
        output: copy ""
        do-events/no-wait
        print powershell-command
        do-events/no-wait
        call/output powershell-command output

        unless silent [
            print output
        ]
        return output
    ]

]
@9214 thanks will try I'm still not very well waken up :smile:
Vladimir Vasilyev
@9214
@lepinekong_twitter my bad, foo here is from previous sessions. It seems that you can't populate execution context in console.
Toomas Vooglaid
@toomasv
@9214
>> foo: has [x][x: 42 'x]
== func [/local x][x: 42 'x]
>> context? foo
== func [/local x][x: 42 'x]
>> x: 'whatever rebind :foo system/words context? foo
== make object! [
    datatype!: datatype!
    unset!: unset!
    none!: none!
    logic!: logic!
    block!: block!
    paren!: paren!
    string!: string!
    file!: file!
    url!: ur
>> rebind :foo :foo context? foo
== func [/local x][x: 42 'x]
Vladimir Vasilyev
@9214
@toomasv yes, already tinkered with that myself.
Toomas Vooglaid
@toomasv
:+1:
hiiamboris
@hiiamboris
and me too :) are we all crazy?
Vladimir Vasilyev
@9214
@lepinekong_twitter
>> expand [#do [abc: 123] print #either abc ["yes"]["no"]]
[print "yes"]
== [print "yes"]
>> type? :abc
== unset!
BeardPower
@BeardPower
@hiiamboris No, we are just searching for the final frontier :smile:
Toomas Vooglaid
@toomasv
Still playing:
>> foo: has [x][x: 42 'x] get foo
*** Script Error: context for x is not available
*** Where: get
*** Stack:  

>> insert back tail body-of :foo 'get foo
== 42
>> remove skip tail body-of :foo -2 get foo
*** Script Error: context for x is not available
*** Where: get
*** Stack:
Vladimir Vasilyev
@9214
@toomasv nice!
Toomas Vooglaid
@toomasv
:)
DideC
@DideC

and me too :) are we all crazy?

I think so, but it's just my opinion ;-)

nedzadarek
@nedzadarek
@lepinekong_twitter hmm... I guess I had to run whole stuff to understand why print doesn't print. Well, thank you nevertheless.
@toomasv try this (very crude example!):
my-contexts: copy []
append my-contexts context [a: 42]
; == [make object! [
;     a: 42
; ]]
my-contexts/1
; == make object! [
;    a: 42
;]
f: func [v] bind [a: a * v 'a] my-contexts/1
; == func [v][a: a * v 'a]
get f 2
; == 84
get f 2
; == 168
Vladimir Vasilyev
@9214
Which is the same as
>> foo: func [y] bind [x: x * y] context [x: 42]
== func [y][x: x * y]
>> foo 2
== 84
>> foo 2
== 168
Toomas Vooglaid
@toomasv
Messing it up:
>> my-contexts: copy []
== []
>> append my-contexts context [a: 42]
== [make object! [
    a: 42
]]
>> f: func [v] bind [a: a * v 'a] my-contexts/1
== func [v][a: a * v 'a]
>> get f 2
== 84
>> get f 2
== 168
>> append my-contexts context [v: 1 a: 2]
== [make object! [
    a: 168
] make object! [
    v: 1
    a: 2
]]
>> rebind :f my-contexts/2
== [a: a * v 'a]
>> get f 2
== 2
>> get f 2
== 2
And righting again..
>> rebind/all :f [my-contexts/1 :f]
== [a: a * v 'a]
>> get f 2
== 336
>> get f 2
== 672
Vladimir Vasilyev
@9214
Hot-swapping :hotsprings:
nedzadarek
@nedzadarek
@9214 I guess... but there is no (yet) garbage collector so we are leaking the contexts, right?
Vladimir Vasilyev
@9214
"leaking the contexts"?
nedzadarek
@nedzadarek
I mean when you unset 'foo the context of his body is still there.
Vladimir Vasilyev
@9214
GC can't touch anonymous context as long as it's referred by at least one word.