Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 20 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
Palaing
@Palaing
@9214 Ok thank you!
ne1uno
@ne1uno
to-image works on panel
Palaing
@Palaing
I'll try that, thanks @ne1uno
Palaing
@Palaing
well... I still miss something: layout [p: panel [box 20x20]] and to-image p still return none ...
Vladimir Vasilyev
@9214
@Palaing it will work only if you render tree of faces with View.
Semseddin Moldibi
@endo64
@Palaing Your face object should be drawn onto screen to be able to convert it to an image.
>> lay: layout [p: panel [box 20x20]] view/no-wait lay to-image lay
== make image! [136x89 #{
    0000000000003AACEF3AACEF3AA
Vladimir Vasilyev
@9214
@endo64 :rocket: :snail:
Semseddin Moldibi
@endo64
:) you won by miliseconds :D
Vladimir Vasilyev
@9214
@rebolek :point_up: we have a new player in town
view/no-wait [b: box red 20x20 button "click" [? (to image! b)]]
lepinekong
@lepinekong_twitter
@nedzadarek it's windows 10 not windows 8 if you talk about latest case. possible it is memory but since theres's enough memory for stable I'm posting it.
Boleslav Březovský
@rebolek
@endo64 go go go!
@9214 I'm on vacation and my focus is really somewhere else these days. For example I was saving wren today so our cat couldn't eat him. He's a predator, I know, but first he has to eat all the catfood we bought, then he can go hunting.
Semseddin Moldibi
@endo64
@rebolek I'll do my best 🐢
Palaing
@Palaing
great thanks @9214 and @endo64 for explanation and example!
Vladimir Vasilyev
@9214
@Palaing you're welcome!
Greg T
@gltewalt
"the image is created with the given dimensions, and with all pixels having color 255.255.255 and transparency 255"
>> img-a: make image! 100x100
== make image! [100x100 #{
    FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

>> to-tuple img-a/rgb
== 255.255.255.255.255.255.255.255.255.255.255.255

>> to-tuple img-a/argb
== 255.255.255.255.255.255.255.255.255.255.255.255

>> to-tuple img-a/alpha
== 0.0.0.0.0.0.0.0.0.0.0.0
Shouldn't alpha be 255 ?
Vladimir Vasilyev
@9214
@gltewalt from what I know, pixel is fully transparent if it has an alpha channel of 0.
Greg T
@gltewalt
If you prefer a non converted return value:
>> img-a/alpha
== #{
00000000000000000000000000000000000000000000000000000000000000...
I'm I reading it wrong, or is that an error in the spec?
@meijeru
Greg T
@gltewalt
Yes, full transparency is 0
" if there are 3elements, A has the default value of 255 (fully opaque)."
>> img-b: make image! [100x100 210.54.128]
== make image! [100x100 #{
    D23680D23680D23680D23680D23680D23680D236

>> img-b/alpha
== #{
00000000000000000000000000000000000000000000000000000000000000...
Rudolf Meijer
@meijeru
See issue #2812, of July 2017
Linker Storm
@linker_storm_twitter

Hi everybody.

I have a parse problem : I would want to filter out some tags which NOT contain some constant string.

Here a sample and my naive (bad) approach :

t: {
<tag attr1="val1" attr2="val2" desc="desc1" attr3="val13"></tag>
<tag attr1="val3" attr2="val4" attrSomeTimes="100" desc="desc2" attr3="val14"></tag>
<tag attr1="val5" attr2="va6" desc="desc3" attr3="val15"></tag>
<tag attr1="va7" attr2="val8" desc="desc4" attr3="val16"></tag>
<tag attr1="val9" attr2="val10" attrSomeTimes="100" desc="desc5" attr3="val17"></tag>
<tag attr1="val11" attr2="val12" desc="desc6" attr3="val18"></tag>
}

r: [
    any [
        thru "<tag "
        thru {attrSomeTimes="100"}
        to "</tag>"
        break ; Don't want this tag because it contains {attrSomeTimes="100"}
        |
        thru "<tag "
        thru {desc="}
        copy desc to {"}
        (print desc)
        to "</tag>" ; I want this tag because it DOESN'T contains {attrSomeTimes="100"}
    ]
]

parse t r

The output is empty, while I expected "desc1", "desc3", "desc4" and "desc6" because I want filter out "desc2" and "desc5" which tags contains {attrSomeTimes="100"}.

I can easily point that the thru {attrSomeTimes="100"} jump to the second tag, ignoring the first.

I have made several tests with ahead, if, fail, not but wiht no luck, because I know that I'm using them incorrectly.
I have carefully read 0.4.1: Introducing Parse.
I have browsed red, gritter and wallet source code, but too difficult to grasp the use of the parse DSL keywords quoted above.

Maybe we can't do that with only one rule ?

Thanks for your help.

Linker Storm
@linker_storm_twitter
And I have tried opttoo...
Toomas Vooglaid
@toomasv
Hi, @linker_storm_twitter ! May be this:
>> parse t [collect any [{attrSomeTimes="100"} thru {</tag>} | {desc="} keep to {"} | skip]]
== [
    "desc1" 
    "desc3" 
    "desc4" 
    "desc6"
]
Linker Storm
@linker_storm_twitter
I see you master "parse" dialect ! :)
So simple, thanks a lot @toomasv !
Toomas Vooglaid
@toomasv
@linker_storm_twitter You are welcome! Do you want an analysis of your rule to understand why it was failing?
Linker Storm
@linker_storm_twitter
Oh yes please, I love learning !
And understanding of course... :)
Toomas Vooglaid
@toomasv

@linker_storm_twitter Problem with your rule was that after matching "<tag" you jumped at once thru attrSomeTimes="100", thus skipping first tag. Then, after skipping to the end of this tag you break the parsing and as it has not reached the tail, it fails.

If you take out break, then it goes further, BUT as first rule succeeded (we are now before the second "</tag>"),
parsing continues with new round - the first alternative again, which brings us to the end of fifth tag (i.e. just
before the end tag after second attrSomeTimes="100"). Next round: as there are no more attrSomeTimes="100",
the first alternative now fails and parse tries second alternative. It goes through {desc="}, copies "desc6" and prints it.
Then skips to "</tag>". On next round it doesn't find "<tag" neither of the first nor of the second alternative,
and as there is no more alternatives parsing stops and returns false because it has not reached the tail of the string.

So, first mistake is to jump thru {attrSomeTimes="100"} - doing so you skip intermediate data you need to find.
Second, you don't need to break in the end of succeeded rule here - doing so you interrupt parsing without checking further.
break can be used in this way if your last match is the only thing you needed from parse.
Third, you usually need to use skip as last alternative to move pointer on if earlier alternatives do not match.

In current exercise you need to check on every letter, if this starts string with either of the two things you want to act on:
avoid "desc=" just after "attrSomeTimes.." and record "desc=" otherwise. So you put these two alternatives in the beginning
with corresponding further rules (skip thru "</tag>" in first case and keep in second), and skip in the end to move on
if neither of these match. In current case the order of first two rules doesn't matter.

To see what your rule is doing you can put out some debugging info from this while developing, e.g.:

r: [
    any [
        (prin "first: ") thru "<tag " s: (probe s)
        thru {attrSomeTimes="100"} s: (probe s)
        to "</tag>" s: (probe s)
        ;break ; Don't want this tag because it contains {attrSomeTimes="100"}
        |
        s: (prin "second: " probe s) thru "<tag "
        thru {desc="}
        copy desc to {"}
        (print desc)
        to "</tag>" ; I want this tag because it DOESN'T contains {attrSomeTimes="100"}
        ;| skip
    ]
]
Linker Storm
@linker_storm_twitter
Thanks a lot Toomas, it's very clear to me now => parse is a very powerful feature in Red, as it is in Rebol (thanks Carl :)) and master it allows powerful parsing in all sort of areas, where regexp could shine too but with more, more clutter :)
Linker Storm
@linker_storm_twitter
Another case that can raise : the attrSomeTimes attribute is placed after the desc attribute, breaking the current rule :
```
t: {
<tag attr1="val1" attr2="val2" desc="desc1"></tag>
<tag attr1="val3" attr2="val4" desc="desc2" attrSomeTimes="100"></tag>
<tag attr1="val5" attr2="va6" desc="desc3"></tag>
<tag attr1="va7" attr2="val8" desc="desc4"></tag>
<tag attr1="val9" attr2="val10" desc="desc5" attrSomeTimes="100"></tag>
<tag attr1="val11" attr2="val12" desc="desc6"></tag>
}

r: [
    collect any [
        {attrSomeTimes="100"} thru {</tag>}
        |
        {desc="}  keep to {"}
        |
        skip
    ]
]
probe parse t r
Toomas Vooglaid
@toomasv
@linker_storm_twitter This would allow any position of attributes:
r: [
    collect any [
        thru {<tag } s: copy tag to {</tag>} [
            if (find tag {attrSomeTimes="100"}) 
        |    :s thru {desc="} keep to {"}
        ]
    |    skip
    ]
]
Toomas Vooglaid
@toomasv
Also this, with parse-only:
r: [
    collect any [
        {</tag>} c: :s keep to {"} :c
    |    {desc="} s:
    |    {attrSomeTimes="100"} thru {</tag>} 
    |    skip
    ]
]
nedzadarek
@nedzadarek

@linker_storm_twitter can't you load tags (or just keep it into block)? The red has built-in tag! type (<foo baz="bar">). If you have collection of values not characters you can just find attrSomeTimes="100" ( sadly tag! is just a string):

tags: [
    <tag attr1="val1" attr2="val2" desc="desc1" attr3="val13"> </tag> 
    <tag attr1="val3" attr2="val4" attrSomeTimes="100" desc="desc2" attr3="val14"> </tag> 
    <tag attr1="val5" attr2="va6" desc="desc3" attr3="val15"> </tag> 
    <tag attr1="va7" attr2="val8" desc="desc4" attr3="val16"> </tag> 
    <tag attr1="val9" attr2="val10" attrSomeTimes="100" desc="desc5" attr3="val17"> </tag> 
    <tag attr1="val11" attr2="val12" desc="desc6" attr3="val18"> </tag>
]

new-tags: collect [
  foreach [tag end-tag] tags [
    unless find tag {attrSomeTimes="100"} [keep tag keep end-tag]
  ]
]

probe new-tags

1) I assume your tags are valid tag!
2) I assume you search for attrSomeTimes="100" without spaces around = not attrSomeTimes = "100" (or any other combination). If you have such values you may use block + parse OR just parse + your string.

Linker Storm
@linker_storm_twitter
@toomasv Thanks a lot again
@nedzadarek Thanks a lot too and indeed, it's a valid XML file that I parse, so your solution is ok for me
Linker Storm
@linker_storm_twitter
@toomasv As I understand very well the first snippet (with the if), I need more explanation with the second (parse only)
Toomas Vooglaid
@toomasv

@linker_storm_twitter Second depends on the fact that </tag> is encountered in start of an alternative only if there was no autoSomeTimes="100" before it since the last </tag> (or beginning). When it is encountered there has been match of desc=" before it and no auto.... So, after matching desc=" I record the position s:and continue walking towards </tag>. If no auto... is seen, I reach </tag>. Position is recorded again (c:). Then I go back to position recorded earlier, after desc=" (:s), keep my value, and continue from position after </tag> (:c).

But if you want to keep whole tag, then @nedzadarek's method is better of course.

Toomas Vooglaid
@toomasv
Although you can use also the above parsing method to collect whole tags:
r: [
    collect any [
        {<tag} s: 
    |    {</tag>} c: keep (copy/part skip s -4 c)
    |    {attrSomeTimes="100"} thru {</tag>} 
    |    skip
    ]
]
viayuve
@viayuve
Linker Storm
@linker_storm_twitter
Ok Toomas, understood, thanks a lot :)
Toomas Vooglaid
@toomasv
:+1:
Vladimir Vasilyev
@9214
@linker_storm_twitter I wouldn't recommend using rules with skip on a real input, as it traverses series element by element, which can take quite some time. load approach is the easiest one, but also sub-optimal, because of current load implementation in Red (not in R/S), which sacrifices speed for ease of developing.
lepinekong
@lepinekong_twitter
can red create android app without downloading the gigantic android sdk :)
Boleslav Březovský
@rebolek
@9214 I would recommend skip everywhere. skip is you friend. to and thru are your enemies. And skip is also fast, unlike to and thru.
>> st: append/dup "" space 100000
== {                                                                                                                        ...
>> append st #"x"
== {                                                                                                                        ...
>> dt [loop 1000 [parse st [to #"x"]]]
== 0:00:00.240976
>> dt [loop 1000 [parse st [#"x" | skip]]]
== 0:00:00.00207
Vladimir Vasilyev
@9214
@rebolek interesting, I got the exact opposite results last time I compared them, though, that was quite a long time ago.
And shouldn't it be to [#"x" | end]?