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
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.
>> a: context [b: 1 print b context [b: 3 print b] print b]
1
3
1
@bitbegin or you can use collect and get rid of local block:
>> range: func [num][collect [repeat i num [keep i]]]
== func [num][collect [repeat i num [keep i]]]
>> range 5
== [1 2 3 4 5]
bitbegin
@bitbegin
:+1:
nedzadarek
@nedzadarek

@9214 @greggirwin

create some words

When you use parse you can set words to some value, for example in parse [a] [set w word!], parse creates word w.

Fixed it for you.

No. You are wrong.

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.

Why do you think I'm using function by default? It's the closest to a "I don't care, just don't mess global space - make everything local" attitude. I'm not ignoring anything - it's just they are less suited to more complex code. Let's dissect your examples.

f: func [/local z][parse [a][set z skip]]

You have only one local word z. What if you have 10 or 20 words that have more than 4 characters in it? For example:

f: func [
  /local abakus abrakadabra ...
][..]

You are making code longer (harder to understand, even it's by "a little).

f: does [parse [a] bind [set z skip] context [z: none]]

You find this in someone's code. What's the purpose of the bind here? You have to go to the context to see whenever or not someone are changing some core functionality of the parse. It makes code less readable.

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

>> f: function [] [
[    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
[    ]
== func [/local words][
    probe unique also words: [] parse/trace [a b c] [ahead [co...
>> a
*** Script Error: a has no value
*** Where: catch
*** Stack:  

>> a: 42
== 42
>> f
[]
>> a
== [a b c]

Yes, it's that easy.

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

If you are going to say I have choice because the language is (is it?) turing complete then you should check what is the Turring tarpit. Is it the turring tarpit? I guess no... but It starts to depart from the Rebol's motto "Rebol against complexity". Especially your binding code.

pimgeek
@pimgeek
😍 So much precious knowledge sharing~
pimgeek
@pimgeek
@nedzadarek Thanks for quoting the Turing-Tarpit anecdote, it's really mind-refreshing 🤯
pimgeek
@pimgeek
@rebolek the collect ... keep procedure is amazing, if you don't show me the code, I would have to struggle much more to understand if by reading the manual 👍😊
@bitbegin Thanks for demonstrating the usage of clear 👏
nedzadarek
@nedzadarek
@pimgeek If you liked collect then you could try cold.