9

I ran into Rebol and I was wondering about it.

I ran into the following script from here:

 use [feed questions answers][
    feed: load-xml/dom http://stackoverflow.com/feeds/tag/rebol
    questions: map-each entry feed/get-by-tag <entry> [
        find/match entry/get <id> "http://stackoverflow.com/q/"
    ]

    answers: make block! length? questions

    foreach question questions [
        question: load-xml/dom join http://stackoverflow.com/feeds/question/ question
        foreach entry next question/get-by-tag <entry> [append answers entry/tree]
    ]

    insert clear feed/find-element <entry> answers
    feed/flatten
 ]

All the collection manipulation operations like map-each remind me of JavaScript and C# both of which have functional abilities.

Is Rebol a functional language? Does it support functional programming? Would it classify as a pure functional language (PFL)?

3
  • 6
    Here's an answer from the creator of REBOL: Is REBOL a Pure Functional Language? Commented Feb 21, 2013 at 2:15
  • 1
    @GregHewgill Thank you for that resource. I asked this question after a chat in the StackOverflow Rebol chat room (chat.stackoverflow.com/transcript/message/7836761#7836761) . They (We) figured that since there is no information about this on programmers or other sites in StackExchange I should ask it here for future reference. That link is great but it could be expanded and explained here so more users who are not experienced Rebol programmers could understand it. An answer with citations from that article and personal development experience would be appreciated. Commented Feb 21, 2013 at 2:20
  • Attributes barely improve Carl's XML scenario: you still have excess metadata (the attribute names) and untyped values (the attribute content). Rebol's implicit metadata provided by the carefully defined of types removes a fair burden on interpretation. With XML, you have to first unlock values, then decipher them (how is a date defined in XML—shall I check the RSS or Atom spec? Can you express the definition in XML?), and then possibly validate them, only then you can evaluate their context. **Intended as a comment in response to [this comment](programmers.stackexchange.com/questions/1
    – user82082
    Commented Feb 21, 2013 at 10:01

1 Answer 1

13

"Pure Functional Programming" in its formal definition is about the idea of designing computational machines whose output is purely "a function of the input to the machine". If you feed the same input into the machine, it will produce the same output. Each input is named explicitly so you know precisely what the dependencies are. A pure functional programming language enforces this rigorously.

Yet... in baseline "Rebol" you can write things like:

foo: function [value [integer!]] [
    either now/date = 20-Feb-2013 [
        value + 1
    ] [
        value
    ]
]

Here we see a function that returns its integer input on every day but today, where you get the value plus one. It includes an invisible dependency on the date which is not formally specified as an argument to the function. It's the sort of thing that makes Haskell people and software formalists like myself scream bloody murder.

Hence Rebol is not pure functional out of the box. (...but read on...)

The less strict definition of functional programming is when functions can act as values in the language. So you can assign a function to a variable, and use it later. In that sense, you can go read the likes of is javascript a functional language and see that the dicey definition would lead some people to say Javascript is a functional language. If you're going to be that loose with the definition then this would be "functional":

>> foo: does [a + 10]

>> a: 20

>> print foo
== 30

(Note: DOES is a convenience for defining a function with no arguments, that has only a body.)

I don't know that I'd consider that (or JavaScript) to fit what people I talk to would call functional programming. YMMV.

If you spend any time in computer science you learn about things like Turing Tarpits and computability and these sort of principles of equivalences where "if you can connect X to Y then Z will be true". And just as you can write a Haskell implementation in C, and then restrict yourself to only using C calls mapped into the Haskell library, you might claim you're doing "functional programming" and be technically correct.

So if you wanted to say Rebol can be bent to functional programming styles, you might be a pessimist and say "well it's no better than pretending you're doing C when you're actually using such a confined subset of the language that you're using Haskell by proxy". The trick up Rebol's sleeve is how easily you slip from one "dialecting" paradigm to another. Writing a little domain-specific-language that happens to be functional is so easy and natural that it doesn't feel like you're twisting your language out of joint to do it. The ability to make domain specific languages that have functional character leads to the labeling of Rebol as "paradigm neutral".

Many people mix up Rebol with its most common dialect (the DO dialect) and think "that's what Rebol is". But Rebol's "essence" is more like XML, it's a data exchange format that coincidentally (okay, not coincidentally) has hyper-optimized code focusing on processing it in some certain ways out of the box. For a good background reading on how it beats the pants off XML, see Was XML flawed from the Start by Carl Sassenrath of AmigaOS (and now Rebol) fame.

4
  • 1
    That's a great answer but I think the "Was XML flawed from the start" article is pretty bad. First, he uses poor XML (everything he represents with nesting can be represented with attributes). Second, languages are represented by a tree like structure that resembles xml. When you parse a sentence you get a parse tree, it's not fair to compare the XML which contains the grammer information with the string that is domain specific. Thanks for the answer :) Commented Feb 21, 2013 at 5:31
  • 2
    I am a Rebol n00b and as you have said, I too am thinking as of now that Rebol is what the DO dialect is. Hope to break out of this mindset. :-)
    – KK.
    Commented Feb 21, 2013 at 5:45
  • 1
    @BenjaminGruenbaum If I could edit Carl's website, believe me, I would. :-) Commented Feb 21, 2013 at 5:58
  • @BenjaminGruenbaum But not all languages can freely manipulate that tree structure. Rebol is very lisp-y in that regard.
    – Izkata
    Commented Jan 17, 2014 at 0:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.