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
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!
OneITI
@OneITI
Hello.
I am a high school student, highly interested in open-source culture and Red project itself.
I would like to contribute to Red project sincerely.
Semseddin Moldibi
@endo64

@OneITI Welcome! First step is reading some docs :)
https://www.red-lang.org/p/contributions.html
https://github.com/red/red/wiki
https://github.com/red/red/wiki/%5BLINKS%5D-Learning-resources

And don't hesitate to ask you questions here and in the /help room

OneITI
@OneITI
Okay, thank you for your genial welcome. I think this project is actually congenial to me.
I have a little question of Red's camera function.
I have tried the camera face in this article; http://helpin.red/Faces.html
I have compiled the second source code, which enables a button to save the current stream as a jpeg-format file.
However, the saved image files are nothing but an immaculately white.
I consider this to be a bug regarding the image process or binary file output.
OneITI
@OneITI
Moreover, my operating system is macOS High Sierra(10.13.6), and I am utilizing Red 0.6.3 with the Visual Studio Code(1.29.1) plugin.
Vladimir Vasilyev
@9214
Perhaps you should update to the latest version first, before pointing out bugs.
And there's certainly no need in double posting your questions in different rooms.
Gregg Irwin
@greggirwin
Welcome @OneITI!
Palaing
@Palaing
wrong syntax, but the error message is weird too:
>> 1 < 2 or 2 > 3
*** Script Error: < does not allow integer! for its value2 argument
*** Where: <
*** Stack:
Toomas Vooglaid
@toomasv
Should be Error: or does not allow...
Somehow op in message is not updated?
Boleslav Březovský
@rebolek
but or allows integer!
Toomas Vooglaid
@toomasv
>> true or 3
*** Script Error: or does not allow integer! for its value2 argument
Boleslav Březovský
@rebolek
Yeah, but
>> 2 or 3
== 3
The error message probably should say something like incompatible values
Toomas Vooglaid
@toomasv
Yes
Can you explain treatment of integers by or and and?
Boleslav Březovský
@rebolek
@toomasv like in C.