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
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
Max
@moliad
@GiuseppeChillemi I know, but just clarifying
Vladimir Vasilyev
@9214
@rebolek and select.
Boleslav Březovský
@rebolek
@9214 right. And in and other esoteric stuff ;)
GiuseppeChillemi
@GiuseppeChillemi
@moliad I know you know but was me which didn't know.
:)
Boleslav Březovský
@rebolek
>> a: context [b: 2 c: 5]
== make object! [
    b: 2
    c: 5
]
>> get in a 'b
== 2
>> do bind [b] a
== 2
>> a/b
== 2
>> select a 'b
== 2
>> do reduce [first words-of a]
== 2
GiuseppeChillemi
@GiuseppeChillemi

So, lets return on my first struggle

y: [b c d]
probe context? y/1

I supposed context? y/1 returned an empty context but instead it is the global one.

Boleslav Březovský
@rebolek
it can't return empty context, word cannot be member of empty context
Max
@moliad
@GiuseppeChillemi yes, cause you created the [b c d] block on the console, so the created words where global at that moment
GiuseppeChillemi
@GiuseppeChillemi
So, which is there rule here: words on a block have the global context when not created inside a function/object ?
Max
@moliad
short answer yes
long answer, it depends.
GiuseppeChillemi
@GiuseppeChillemi
Noooo, I can't live with "depends" !
Max
@moliad
it will use the "current" context. which is the global one by default (at root of app, on the console, etc.)
GiuseppeChillemi
@GiuseppeChillemi

When I have written:

words on a block have the global context when not created inside a function/object

I meant that when created inside them they get their context which is the current one.

Max
@moliad
it is possible that if you read code and load it within some other code, it will bind some of it there, and bind some of its words to the global context, if the words are new
GiuseppeChillemi
@GiuseppeChillemi
Not as easy as it seems....
Max
@moliad
dialects have a tendency to have a bind inside somewhere... ex: foreach, binds to a new hidden context, all the words in the 'words argument (the first)
the rest stay as they where.
function dialect binds all set-words to a new inner context.
GiuseppeChillemi
@GiuseppeChillemi

If I have a:

        foreach [value] block-with-specific-context
        [
...
        ]

How do I manintain the context of block-with-specific-context

Max
@moliad
what do you mean by "maintain"?
here 'value is local to the loop.
Boleslav Březovský
@rebolek
@moliad not in Red:
>> x
*** Script Error: x has no value
*** Where: catch
*** Stack:  

>> foreach x [1 2 3][]
>> x
== 3
Max
@moliad
all the rest of the content in 'block-with-specific-context stays bound to the same value
GiuseppeChillemi
@GiuseppeChillemi
but value get its value for a block and block words could a context you may want to have on value too
Max
@moliad

@rebolek

not in Red:

>> foreach x [1 2 3][]
>> x
== 3

what! is this by design or is it an unresolved side-effect?

Vladimir Vasilyev
@9214
@moliad unresolved design.
Iterators' words remain in global context.
Max
@moliad
was it a debate or just not addressed?
Boleslav Březovský
@rebolek
it's faster this way right now
but it's not final design
GiuseppeChillemi
@GiuseppeChillemi
@9214 I have already read about it on a discussion on GITTER time ago...
Vladimir Vasilyev
@9214
@moliad there's no "current" context though. All words that pass the lexer defaults to global context. Then, at run-time, words acquire new contexts as evaluation of everything related to function! and any-object! builds up.
Max
@moliad
I often hear the argument about foreach being "slow" in R2... well its the fastest iterator in the language.
I did a 10 hour study on all iterators. the single binding pass isn't a bit deal... unless you use foreach in a huge block
Boleslav Březovský
@rebolek
I believe there are implementation differences between R2 and Red that may have something to do with that decision.
Max
@moliad
hum... looks I'll have to redo a few tests to discover some of the more complex binding issues that crop up with self-modifying code and run-time compilation.
GiuseppeChillemi
@GiuseppeChillemi

I am working on having a single function with different arguments length depending on the "method" of the function.

Example:

alter-db 'add-rows ["db-name" "table-name" [column1 column2 column3]]
alter-db 'remove-table ["db-name" "table-name"]

The same alter-db has different number of arguments depending on the method used

Inside alter-db I have a block which specifies the words of the arguments

Alter-DB is defined as

Alter-DB: function [
    method
    arg-block
]
[
   fnc-args: [
      'add [db table rows]
      'remove-table [db table]
   ]
]

I want to associate each word in a method i.e. 'ADD has -db table rows-

To the corresponding word in arg-block

Note: I know I could use objects but I wish to build from this the learn some red topics.
Actually I am stuck into building a global function which is used to associate method words to arguments when called from any functions which is built this way