Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:19
    @PeterWAWood banned @TimeSeriesLord
  • Aug 13 2016 03:23
    @PeterWAWood banned @Vexercizer
geekyi
@geekyi
@9214 red/red#2249
Vladimir Vasilyev
@9214
@geekyi :+1:
geekyi
@geekyi
Note that I have a different perspective that may be wrong; my understanding of bind is from in
Vladimir Vasilyev
@9214
set 'a 3 is the same as a: 3, right?
get 'a == :a
PeterWAWood
@PeterWAWood
@9214 Not quite:
red>> o: make object! [ a: 1 set 'b 2]
== make object! [
    a: 1
]
red>> o/a
== 1
red>> o/b
*** Script Error: cannot access b in path o/b
*** Where: catch
red>> b
== 2
Vladimir Vasilyev
@9214
i.e. set 'b 2 in any context is the same as system/words/b: 2?
PeterWAWood
@PeterWAWood
and
red>> b
== 2
red>> get 'b
== 2
red>> get 'a
*** Script Error: a has no value
*** Where: get
red>> get in o 'a
== 1
Vladimir Vasilyev
@9214
a: is "context dependent", while set is not?
Vladimir Vasilyev
@9214
Perhaps I've misunderstood what "binds" actually mean
PeterWAWood
@PeterWAWood
It could be that I misunderstand bind more than you :-)
Vladimir Vasilyev
@9214
Or... I think my notion of words is completely wrong. I know that it's a structure with a text representation and a pointer to the context, but... uhm... do they "exist" inside or outside of contexts?
because if a word! value is something external to a context, then I don't get why I can't change its pointer and make it refer to a different context where word will have different value (meaning)
PeterWAWood
@PeterWAWood
As I understand, a word exists in a context. One good explanation that I have read, is that each context is like a dictionary, a in one context can mean 1, in another context it can mean "This is mine.".
Vladimir Vasilyev
@9214
Yes, every context is a dictionary with word -- meaning pairs. Does that mean that actual word is that exact word part inside word -- meaning pair?
I.e. there's no external refference to it?
Vladimir Vasilyev
@9214
unnamed021312.png
which one is correct? Left one?
Vladimir Vasilyev
@9214
Sherlock Wordes and Doctor Bindson, or "Zen and The Art of Scope Maintenance: An Inquiry into Contexts" :bulb:
PeterWAWood
@PeterWAWood
I believe it is the left one based on previous explanations, to think of a context as a block of words.
Vladimir Vasilyev
@9214
block is kinda misleading though
?
unnamed01313123123123.png
Vladimir Vasilyev
@9214
For clarity
c: context [a: 2]
a: 1
Semseddin Moldibi
@endo64
That is because you are trying to print a in default context. Even simpler version:
c: context [a: 2]
bind 'a (context? in c 'a)   ; No error here. (parens aren't needed)
print a  ;there is no a in default context, hence an error occurred
print get in c 'a  ; == 2
c: context [a: 2]
b: in c 'a  ;b bounds to c *now*
get b  ; == 2

context? b ; == make object! [a: 2]
Nenad Rakocevic
@dockimbel
@9214 I haven't read the whole discussion, but bind or in will just rebind the argument value, other words (with same symbol) are unaffected. Each word is an instance of a symbol (internal symbol! type), and exists independently of all others. bind and in will return their arguments bound, you need to use that rebound value in your example:
c: context [a: 2]
new: bind 'a (context? in c 'a)
print new          ; == 2
print get in c 'a  ; == 2
BTW, you can just use :a instead of context? in c 'a (strictly equivalent).
Vladimir Vasilyev
@9214

BTW, you can just use :a instead of context? in c 'a (strictly equivalent).

I'm not sure that I've understand that part clearly :confused:

Nenad Rakocevic
@dockimbel
Oops, I meant :c.
Vladimir Vasilyev
@9214
@dockimbel :C happens! :wink:
Vladimir Vasilyev
@9214
@dockimbel so in my diagrams the left one model is more accurate or non of them are even close to the real life? I can see that any-word! word consists of symbol! part (its textual representation), object!reference part (pointer to a context) and value part of some type.
Vladimir Vasilyev
@9214
I think it's that time when everyone should say "go read some sources, kid!" :baby:
Nenad Rakocevic
@dockimbel
A word value contains a symbol, a context! reference and an index in that context (used as cache). In your last diagram, I don't see what is system block compared to system/words?
You can picture a context as just a table with two colums, the left one for symbols, the right once with value slots.
Vladimir Vasilyev
@9214
Yep, table analogy, so words can exist only in those tables? And if word is in a table, then it's bounded to that table (context)?
And in fact every any-word! in my code is more like | symbol | context! reference | index | under the hood?
Nenad Rakocevic
@dockimbel
so words can exist only in those tables No, symbols can only exist there, words can exist in any value container (blocks for example). Word = symbol + a context pointer. Symbols are context-free, words are context-bound.

And in fact every any-word! in my code is more like | symbol | context! reference | index | under the hood?

Yes. Those info are stored in the slot occupied by the word in the container (usually block! or paren!).

Vladimir Vasilyev
@9214

But why I can't change context pointer part to point to some different context, leaving older context entry as it was?

Say, a: 1 and a: 2 are entrys in different context; when I've encountered a word which points to the first a: 1, why can't I alter this word to point to the second one a: 2, leaving a: 1 as it was without any changes?

Or I can but I have missed the point?
Nenad Rakocevic
@dockimbel
@9214 You can, you just need to pass a block instead of a single word value to bind.
Vladimir Vasilyev
@9214
and block because word can exist only inside a container?
hm, in fact, after load phase script itself is a block
Nenad Rakocevic
@dockimbel
Right.
a: 0
one: context [a: 1]
b: [a]
print bind b/1 one  ; == 1
print b             ; == 0 
bind b one
print b             ; == 1
Vladimir Vasilyev
@9214
@dockimbel :point_up: 20 марта 2017 г., 06:52
why with block the bind change is kinda persistent, but without one it has zero effect, just returns a value?
Nenad Rakocevic
@dockimbel
Words are scalar values, they are "passed by value" on the evaluation stack, so if you bind a word directly, you are binding its instance on the stack, nothing else. When you pass a block, the words in the block are rebound, and if you keep a reference on that block, you can then use the rebound words.
Vladimir Vasilyev
@9214
gee
Nenad Rakocevic
@dockimbel
bind is quite dumb, it will simply process the argument you provide on the stack. As you can only get the return value back from the stack, if you pass a scalar value (word! value in this case) and do not use the returned value (rebound new word), your bind call will have produced no effect.
If you want to keep it side-effect free on the argument block, you can use copy or the /copy refinement of bind(which avoids an extra internal copy do be done).