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
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
Vladimir Vasilyev
@9214
set select fnc-args method arg-block
GiuseppeChillemi
@GiuseppeChillemi
@9214 block to block mapping ?
Vladimir Vasilyev
@9214
A crude substitute for what should be an object with dedicated methods.
nedzadarek
@nedzadarek
@moliad so foreach's word is binded to a local context (e.g. function) but set doesn't bind. I wonder why setdoesn't behave like foreach.
GiuseppeChillemi
@GiuseppeChillemi

@9214
What if I use a global function like:

set-args: function 
[my-args arg-words] 
[
    set select my-args method arg-words
    .....
]

and call it from the inside of alter-db

using

set-args fnc-args arg-block

After selecting them ?

How do I bind words to the calling function ?

Max
@moliad
in Red, it seems like foreach doesn't bind (confirmed).
set doesn't deal with binding... that's the magic, it just uses the word's binding (remember that all any-word! types store their binding internally)
Vladimir Vasilyev
@9214
@GiuseppeChillemi they are already bound to calling function if they were /local to it.
GiuseppeChillemi
@GiuseppeChillemi
@9214 I'll experiment tomorrow. Now I feel the need to sleep. Another evening with the pro's makes me so tired....
nedzadarek
@nedzadarek

@moliad

in Red, it seems like foreach doesn't bind (confirmed).

>> f: function [] [foreach w [1 2 3] [print w]]
== func [/local w][foreach w [1 2 3] [print w]]
>> f
1
2
3

It could be the function that does this but I mean the results (word is local)

GiuseppeChillemi
@GiuseppeChillemi

A very last question:

>> aa: 1
== 1
>> zz: [aa bb cc]
== [aa bb cc]
>> same? 'aa zz/1
== true

I have always thought that

aa
in the main code
and
aa in [aa bb cc]
Are totally different

But the implications of being same? has implications still to understand in my mind.
No, thats not a question. Its simple a new topic to work on.
Vladimir Vasilyev
@9214
[aa bb cc] is the "main code".
GiuseppeChillemi
@GiuseppeChillemi
@9214
Thanks, I'll spend my night having nightmares !
Vladimir Vasilyev
@9214
Your two aa's are idential because they have the same spelling and are bound to the same context.
GiuseppeChillemi
@GiuseppeChillemi
@9214
I'll have a lot of problems in my REM phase.
Vladimir Vasilyev
@9214
Very funny.
GiuseppeChillemi
@GiuseppeChillemi
@9214 However thanks, you are giving me topics to think on. See you tomorrow !
Gregg Irwin
@greggirwin

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)

The key distinction here is intended use. Maps and objects are based on unorderd key-value slots, blocks are based on ordered slots. This is an important distinction. While this is not laid out in a design spec, it tells you that it is safe to use blocks based on their order, but that it's not safe to do so with maps and objects. That is, a block will always return values in the same order, but a different implementation of map/object might change the internal order of things, and return them in a different order in response to words-of/values-of.

GiuseppeChillemi
@GiuseppeChillemi
Blocks were so innocents for me.. Now a have to build a whole new mind map
Gregg Irwin
@greggirwin

On foreach, as @nedzadarek showed, it is special, along with remove-each and repeat, If you use function rather than func. _function/collect-words and _function/collect-deep are responsible for that special handling.

This is a workaround for now, but a fairly effective one in most cases. Not perfect, but better than nothing.

_function is the context name in the function! datatype code.
Max
@moliad
@greggirwin not sure I follow you. foreach currently doesn't "localize" words in Red
or does it on set-word! within?
hiiamboris
@hiiamboris
@moliad function constructor does that
Max
@moliad
yes... but @greggirwin refers to foreach in his post. (btw I just checked and foreach doesn't localize set-word! values)
GiuseppeChillemi
@GiuseppeChillemi
@9214 while coding I had the needing to reuse object method arguments without rewriting them for each method. The final version of this 'crude object' Will be a function with many methods that share a couple of arguments sets.
hiiamboris
@hiiamboris
@moliad function constructor does that for foreach and some others ☻
Max
@moliad
(I just tested, and foreach does no localization of any word.)
the fact that its within another context (within a function or an object), isn't a property of foreach
hiiamboris
@hiiamboris
yes
Max
@moliad
sorry for being anal... I don't want people to get mixed up :smirk: ... its already easy to mess up binding understanding
gtg, will be back tomorrow, ciao!