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
@giesse I see, thank you for the information.
Gabriele Santilli
@giesse
@pekr, unpopular with this crowd at least :)
GiuseppeChillemi
@GiuseppeChillemi

What should I expect using context?

If I use it on an object word I get ?function?. This is not so meningful to me.
I ask it beacuse I wish to find which functions returns what: I wish to compare if the context of words inside block is the same of the result when using extract, or contexts of words passed between funtions, or if words setted into a foreach loop maintain the context of the foreach block argument.

hiiamboris
@hiiamboris
you're probably using it not on object's word but on it's associated value
GiuseppeChillemi
@GiuseppeChillemi
AA: 1
Context? 'AA
( pardon, I am in mobile )
hiiamboris
@hiiamboris
>> o: object [w: 123  probe context? 'w]  ()
make object! [
    w: 123
]
no function as you can see
can't tell you more without seein the code
Toomas Vooglaid
@toomasv
@GiuseppeChillemi Or, if you have bound words somewhere else, e.g.:
a: [b]
o: object [b: 2]
bind a o
context? a/1
;== make object! [
;    b: 2
;]
GiuseppeChillemi
@GiuseppeChillemi
@toomasv Yesterday it was too late. I was using PRINT instead of PROBE to get the context.
Boleslav Březovský
@rebolek
Careful with that, print evaluates
GiuseppeChillemi
@GiuseppeChillemi
@toomasv I still not undestand how to get the context of a word inside a block.
@rebolek Yes, I have discovered it with long consolle output !
Toomas Vooglaid
@toomasv
@GiuseppeChillemi If you have bound words in the block, you can ask context? of these words, as in above example.
Also:
>> a: [context? 'b]
== [context? 'b]
>> o: object [b: 2]
== make object! [
    b: 2
]
>> bind a o
== [context? 'b]
>> do a
== make object! [
    b: 2
]
Greg T
@gltewalt
If you’re wondering how to get the name that a value is set to... values are anonymous.
nedzadarek
@nedzadarek
@GiuseppeChillemi to add to @toomasv answer:
you just need to extract a word!. As Toomas noted, you can use /n syntax (arr: [a b c] arr/3; c) or using pick (pick [a b c] 3). You can evenfindit (first find [a b c] 'a`). As fair I remember, it's like any other way to extract values.
@toomasv has binding changed? I remember saving bindings (e.g. arr: [a b c] arr: bind arr context [a: 1 b: 2 c: 3]). I don't think it's necessary now.
Toomas Vooglaid
@toomasv
@nedzadarek No need to "save". Bindings are changed in-place. But you can bind a (deep) copy with bind/copy.
nedzadarek
@nedzadarek
@toomasv I see.
@toomasv @GiuseppeChillemi As fair I know bind binds any-word!:
>> arr: [a a: 'a :a] 
== [a a: 'a :a]
>> reduce to-word probe first (bind arr context [a: 42])
a
== 42
>> reduce to-word probe second (bind arr context [a: 42])
a:
== 42
>> reduce to-word probe third (bind arr context [a: 42])
'a
== 42
>> reduce to-word probe fourth (bind arr context [a: 42])
:a
== 42
GiuseppeChillemi
@GiuseppeChillemi
Here:
y: [b c d]
probe context? y/1
I expected a result from context? but basically I was wrong. I supposed B has some context
Boleslav Březovský
@rebolek
But there is result.
Also,
>> equal? system/words context? y/1
== true
nedzadarek
@nedzadarek
@GiuseppeChillemi don't probe it - main context is huge to print
GiuseppeChillemi
@GiuseppeChillemi
@rebolek , yes there is a result.

Also I expected a result from:

z: make object! [b: 0 c: 1 d: 2]
probe context? z/1

But I get an error

*** Script Error: cannot access 1 in path z/1
*** Where: context?
*** Stack: probe 
>>
Boleslav Březovský
@rebolek
z is object, there's no z/1
this has nothing to do with context?
GiuseppeChillemi
@GiuseppeChillemi

@gltewalt

If you’re wondering how to get the name that a value is set to... values are anonymous.

This is now clear to me.

@rebolek I expected z/1 returning the first word in the object and returning the object Z itself as result of context?
nedzadarek
@nedzadarek
@GiuseppeChillemi I guess you have used the Rebol to have such expectations:
z: object [a: 1 b: 2]
first z
; == [self a b]
second z
;== [make object! [
;        a: 1
;        b: 2
;    ] 1 2]
Boleslav Březovský
@rebolek
@nedzadarek certainly not, first z does return words-of, not first word.
@GiuseppeChillemi Ah, you wanted this:
>> z: make object! [b: 0 c: 1 d: 2]
== make object! [
    b: 0
    c: 1
    d: 2
]
>> w: words-of z
== [b c d]
>> w/1
== b
>> context? w/1
== make object! [
    b: 0
    c: 1
    d: 2
]
nedzadarek
@nedzadarek

@rebolek

@nedzadarek certainly not, first z does return words-of, not first word.

I mean that only the Rebol allows you to use integer indexes (well, first and second) to retrieve words & values respectively. The Red is more descriptive (-of functions).

Boleslav Březovský
@rebolek
@nedzadarek right, it does, however @GiuseppeChillemi writes: I expected z/1 returning the first word in the object..., so this has nothing to do with first and second (and third also, IIRC) functionality in Rebol.
nedzadarek
@nedzadarek
@rebolek Maybe he saw obj: make object! [...] ... second obj. So, he thought "I can use integer indexes on objects".
After some time he tried it on the Red (not remembering exact details), expecting above.
Boleslav Březovský
@rebolek
:)
GiuseppeChillemi
@GiuseppeChillemi
Yes, when I see a block I think automatically I can get its elements via integers
Boleslav Březovský
@rebolek
And you of course can. However, object is not a block.
GiuseppeChillemi
@GiuseppeChillemi
I always think that there is an uniform access method in RED or REBOL so I apply the knoledge of blocks in object as when I probe them they actually seem an block with a "make object!" just before.
It's common to abstract a rule and apply it on similar things.
But REDBOL has many so many changes that this method can't be always applied.
Boleslav Březovský
@rebolek
There's no literal form of object which may be confusing for some people. But have a look at map!, it has its literal form - #( ... ), so you can't confuse it with block, can you? And objects are more like maps in this regards.
GiuseppeChillemi
@GiuseppeChillemi
However I think that having uniform access methods make easier to handle the language.
I don't know what you mean for "literal form" but I can imagine
Boleslav Březovský
@rebolek
There is uniform access method in form of path: x/y/z, but that does not mean that you can use integers everywhere, only where appropriate.
Max
@moliad
objects have little to do with blocks. objects are not series.
Boleslav Březovský
@rebolek
Literal form is datatype specific syntax.