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
@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.
pimgeek
@pimgeek
@nedzadarek Okay, I will star it and create a reference in my TheBrain KB 👌
Do you know whether I can declare a constant value in Red lang?
pimgeek
@pimgeek
image.png
Boleslav Březovský
@rebolek
@pimgeek you can't (yet).
pimgeek
@pimgeek
@rebolek thanks for confirming that 👌
Max
@moliad
doesn't red support a macro prepropressor built-in? or is that just for R/S?
Boleslav Březovský
@rebolek
Hm, it does, I guess. But if you're in console, it doesn't help you very much.
Max
@moliad
but constants don't really make sense in a console anyways ;-)
Boleslav Březovský
@rebolek
well for testing, they do
nedzadarek
@nedzadarek
@pimgeek nice visualisation - can we see it online?
Vladimir Vasilyev
@9214

@nedzadarek

Why do you think I'm using function by default?

Because you're naive enough to think that it can cover all cases properly, and take care of set and copy in Parse.

it's just they are less suited to more complex code.

Maybe the problem is in your code then? As you yourself so boldy affirmed: but It starts to depart from the Rebol's motto "Rebol against complexity"

Let's dissect your examples.

Straw man fallacy. Do you understand how ridiculous it is to "dissect" one-liners written for demonstrative purpose? They show an idea, not an implementation.

What if you have 10 or 20 words that have more than 4 characters in it?

Then you probably should reconsider your design approach.

whenever or not someone are changing some core functionality of the parse. It makes code less readable.

I have a hard time trying to follow this argument. Purpose of bind is evident here, and you can change "core functionality of Parse" from Red, because it's a parsing engine written in R/S.

Yes, it's that easy.

If you try to discredit me, at least do so properly:

>> f: function [][
[        callback: func [event match? rule input stack][
[            also yes if all [match? find [set copy] first rule][
[                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
[    ]
== func [/local callback words][
    callback: func [event match? rule input stack] [also yes if all [match? find [set copy] first rule] [append words...
>> reduce [:a :b :c]
== [unset unset unset]
>> set [a b c][1 2 3]
== [1 2 3]
>> f
[a b c]
>> reduce [:a :b :c]
== [unset unset unset]

Above works as expected, contrary to your claim.

If you are going to say

Oh, no, I'm not going to say anything. Seeing how you don't have anything constructive (or original) to add to this discussion, I'm rather disinterested in continuing it. Arguing for the sake of arguing is solely your prerogative.

Boleslav Březovský
@rebolek
I think that the discussion can be less personal.
Vladimir Vasilyev
@9214

@pimgeek

is there anything in Red like (let ... ) in the Lisp language?

let: func [environment body][
    do bind copy/deep body context environment
]

set [a b][1 2]

let [a: 3 b: 4][
    probe a + b
]

probe a + b
nedzadarek
@nedzadarek

@9214

Because you're naive enough to think that it can cover all cases properly, and take care of set and copy in Parse.

No, read the next sentence...

Straw man fallacy. Do you understand how ridiculous it is to "dissect" one-liners written for demonstrative purpose?

I'm sorry. I should have used different word. I guess "examine" should be better.

Then you probably should reconsider your design approach.

https://github.com/red/red/blob/master/runtime/allocator.reds#L466

Purpose of bind is evident here,

Yes, it's easy to understand. You know why? Because it's just one line. When you write more line you will start to understand this.

and you can change "core functionality of Parse" from Red, because it's a parsing engine written in R/S.

Not sure why mentioned R/S but I agree, I can change (at least some part) parse.

If you try to discredit me, at least do so properly:
Above works as expected, contrary to your claim.

So, do you expect to destroy some words from some other context? Well, I'm not sure why you corrected it. I'm really confused about this code. We were talking about "local words in the function" (how to make it local) and your function changes/delete those words (and it shouldn't do this)

Oh, no, I'm not going to say anything. Seeing how you don't have anything constructive (or original) to add to this discussion, I'm rather disinterested in continuing it. Arguing for the sake of arguing is solely your prerogative.

I'm sorry. I believe in my arguments but I cannot explain it clearly to you. It might be my knowledge (language and/or programming).
I respect you for your knowledge and willing to help others so I, as you said, I don't want to waste your and mine time.
I'm fine If you don't want to answer to this post.

GiuseppeChillemi
@GiuseppeChillemi
I would try to create self generating code from "specs", either as function, or objects or parse code to create a DSL.
Could I define an object and then make it even if not defined at code start ?
Could I do the same with a function ?
Is there any code I could not create dynamically in RED ?