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
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.
Map has one, object doesn't.
GiuseppeChillemi
@GiuseppeChillemi
Yes @moliad but first/second/third or obj/1 ../2 /3 is a method you could apply to object content. In fact in rebol you could use it on the third element of an object. (i.e.: probe first third obj)
Vladimir Vasilyev
@9214
@GiuseppeChillemi because third obj in Rebol is equivalent to body-of obj in Red.
GiuseppeChillemi
@GiuseppeChillemi

So, having

z: make object! [b: 0 c: 1 d: 2]

a first z returning b could be a valid access method.

@9214 Yes, now I have understood
In RED a more explicit and verbose method is used
Max
@moliad
@GiuseppeChillemi in fact /1 /2 /3 doesn't work in Rebol :smirk:
>> a: context [a: 8]
>> a/1
** Script Error: Invalid path value: 1
** Near: a/1
GiuseppeChillemi
@GiuseppeChillemi
Just had to learn the proper way to get object contend

@moliad

Yes, we have another way

>> z: make object! [b: 0 c: 1 d: 2]
>> probe pick third z 1
b:
== b:
Boleslav Březovský
@rebolek
words-of, values-of, body-of and of course object/key