Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 08 21:44

    dockimbel on fast-lexer

    FEAT: minor update for year in … (compare)

  • Dec 08 21:41

    dockimbel on fast-lexer

    FIX: [R/S] ensures that functio… (compare)

  • Dec 07 17:10

    qtxie on Direct2D

    FEAT: code refactoring for Dire… (compare)

  • Dec 07 12:12
    hiiamboris closed #4178
  • Dec 07 12:12
    hiiamboris commented #4178
  • Dec 07 12:07
    qtxie commented #4178
  • Dec 07 11:55
    hiiamboris opened #4178
  • Dec 07 11:48
    hiiamboris opened #4177
  • Dec 06 21:55
    hiiamboris commented #4176
  • Dec 06 21:35
    greggirwin commented #4176
  • Dec 06 20:22
    hiiamboris opened #4176
  • Dec 06 14:06

    qtxie on Direct2D

    FIX: rich-text does not work pr… (compare)

  • Dec 06 11:27

    qtxie on Direct2D

    FEAT: preliminary migrate to Di… (compare)

  • Dec 06 08:40

    dockimbel on fast-lexer

    FEAT: extends libRedRT API with… FEAT: ensures native reference … (compare)

  • Dec 05 19:56
    greggirwin commented #4162
  • Dec 05 16:35
    DideC commented #4162
  • Dec 05 10:43
    bitbegin commented #4171
  • Dec 05 07:06

    qtxie on GTK

    FIX: check font type not right (compare)

  • Dec 05 07:06
    qtxie closed #4175
  • Dec 05 03:19
    bitbegin opened #4175
Gregg Irwin
@greggirwin
I don't know if I've ever tried this exact thing before.
Cristián Romo
@cromo
Right, that's more or less what I'm looking for
Gregg Irwin
@greggirwin
I think it's a bug. @9214?
Cristián Romo
@cromo
Actually, if there's a generic way to call a function definition in place (like JS's IIFE: function(){ ... }()) that's really what I'm after
Gregg Irwin
@greggirwin
That is, if the paren is the last segment and refers to a func, the func is called, but the computed index is returned instead of the evaluated func result.
Vladimir Vasilyev
@9214
>> fs: reduce [does [print "hi"] does [print "hey"] func [x][probe x probe add x 1]]
== [func [][print "hi"] func [][print "hey"] func [x][probe x probe add x 1]]
>> fs/(1 + 2) 100
100
101
== 3
Gregg Irwin
@greggirwin
@9214, I did that too. :^)
Vladimir Vasilyev
@9214
(1 + 2) evaluated last and its result is returned from expression
dunno if it's a bug or a feature though
Gregg Irwin
@greggirwin
I vote for bug.
Cristián Romo
@cromo
Aww, it returns the value of the paren! ? That's surprising and probably not useful
I vote bug.
Gregg Irwin
@greggirwin
R2 returns the func result, as expected. Easy to miss, as this is not a common thing to do.
I'll file a ticket.
Cristián Romo
@cromo
Lookup tables of functions are quite common in functional programming, which is why I ask.
Vladimir Vasilyev
@9214

generic way to call a function definition in place

do reduce [...]

Gregg Irwin
@greggirwin
Seems single arity funcs are the key. 0 or >1 args avoids the problem.
Cristián Romo
@cromo
What problem?
Vladimir Vasilyev
@9214
paren! in path returning result of evaluation
Gregg Irwin
@greggirwin
My mistake, I jumped to R2 when making my ticket. Arity has no effect.
Cristián Romo
@cromo
Ah, I tried it and didn't see a problem other than it returning the paren! value in Red, hence my confusion
Vladimir Vasilyev
@9214
@cromo
>> λ: func [spec body args][do reduce head insert args func spec body]
== func [spec body args][do reduce head insert args func spec body]
>> λ [x][x + 1][2]
== 3
>> 
>> λ [x][reverse x][[1 2 3]]
== [3 2 1]
Cristián Romo
@cromo
do reduce [...], got it
Gregg Irwin
@greggirwin
@cromo, the path/paren bug has been fixed, just FYI.
Ruslan Prokopchuk
@ul
Hey folks, would you mind helping me with parse? It looks very intuitive, but I hit the wall and don't understand how it does particular things.
In that snippet https://gist.github.com/ul/0e04ecc600b2c975e863baf1f41e0e4b name get lost before collecting phase.
If I put (print name) before #+BEGIN_SRC matching rule, name is still here.
But after that word for somewhat reason it's lost.
Another thing is why I don't do just keep to newline in src-name instead of copy. That's because Red collects a lot of empty entries in that case when rule doesn't match, which also seems strange to me.
Gregg Irwin
@greggirwin

You are using to newline, but then not skipping the newline. So you don't get a match on src-body, and then it will backtrack.

src-name:  ["#+NAME:" any space copy name to newline skip]

Adding skip will probably also eliminate your extra values if you change the src-name rule as you propose.

Basically, keep can see that the next rule matches, but doesn't know about outside backtracking.
Ruslan Prokopchuk
@ul
@greggirwin Thanks! I need to build intuition about those topics, keep to skip...
Adding skip as you proposed works like a charm, now I need to disenchant it and understand.
Gregg Irwin
@greggirwin
It's the difference between to and thru. To stops at the beginning of the match. Both are powerful and can trip you up, if you're doing more than newline targets with them. i.e., they're greedy.
An alternative would be to use thru, and then trim the trailing newline from your result.
Gregg Irwin
@greggirwin

Composite is a func I'm going to propose for inclusion with the format work I'm doing, though it can stand on its own as well. It's sort of like compose for strings. That is, you evaluate expressions found in a string and insert their results in situ. The basic idea is simple, but there are a lot of details to consider. I have found that being able to evaluate in a specific context is very useful (@endo64 did this originally for build-markup in R2). Custom markers I'm still torn about (@toomasv's idea). Custom error values are helpful if you're passing data to users directly, IME. Is there a solid argument for allowing mismatched expression markers? I haven't come up with one.

In any case, it's food for thought: https://gist.github.com/greggirwin/d40a0e3b4c8de31a7d3b82695b9b4b03

Toomas Vooglaid
@toomasv
@greggirwin Marvelous!
Do you have some custom functions here from thy formatbag?
{^/        name: :(form-full-name cust):^/        rank: :(as-ordinal index? find scores cust):^/        ser#: :(cust/uuid):^/    } == {^/        name:  *** Error: no-value Where: form-full-name cust *** ^/        rank:  *** Error: no-value Where: as-ordinal index? find scores cust *** ^/        ser#:  *** Error: no-value Where: cust/uuid *** ^/    }
Gregg Irwin
@greggirwin
@toomasv, that example was to show why custom error values can be useful, and how multiple error vals are inserted in the result. Ordinals will be part of format though, yes.
    set 'ordinal-suffix func [    ; English only right now.
        "Return the ordinal suffix for a number (th, st, nd, rd, etc.)"
        val [integer!]
    ][
        ;if negative? val [make error! "Ordinal-suffix doesn't support negative numbers"]
        either all [val >= 10 val <= 20] ['th] [
            switch/default remainder val 10 [1 ['st] 2 ['nd] 3 ['rd]] ['th]
        ]
    ]

    set 'as-ordinal func [
        "Return the ordinal string for a number (1st, 2nd, 3rd, etc.)"
        val [integer!]
    ][
        if negative? val [make error! "Ordinal doesn't support negative numbers"]
        append form val ordinal-suffix val
    ]
I also originally allowed any-string! vals for markers, but file! values turned out to be problematic for things like %<, and email and url values don't seem very useful there either.
Toomas Vooglaid
@toomasv
@greggirwin Thanks for explanation!
Yes, I imagine any-stringmight become very ..., hmm, ..., interesting, as a marker.
Mateusz Czapliński
@akavel
I'm trying the following code, but clicking the > button changes only one value (in the very bottom-right cell), do I have some error? or is it a bug in view/vid/react?
state: make reactor! [
    month-start: do [d: now/date  d/day: 1  d]
]

month-pane: probe collect [repeat offset (7 * 6) [
    keep compose/deep [
        button react [
            d: state/month-start
            d/weekday: 1
            d: d + (offset - 1)
            face/data: d
            face/text: probe to-string d/day
        ]
    ]
]]

view [
    button ">" [ d: state/month-start  d/month: d/month + 1  state/month-start: probe d ] return
    group-box 7 month-pane
]
issue-view-react.gif
I attached a screencast (gif) above showing what happens: the probes in react blocks all get evaluated apparently, but only one button's text seems to change
Mateusz Czapliński
@akavel
(bottom-right)
Mateusz Czapliński
@akavel
I'll be leaving the gitter room, so I copied the report to red/red#3101
Christopher Ross-Gill
@rgchris
@akavel Could possibly ask as a StackOverflow question—there may be something else awry here.
Gregg Irwin
@greggirwin
@akavel, not sure if you're leaving forever, or just a while. In any case, what you're doing is a bit tricky, in that you're composeing your react block, but not copying it. If you do that, it should work.
state: make reactor! [
    month-start: do [d: now/date  d/day: 1  d]
]

month-pane: probe collect [
    repeat offset (7 * 6) [
        keep copy/deep compose/deep [
            button react [
                d: state/month-start
                d/weekday: 1
                d: d + (offset - 1)
                face/data: d
                face/text: probe to-string d/day
                ;print mold reduce [face/offset face/text]
            ]
        ]
    ]
]

view [
    button ">" [
        d: state/month-start  d/month: d/month + 1  state/month-start: probe d
    ] return
    group-box 7 month-pane
]
It wasn't clear to me either, at a glance, so I added the print line you see, and the offset for the face was the same in every reaction.
Mateusz Czapliński
@akavel
@greggirwin indeed, seems to work, thanks!