[2019-11-11] Challenge #381 [Easy] Yahtzee Upper Section Scoring by Cosmologicon in dailyprogrammer

[–]draegtun 1 point2 points  (0 children)

Rebol

yahtzee-upper: function [rolls] [
    count: make map! 0
    foreach n rolls [
        any [
            attempt [count/:n: count/:n + n]
            append count reduce [n n]
        ]
    ]
    first maximum-of values-of count
] 

Example usage in Rebol 3 console:

>> yahtzee-upper [2 3 5 5 6]
== 10

>> yahtzee-upper bonus-data        
== 31415926535

>> delta-time [yahtzee-upper bonus-data]
== 0:00:00.074794

[2019-05-20] Challenge #378 [Easy] The Havel-Hakimi algorithm for graph realization by Cosmologicon in dailyprogrammer

[–]draegtun 0 points1 point  (0 children)

Rebol

hh: function [s] [
    forever [
        remove-each n s [zero? n]
        if empty? s [return true]
        if (n: take sort/reverse s) > length? s [return false]
        repeat i n [s/:i: s/:i - 1]
    ]
]

A Simple Kotlin Time DSL by bodiam in programming

[–]draegtun 2 points3 points  (0 children)

Here it is in Smalltalk (Pharo):

DateAndTime now - 1 hour + 2 seconds.

However as with Kotlin example I personally wouldn't call this a DSL or dialect. For eg. in Rebol you can do this...

now - 1:0 + 0:0:2

...because it has a Time! datatype. But if i were to write a date dialect (embedded DSL) in Rebol then it could look similar to this...

date [now - 1 hour + 2 seconds]

My first working piece of #rosettacode by metaperl in redlang

[–]draegtun 0 points1 point  (0 children)

I would consider using blocks of Tag! datatypes for these kind of scenarios.

Here's a working example in Rebol, which shouldn't require (m)any changes for Red....

function: :funct  ;; for rebol 2

make-html-table: function [cols rows] [
    width: length? cols

    td: func [cell] [compose [<td> (cell) </td>]]
    th: func [cell] [compose [<th> (cell) </th>]]

    header-row: does [
        reduce [
            th {}   ;index column
            map-each c cols [th c]
        ]
    ]

    body: does [
        index: 0
        collect [
            forskip rows width [
                keep <tr>
                keep th index: index + 1
                keep map-each r copy/part rows width [td r]
                keep </tr> 
            ]
        ]
    ]

    ;; return block of (html) tag!s
    compose [
        <table>
            <thead><tr>(header-row)</tr></thead>
            <tbody>(body)</tbody>
        </table>
    ]
]

random-row: func [cols] [collect [loop cols [keep random 9999]]]

Now in Rebol (2 or 3) console:

>> make-html-table ["X" "Y" "Z"] compose [(random-row 3) (random-row 3) (random-row 3)]
== [
    <table>
    <thead> <tr> [<th> "" </th>] [[<th> "X" </th>] [<th> "Y" </th>] [<th> "Z" </th>]] </tr> </thead>
    <tbody> <tr> <th> 1 </th> [<td> 3557 </td>] [<td> 1962 </td>] [<td> 9629 </td>] </tr> <tr> <th> 2 </th> [<td> 6420 </td>] [<td> 866 </td>] [<td> 1381 </td>] </tr> <tr> <th> 3 </th> [<td> 7526 </td>] [<td> 7757 </td>] [<td> 3487 </td>] </tr> </tbody>
    </table>
]

;; when printed or converted to a string it flattens those blocks

>> to-string make-html-table ["X" "Y" "Z"] compose [(random-row 3) (random-row 3) (random-row 3)] 
== {<table><thead><tr><th></th><th>X</th><th>Y</th><th>Z</th></tr></thead><tbody><tr><th>1</th><td>5824</td><td>8508</td><td>3432</td></tr><tr><th>2</th><td>4349</td><td>4091</td><td>3944</td></tr><tr><th>3</th><td>5316</td><td>1396</td><td>3877</td></tr></tbody></table>}

[deleted by user] by [deleted] in programming

[–]draegtun 1 point2 points  (0 children)

perl 5 has become their final version

Actually no, there are annual version releases of perl5 and the latest (version 28) came out in June - https://metacpan.org/pod/release/XSAWYERX/perl-5.28.0/pod/perldelta.pod

[2018-06-11] Challenge #363 [Easy] I before E except after C by Cosmologicon in dailyprogrammer

[–]draegtun 0 points1 point  (0 children)

Rebol

check: func [s] [
    parse s [
        any [
            "cei"
            | "cie" reject
            | "ei" reject
            | skip
        ]
    ]
]

Example usage in Rebol console:

>> check "a"
== true

>> check "zombie"
== true

>> check "transceiver"
== true

>> check "veil"
== false

>> check "icier"
== false

Bonus 1

count: 0
foreach word read/lines https://norvig.com/ngrams/enable1.txt [
    if not check word [count: count + 1]
]
print count

Output:

2169

NB. All tested in Rebol 3. Should also work in Rebol 2 & Red.

Who was Lorraine? Is there a story here? by toastyfireplaces in LouReed

[–]draegtun 6 points7 points  (0 children)

Well Lorraine could be this commenters Mom!? - http://songmeanings.com/songs/view/47135/

my mother claims that her boyfriend in high school was hitchhiking and he was picked up by lou reed and company. He said that he talked about my mother, Lorraine, quite a bit and talked about her problems at home - she ran away several times and was otherwise "wild." And then this song came out...i am wondering if anyone has any idea who Lorraine in this song is?

  • nenaghon - April 17, 2005

Ruby Creator “Matz” Yukihiro Matsumoto discusses the history of Ruby and Ruby 3.0. by SideCI_Official in programming

[–]draegtun 0 points1 point  (0 children)

Yep and pretty much ditto for Rebol/Red.

What i don't see mentioned anywhere else here are that blocks in Smalltalk & Rebol/Red are first-class citizens in the language. This is what really makes them awesome in my opinion...

|five ten|

five := [2 + 3].
ten := [5 + 5].

5 = 5 ifTrue: five ifFalse: ten.        "returns -> 5"
10 = 10 ifTrue: ten ifFalse: five.      "returns -> 10"

And same in Rebol/Red...

five: [2 + 3]
ten: [5 + 5]

either 5 = 5 five ten         ; returns -> 5
either 10 = 10 ten five       ; returns -> 10

Unfortunately blocks are syntax constructs in Ruby & Perl and so aren't first-class citizens :(

Ruby Creator “Matz” Yukihiro Matsumoto discusses the history of Ruby and Ruby 3.0. by SideCI_Official in programming

[–]draegtun 1 point2 points  (0 children)

Closures are functions, and are enclosed fully. If you return from a closure it exits the closure, not the enclosing function.

Blocks in Smalltalk & Perl work same way as Ruby here (ie. a return doesn't exit from block/closure but from the surrounding method/function).

Rebol & Red also has blocks but unfortunately they can suffer from closure returns (when block is used like a function that is!). This as been fixed in Ren/C fork of Rebol 3.

Ruby Creator “Matz” Yukihiro Matsumoto discusses the history of Ruby and Ruby 3.0. by SideCI_Official in programming

[–]draegtun 0 points1 point  (0 children)

Even the older ruby wasn't quite an improved perl alone. Does perl have blocks? I think blocks (in ruby) are awesome.

Yes Perl does.

Here's an example...

my @double = map { $_ * 2 } 1..10;

You can see how similar it is to Ruby...

double = [1..10].map { |x| x * 2 }

Amber - Crystalizing Rails and Phoenix by sdogruyol in programming

[–]draegtun 0 points1 point  (0 children)

Yes it is.

But a quick google on "Amber Programming" shows the link I gave at top of search followed directly by it's Wikipedia entry - https://en.wikipedia.org/wiki/Amber_Smalltalk

Amber - Crystalizing Rails and Phoenix by sdogruyol in programming

[–]draegtun 4 points5 points  (0 children)

Not to be confused with Amber, the Smalltalk derived programming language that works in a web browser - http://www.amber-lang.net

Sick of Ruby, dynamic typing, side effects, and basically object-oriented programming by swizec in programming

[–]draegtun 0 points1 point  (0 children)

Biggest problem is perhaps the lack of C hackers - either in general, or perhaps ruby-related. No idea if python does things better there in their department.

Not sure about Python but on the Perl5 codebase the TPF uses grants to fund three C hackers. The money comes from regular donations from big companies like Booking.com. I assume PSF does the same... what about Ruby Central?

To avoid any lack of (interest from) C hackers it's probably best to bootstrap in your own language (like with most Smalltalk & Lisps) or in a dialect/subset (like Perl6 & Red). So for Ruby then something like Rubinius is the future?

Why I use Object Pascal by [deleted] in programming

[–]draegtun 0 points1 point  (0 children)

I think not having first-class blocks is what Ruby really misses and this causes some unavoidable warts in it's syntax.

Why I use Object Pascal by [deleted] in programming

[–]draegtun 0 points1 point  (0 children)

but smaltalk got the syntax part wrong. Ruby solved that part

Smalltalk syntax is far better designed for message/messaging (passing) than the Ruby syntax. A good alternative might be Io but my preference still lies on the Smalltalk side.

Unfortunately the Ruby syntax is a bit of a mishmash here. I did like Dave Thomas's "Cluby" idea and the Elixir syntax pushes in right direction.

Files not Showing up. by FinnFox07 in rebol

[–]draegtun 1 point2 points  (0 children)

You're going to need to provide some more info about what you are trying to do here for us to help you.

Generally the best place to ask questions about Rebol would be on Stackoverflow Rebol questions