Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 01 2018 17:34
    @greggirwin banned @BIjeuca_twitter
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:20
    @PeterWAWood banned @TimeSeriesLord
Luis Vale Mendes
@lpvm
I'll follow your advice. I'm solving the puzzles of Advent of Code 2018.
for input-txt: "#102 @ 1,3:^/"
parse input-txt [any [thru "#" copy nr to space break]] although nr gets the number correctly, parse returns false. What's wrong with my rule?
Boleslav Březovský
@rebolek
Your rule is fine, but does not match end. Parse returns true only when your rule sucessfully matched end.
So either add to end or ignore the return value.
Luis Vale Mendes
@lpvm
thought break had that meaning but it's meant to exit control loops
Luis Vale Mendes
@lpvm
Now, to insert the matched parts into a block. I've built this simple example: https://gist.github.com/lpvm/77780cb47fc8ef9281ce6188260ccbc2
l and r (left and right of #) are parsed right, but neither parse traversed the second line nor are values inserted in b.
Vladimir Vasilyev
@9214
@lpvm well, maybe that's because you don't insert anything in b?
And don't iterate over the whole string?
>> split "1#11^/2#22^/" charset "#^/"
== ["1" "11" "2" "22" ""]
Luis Vale Mendes
@lpvm
Tried [append b copy l ... didn't work, either.
Vladimir Vasilyev
@9214
@lpvm have you read Parse documentation?
Luis Vale Mendes
@lpvm
Yes. This is a minimal example, I still need the parse instead of the split, although I can use split first and then the parse for each line afterwards.
Vladimir Vasilyev
@9214
>> parse "1#11^/2#22^/" [collect some [keep to "#" skip keep to newline skip]]
== [#"1" "11" #"2" "22"]
What's the problem you're trying to solve, once again?
Luis Vale Mendes
@lpvm
some are parsed as char! some as string!. Interesting. How would you do to get this result: [[#"1" "11"] [#"2" "22"]]?
Vladimir Vasilyev
@9214
>> parse "1#11^/2#22^/" [collect some collect [keep to "#" skip keep to newline skip]]
== [[#"1" "11"] [#"2" "22"]]
Ah, I see, it's AoC No. 3.
Luis Vale Mendes
@lpvm
Yes, I'm trying to improve my skills on Red to jump to a bigger project.
Vladimir Vasilyev
@9214
@lpvm I would suggest to put away Parse for a moment, as I don't think that 3/1 really requires it.
Luis Vale Mendes
@lpvm
@9214 From the parse blog, it's said that collect should be followed by a block of some rule [rule]. Is this correct? I'm asking this because you used collect some, not collect [some
Vladimir Vasilyev
@9214
@lpvm you can wrap rule in a block if you want to, it won't change anything.
Luis Vale Mendes
@lpvm
You saved my day! Now, I'm ready to solve the puzzle. The solution is in my head already, parsing the input was the most difficult part. Thanks!
Vladimir Vasilyev
@9214
@lpvm you're welcome. As I said, Parse isn't really necessary here. You can always process string using native functions, even if it looks naive.
Gregg Irwin
@greggirwin
On red-by-example, @mikeparr is the current lead there, but anyone can contribute new entries. Just work with him on the process. I'm sure he'll be happy to get some help.
Luis Vale Mendes
@lpvm
Yes, but being more comfortable with parse is also important to me.
Vladimir Vasilyev
@9214
@lpvm ok, but don't forget about baby steps.
Vladimir Vasilyev
@9214
:baby: ( :neckbeard: )
>> load replace form split "#123 @ 3,2: 5x4" complement charset [#"0" - #"9" ",x#"] comma 'x
== [#123 3x2 5x4]
Gregg Irwin
@greggirwin
@9214 :+1: (baby steps)
GiuseppeChillemi
@GiuseppeChillemi

@9214

thought break had that meaning but it's meant to exit control loops

That's the "prior knowledge" concept which is working here... ;-)

rpherman
@rpherman
I've tried compiling a redCV example shape.red, however, it says the zlib1.dll is missing. It's there, but is this a 32-bit vs. 64-bit issue? I am on Win 64-bit machine. Thanks.
rpherman
@rpherman
I should add it compiles, and this is the message on double clicking the shape.exe file.
Luis Vale Mendes
@lpvm
Why does this need partenthesis? put singles cl-id (select singles cl-id) + 1, since evaluation is left to right.
Boleslav Březovský
@rebolek
Because select function will evaluate its arguments first
Luis Vale Mendes
@lpvm
arguments, plural? ? select says value (singular) as second argument...
Boleslav Březovský
@rebolek
Yeah, but select takes two arguments.
And if you leave parenthesis out, select sees select singles cl-id + 1, which is select (singles) (cl-id + 1).
Luis Vale Mendes
@lpvm
yes, I know, that's why I asked. + takes precedence, then.
Vladimir Vasilyev
@9214
Operators have precedence over functions. Functions take as much expressions as they need, operators take one value on the left and one expression on the right.
Luis Vale Mendes
@lpvm
It's explained, thank you both.
Found it in the Rebol user's guide
Luis Vale Mendes
@lpvm
Can't figure out what's the problem with this:
input-txt: ["[1518-02-24 "]
shift-date: [thru "[" keep to space to end]
shifts: parse input-txt [collect some collect [shift-date skip]]
probe shifts
== [[]]
Vladimir Vasilyev
@9214
@lpvm are you sure that input-txt should be a block?
Luis Vale Mendes
@lpvm
Yes, that's the result of a read/lines %input.txt
Vladimir Vasilyev
@9214
Why then do you parse block as if it's a string?
>> parse ["[1518-02-24 " "[123-45-6 "][collect some [into [thru "[" keep to space skip]]]
== ["1518-02-24" "123-45-6"]
Again, step aside from Parse. You don't need it to extract something between [ and .
Luis Vale Mendes
@lpvm
into, alright. Could mold it as well, right?
Vladimir Vasilyev
@9214
mold what?