Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 22 11:44
    qtxie closed #91
  • Jun 22 03:47
    bitbegin opened #91
  • Jun 22 03:31
    qtxie closed #90
  • Jun 22 03:30
    qtxie opened #90
  • May 29 02:36
    bitbegin closed #89
  • May 29 02:34
    bitbegin opened #89
  • May 29 02:32
    bitbegin closed #88
  • May 29 02:32
    bitbegin opened #88
  • May 29 02:32
    bitbegin closed #86
  • May 29 02:30
    qtxie closed #85
  • May 29 02:26
    qtxie closed #87
  • May 29 02:26
    qtxie opened #87
  • May 29 02:17
    bitbegin opened #86
  • May 28 02:50
    bitbegin opened #85
  • Apr 26 18:38
    greggirwin closed #84
  • Apr 26 18:12
    9214 opened #84
  • Dec 26 2019 08:00
    greggirwin closed #83
  • Dec 25 2019 07:49
    Intey opened #83
  • Oct 07 2019 05:49
    greggirwin closed #81
  • Jan 04 2019 20:21
    greggirwin closed #29
Respectech
@Respectech
random/only - Learning so much new stuff!
ralfwenske
@ralfwenske
I have a printF function which I find very usefull for creating formatted tabular reports. I am interested in getting feedback regarding concept and code. Perhaps others might want to play with it too. Is this the place to show it?
Boleslav Březovský
@rebolek
@ralfwenske certainly
ralfwenske
@ralfwenske

this syntax :

Red []

do load %printF.red

printF/underlined ["Some examples" [20] "This" [-14] "That" [-10] "A Rest" [-8 ] "When" [-12]] #"_"
printF ["none shown" [20] 345.2345 [-14 2 "$ " 'blank] 123.4567 [-10 3] none [-8 ] 2000-1-1 [-12]]
printF ["various 'blank" [20] 98765.7321 [-14 2 "$ " 'blank] -1.87654 [-10 3] 0 [-8 'blank] 2019-3-6 [-12]]
printF ["zero blank / not blank" [20] 0.0 [-14 2 "$ " 'blank] 0 [-10 3] -98 [-8 0 "" 'blank]]
printF ["a block shown" [20] [0 "xyz"] [-14] 0 [-10 3] -98 [-8 0 "" 'blank]]
printF/underlined ["too big float" [20] 98765444444.7321 [-14 2 "$ " 'blank] 1.87654 [-10 3] 54321 [-8 'blank] none [-12]] #"-"

str: printF/asString/underlined ["more underlined" [20] 345.2345 [-14 2 "$ " 'blank] 123.4567 [-10 3] 12345678 [-8 'blank] now/date [-12]] #"="
print [str]

produces this report:

Some examples                  This       That   A Rest         When 
____________________________________________________________________
none shown                 $ 345.23    123.456            1-Jan-2000 
various 'blank           $ 98765.73     -1.876            6-Mar-2019 
blank / not blank                        0.000      -98 
a block shown             [0 "xyz"]      0.000      -98 
too big float        $ 98765444444.73      1.876    54321              
--------------------------------------------------------------------
more underlined            $ 345.23    123.456 12345678  20-Feb-2020 
====================================================================

Code for inspection:

Boleslav Březovský
@rebolek
That's nice!
Gregg Irwin
@greggirwin
Nice work @ralfwenske. Thanks for posting.
ralfwenske
@ralfwenske
Thanks for encouragement @rebolek @greggirwin . I have made a refinement by replacing the refinement /underline:
alt
There are two odd things though (on Mac)
  • still strange behaviour when resizing window (already reported)
  • In the demo1-area some linefeeds are missing from mould :demo1
    as I have verified this with probe also this seems OS independant. Is this a bug?
Gregg Irwin
@greggirwin

Is it this? red/red#3964

If not, can you post a small reproducible case?

ralfwenske
@ralfwenske
Yes, that's it @greggirwin . Can someone confirm the lost linefeeds related to mold? Can be produced when running 'printf-test.red'.
GaryMiller
@GaryMiller

I noticed in the large numbers such as 98765.73 that there were no comma separators such as 98,765.73

I wasn't sure if that was because it was just an American standard formatting feature or because of the comma being more complicated to include in a number due to a RED dual meaning.

Boleslav Březovský
@rebolek

@GaryMiller Yes, because the comma is used as decimal separator in other languages, it can't be used as thousands separator.:

>> 123.45
== 123.45
>> 123,45
== 123.45

However, you can use an apostrophe as a thousands separator:

>> 12'345.67
== 12345.67
>> 12'345,67
== 12345.67
Adam Sherwood
@theSherwood
Are there any implementations of iterators or generators floating around in the community?
Dave Andersen
@dander
@theSherwood I did some experimentation on that - https://gist.github.com/dander/66ad65555b30286115cee675b16bf1d7
It's a little messy, but once you get past the different partial implementations, I think the sample generator functions down below should make sense. I've been meaning to get back to it to clean it up. I've learned a lot since then too, but life is crazy right now
Adam Sherwood
@theSherwood
@dander Great! Thanks!
Dave Andersen
@dander
Sure thing! I'd be interested to hear any thoughts you have about it. I think it would also be interesting to also add some sort of yield method
Adam Sherwood
@theSherwood
Yeah. I'm trying to conceive of a way to yield without a bunch of slow parsing. But I haven't thought of a good approach yet.
Dave Andersen
@dander
I was thinking maybe something with do/next saving the current position in the block
Toomas Vooglaid
@toomasv
I was recently playing with a special syntax for these.
Adam Sherwood
@theSherwood
@toomasv I remember seeing that. Really cool stuff
Toomas Vooglaid
@toomasv
:smile: Thanks! If you will play with it, any remarks/ideas are welcome.
Adam Sherwood
@theSherwood
The examples you show demonstrate just how flexible those functions are! I think the lazy sequence function you have there might be the one I focus in on.
R cqls
@rcqls
Really cool stuff @toomasv. I love the syntax when range (and I guess sequence) is followed by block as function body.
Toomas Vooglaid
@toomasv
@rcqls I didn't remember if it worked for sequences too, but seems so. E.g. this generates endless Fibonacci sequence:
>> fib: ...| [seed: [0 1] also seed/1 seed/2: sum reverse seed] ()
>> loop 10 [prin [fib ""]]
0 1 1 2 3 5 8 13 21 34
Petr Krenzelok
@pekr
Eeeh, you took a pipe char, which I dreamed of as an expression separator when writing one liners 😀
Toomas Vooglaid
@toomasv
No problem, pipe char in this syntax is special after ... and .. only.
Toomas Vooglaid
@toomasv

Hmm, looking at it... this does too:

fib: does [seed: [0 1] also seed/1 seed/2: sum reverse seed]

No need for fancy syntax here :flushed:

Vladimir Vasilyev
@9214
Reminded me of streams implementation.
Toomas Vooglaid
@toomasv
Quite an inception. Finally wrapped my head around it.
Adam Sherwood
@theSherwood
@9214 I've been probeing that thing for a little while. I still can't figure out how/where the growth function is being called in thaw. What am I missing?
OOOOOh. nevermind. It just clicked.
Vladimir Vasilyev
@9214
stream/-1 stream.
Adam Sherwood
@theSherwood
Gotcha.
That thing is some dark magic.
Very cool stuff.
Vladimir Vasilyev
@9214
Here's the kicker.
Red [
    Title:  "Bubble sort"
    Date:   17-Apr-2018
    Author: 9214
]

bubble: func [list [series!]][
    also list until [
        tail? next list: skip list do reduce [
            pick [do last] list/1 > list/2
            [swap list next list negate 1]
        ]
    ]
]
Toomas Vooglaid
@toomasv
It is nice demonstration of dynamic construction, but consumes lot of memory due to reducing. Following stripped down version takes ~300 times less memory:
bubble2: func [list [series!]][
    until [
        tail? next list: skip list either list/1 > list/2 [
            swap list next list -1
        ][1]
    ] head list
]
Adam Sherwood
@theSherwood
Interesting. @toomasv how do you do the memory profiling?
Vladimir Vasilyev
@9214
>> recycle x: stats bubble [3 7 9 9 5 0 2] stats - x
== 3844
>> recycle x: stats bubble2 [3 7 9 9 5 0 2] stats - x
== 156
GiuseppeChillemi
@GiuseppeChillemi
I didn't know about this group. What is it for?
Vladimir Vasilyev
@9214
Have you read this room's description?
Adam Sherwood
@theSherwood
@9214 Thanks!
Follow up: why does reducing result in a lot of memory consumption?
Vladimir Vasilyev
@9214
Because it allocates a new block. reduce/into avoids that and reuses the one that you give it.
Adam Sherwood
@theSherwood
Good to know. Thanks
GiuseppeChillemi
@GiuseppeChillemi
Vladimir, I am on mobile, there is no description other than the name. The android client lacks of many things like this. I see just red/red/code 😔.
Toomas Vooglaid
@toomasv

Ah, yes, of course, memory consumption grows with growing length of sorted series:

>> recycle/off
>> string: "sdlkjflkjlsdmcvLKJFawjrfaoiajfliuh.ghlskls" ()
>> profile/show [[bubble copy string][bubble2 copy string]]
Count: 1
Time         | Time (Per)   |      Memory | Code
0:00:00.001  | 0:00:00.001  |         360 | [bubble2 copy string]
0:00:00.002  | 0:00:00.002  |      104428 | [bubble copy string]
>> 104428 / 360
== 290.0777777777778

@theSherwood I used the profile func by @greggirwin.

Toomas Vooglaid
@toomasv
With reduce/into it is almost as good as stripped down version:
bubble: func [list [series!] /local code][
    code: clear []
    also list until [
        reduce/into [
            pick [do last] list/1 > list/2
            [swap list next list negate 1]
        ] clear code
        tail? next list: skip list do code
    ]
]
>> profile/show [[bubble copy string][bubble2 copy string]]
Count: 1
Time         | Time (Per)   |      Memory | Code
0:00:00.001  | 0:00:00.001  |         360 | [bubble2 copy string]
0:00:00.003  | 0:00:00.003  |         516 | [bubble copy string]
Adam Sherwood
@theSherwood
@toomasv Thanks! I'll check out the profile func
Toomas Vooglaid
@toomasv
@theSherwood You are welcome!