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
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?
Luis Vale Mendes
@lpvm
mold the block, so that it becomes a string. Did it and it works.
Vladimir Vasilyev
@9214
... why then use read/lines if you instantly convert block back to string?
Luis Vale Mendes
@lpvm
I'll explain it. For day 04 of AoC, I had the parse working fine for each line, after using read to import the input. Except that the input was not sorted. Had to use read/lines to then sortit. That's where the block took the place of the string.
Now that things are in chronological order, as some lines are dependent (need information) on a line that is above, I can parse it and complete some lines with values of a previous line. into or mold do the job.
Thanks both of you.
Luis Vale Mendes
@lpvm

Now, one step ahead. The first expression is parsed correctly, but the following are not.

input-txt: ["[1518-02-24 23:58] Guard #853 begins shift" "[1518-02-25 00:20] falls asleep" "[1518-02-25 00:43] wakes up"]
digit: charset "0123456789"
shift-date: [thru "[" keep to space skip keep to "]" skip]
action: ["Guard #" copy guard keep some digit keep (7) thru {"} | "falls asleep" keep (load guard) keep (0) | "wakes up" keep (load guard) keep
(1)]
rule: [collect some collect [into [shift-date space action skip opt txt]]]
shifts: parse input-txt txt: rule

Added the txt: before rule and added opt txt to rule but it's not working.

Vladimir Vasilyev
@9214
>> load/next "[1518-02-24 23:58] Guard #853 begins shift" 'rest
== [24-Feb-1518 23:58:00]
Boom. Done. Unless you purposedly complicate your life by using Parse.
Luis Vale Mendes
@lpvm
I want to use the guard number for the lines that don't have it, that's why I'm using Parse. The other reason is to become more proficient on it.
Vladimir Vasilyev
@9214
I don't think that me solving your problems will make you more proficient. :wink:
Vladimir Vasilyev
@9214
input: [
    "[1518-02-24 23:58] Guard #853 begins shift"
    "[1518-02-25 00:20] falls asleep"
    "[1518-02-25 00:43] wakes up"
]

actions: [begins falls wakes]

forall input [
    probe parse load input/1 [
        collect [
            into [keep pick to end]
            [thru set ID keep issue! | keep (ID)]
            set action skip keep (index? find actions action)  
        ]
    ]
]
Toomas Vooglaid
@toomasv
Why not load it at once? It is all Red types.
Vladimir Vasilyev
@9214
@toomasv dunno.
Toomas Vooglaid
@toomasv
E.g.:
input: load %day4.input
data: parse input [
    collect some [
        ahead block! into [keep date! keep time!] 
    |     keep [issue! | 'wakes | 'asleep] 
    |     skip
    ]
]
; == [22-Apr-1518 0:56:00 asleep 23-Jul-1518 0:09:00 asleep...]
Vladimir Vasilyev
@9214
input: load {
    [1518-02-24 23:58] Guard #853 begins shift
    [1518-02-25 00:20] falls asleep
    [1518-02-25 00:43] wakes up
}

actions: [begins falls wakes]

probe new-line/all parse input [
    collect some collect [
        into [keep pick to end]
        opt [thru set ID issue!] keep (load form ID)
        set action skip keep (index? find actions action) skip
    ]
] on
[
    [24-Feb-1518 23:58:00 853 1]
    [25-Feb-1518 0:20:00 853 2]
    [25-Feb-1518 0:43:00 853 3]
]
Toomas Vooglaid
@toomasv
From flat representation it is easy to sort/pick things, but not hard from deep structures also, of course.
Luis Vale Mendes
@lpvm
@9214 I don't want you to solve my problems. If I needed to solve it, would just use some Unix tool to sort the input and parse it with the rules defined before. Or just solve everything in awk.
Just want to learn Red and Parse, so nothing better to see some different examples and understand them.
There are some things I don't understand yet in your and @toomasv examples, but I'll have some hours of sleep before returning to the examples.
Gregg Irwin
@greggirwin

I've tried compiling a redCV example shape.red, however, it says the zlib1.dll is missing.

@rpherman, I haven't built redCV in a while. With luck @ldci will show up and answer. The DLL needs to be where the EXE can find it, e.g. in a system path or the same dir as the exe.

Alan
@virtualAlan
Hi, not found a decent slideshow viewer for red yet, so did this one: http://www.mycode4fun.co.uk/About-Red-Programming also a more advanced script here: http://www.mycode4fun.co.uk/example-scripts regards Alan.
sorry, it's 'example 46' - so need to scroll down a ways ....
Gregg Irwin
@greggirwin
Thanks Alan!