by

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 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!
GiuseppeChillemi
@GiuseppeChillemi
@moliad can't - bind sleep me -
Words are floating in my mind in every RED context
Gregg Irwin
@greggirwin
@moliad, correct. Foreach doesn't collect and bind words currently. Function does that.
o: object [
    f: func [][foreach w [1 2 3][]]
    ff: function [][foreach ww [11 22 33][]]
    f
    ff
    attempt [print w]
    attempt [print ww]
]

print mold words-of o
w
nedzadarek
@nedzadarek
@moliad I (we) mean this:
  • function makes all set-word! local (adds it to the /local refinement f: function [][a: 1] ; == func [/local a][a: 1])
  • as you know, setting words without using set-syntax (foo: 42) won't make a word local (f: function [] [set 'a 1] ; == func [][set 'a 1] <- a isn't local)
  • foreach make function collect that word (wrong - to be more precise) -> f: function [] [foreach w [1 2 3][ print w]] ;== func [/local w][foreach w [1 2 3] [print w]]
nedzadarek
@nedzadarek
@greggirwin :point_up: February 20, 2019 11:29 PM
1) Is there a plan to include other functions (especially set)?
2) Can we access & modify _function/collect-words and _function/collect-deep from within Red (console? compiled?)
Vladimir Vasilyev
@9214
  1. No.
  2. No.
Gregg Irwin
@greggirwin
@nedzadarek, set works the way it does by design. It allows you to externalize a word without having to use /extern, so it will not change. And you really don't want to mod things in the bowels of the langauge, even if you can, because that will create all sorts of problems when sharing code and staying compatible with language changes.
nedzadarek
@nedzadarek

@greggirwin

It allows you to externalize a word without having to use /extern

What about set (or other "functions") in the parse (f: function [] [parse [a] [set z word!] z] z; a)? It wasn't my intention to externalize a word by using set here.
Could you change that kind of functions (or introduce others) in the parse to be "local"?

Vladimir Vasilyev
@9214
If it wasn't your intention, then word should have been bound to another context in the first place.
nedzadarek
@nedzadarek
@9214 I want to create some words in the parse. That's my intention.
It modifies global context (in the mentioned case) but have I specifically chosen that function so it behaves this way? No. I don't have a choice - there is no another function to choice from.
Vladimir Vasilyev
@9214

No idea what "create some words" means. Parse doesn't create them in any way, make, to and load do.

but have I specifically chosen that function so it behaves this way? Yes.

Fixed it for you. There's plenty of functionality to make it work the way you want, but you seem to ignore all of it so as to strengthen your argument.

>> f: func [/local z][parse [a][set z skip]] :.
>> f: does [parse [a] bind [set z skip] context [z: none]] :.

You can even intercept set and copy within callback function and aggregate their arguments for further post-processing.

callback: func [event match? rule input stack][
    also yes if all [match? find [set copy] rule/1][
        append words rule/2
    ]
]

probe unique also words: [] parse/trace [a b c][
    ahead [copy a [3 word!]] 
    ahead [set b skip]
    copy c [2 skip]
    set  d to end
] :callback

unset words

set and copy can support paths the way Rebol does, but that will cause a slight decline in perfomance. red/red#3528

What was it with your "no choice" once again..?

Gregg Irwin
@greggirwin

@nedzadarek I'm not clear on the goal or problem, but maybe @9214's example cleared it up.

I want to create some words in the parse.

This is the part I don't understand.

pimgeek
@pimgeek
how to generate an array of numbers [0 1 2 3 4] like in Python3 : list(range(5)) ? I search for answers online but without luck 😥
pimgeek
@pimgeek
image.png
Boleslav Březovský
@rebolek
change num-list: [] to num-list: copy []
pimgeek
@pimgeek
change num-list: [] to num-list: copy []
Oh, thanks very much! I will have a try
It works! I believe I need to learn more about copy and Red's "word"
Boleslav Březovský
@rebolek
@pimgeek good idea :) If you have any questions, feel free to ask. Just a note, in Red, functions do not use (...) for arguments. It works in your case, because your function has just one argument and parenthesis evaluate all values and return last. So (3) in your case becomes 3. But if you'll have function with more than one arg, it won't work.
pimgeek
@pimgeek
oh, my god ... I mistyped it and didn't notice
image.png
I have checked the manual and found the following BEGGINER MUST KNOW, thanks for your kind help, I will finish all of BEGGINER's reading.
Boleslav Březovský
@rebolek
You're welcome!
pimgeek
@pimgeek
BTW, is there anything in Red like (let ... ) in the Lisp language?
I mean, data "processing" without side effects?
bitbegin
@bitbegin
>> range: function [num [integer!]][list: clear [] repeat i num [append list i] list]
== func [num [integer!] /local list i][list: clear [] repeat i num [append list i] list]
>> range 10
== [1 2 3 4 5 6 7 8 9 10]
>> range 10
== [1 2 3 4 5 6 7 8 9 10]
>>
Boleslav Březovský
@rebolek
In Red, words have their value based on context in which they are defined, so it possible to do something like let, but differently.