# Another Concatenative Language -- dc

## Jack Waugh — 2001-08-06 00:32:40

    On any Unix-like system, do a "man dc".  'dc' (desk calculator) has a

    stack and a namespace (with only single-character names).  A single

    character denotes each function (for example, + adds the top two

    stack elements and replaces them with the result; d duplicates the

    top element; p prints the top element without consuming it; x

    executes the top element as a program).  Quoting character strings

    suffices to quote code.  There are combinators.  Arithmetic runs to

    arbitrary precision.  dc is not as purely functional as Joy (ignoring

    I/O) is, because of the namespace operators.  In fact the only way to

    pop the top element and discard it is to store it under a name (I

    use "g" for garbage, so the function is "sg", store in garbage) (I

    lied about functions being always denoted by just one character;

    the "store" and "load" functions take two characters: "s" or "l"

    followed by the name of the cell in the namespace).

## Manfred von Thun — 2001-08-06 02:06:35

    On Mon, 6 Aug 2001, Jack Waugh wrote:

     > On any Unix-like system, do a "man dc".  'dc' (desk calculator) has a

    > stack and a namespace (with only single-character names).  A single

    > character denotes each function (for example, + adds the top two

    > stack elements and replaces them with the result; d duplicates the

    > top element;

     You are right, I had forgotten about dc's dup operator d.

    So what I wrote on the Joy FAQ just three days ago is wrong:

    According to the definition I use there,

    dc is not postfix but concatenative. I'll amend the FAQ.

     > p prints the top element without consuming it; x

    > executes the top element as a program).  Quoting character strings

    > suffices to quote code.  There are combinators.  Arithmetic runs to

    > arbitrary precision.  dc is not as purely functional as Joy (ignoring

    > I/O) is, because of the namespace operators.  In fact the only way to

    > pop the top element and discard it is to store it under a name (I

    > use "g" for garbage, so the function is "sg", store in garbage)

     Indeed, so we have dup and pop

     > (I

    > lied about functions being always denoted by just one character;

    > the "store" and "load" functions take two characters: "s" or "l"

    > followed by the name of the cell in the namespace).

     And swap can be done by  sa sb  la lb

    So the three principal stack operators can be effected in dc

    Thanks for pointing it out.

    Being envious of the infinite precision in dc (and bc),

    some time ago I even considered having a Joy package which

    uses dc to do the hard work, hidden away from the user by an

    invisible "system" call. But I rejected the idea for the time being.

    Maybe somebody should look at it again.

      - Manfred

## John Cowan — 2001-08-06 03:31:48

    Manfred von Thun scripsit:

     > Being envious of the infinite precision in dc (and bc),

    > some time ago I even considered having a Joy package which

    > uses dc to do the hard work, hidden away from the user by an

    > invisible "system" call. But I rejected the idea for the time being.

    > Maybe somebody should look at it again.

     There are arbitrary-precision packages written in C.  I'll look into

    this at some point, though bignums aren't something which really

    fascinate me.

    --

    John Cowan                                   cowan@...

    One art/there is/no less/no more/All things/to do/with sparks/galore

    	--Douglas Hofstadter

## John Carter — 2001-08-06 03:53:25

    On Mon, 6 Aug 2001, Jack Waugh wrote:

     > On any Unix-like system, do a "man dc".

     In that realm is the Hp48 calculators RPL (Reverse Polish Lisp).

    In the opposite realm there is a converter that translates a lispish

    version of postscript into ordinary postscript!

    Hp48 RPL was what got me interested in postfix based languages in the

    first place.

    I suddenly realised, while programming my calculator, that the huge fuss

    made about syntax is totally irrelevant compared to the semantics. ie. A

    postfix language is almost syntaxless, all you need is a lexical scanner,

    no parser needed.

    Unfortunately Computer Science departments have given a generation of

    students an obsessive fixation of syntax and parsers and parser

    generators. All that effort and thought has been misdirected.

    What would have happened if all that creativity had been expended on the

    semantics instead of increasingly complex syntaxes that render reflection

    impossible....

    John Carter                             Phone : (64)(3) 358 6639

    Tait Electronics                        Fax   : (64)(3) 359 4632

    PO Box 1645 Christchurch                Email : john.carter@...

    New Zealand

    I'm becoming less and less convinced of humans as rational beings.

    I suspect we are merely meme collectors, and the reason meme is only

    kept on to help count our change.

## Jack Waugh — 2001-08-06 16:24:04

    Oops; dc doesn't have a string concatenation operator.  It provides

    no programmatic way to build programs.

    In fact, there seem to be no ways to build any kind of aggregate,

    unless the : and ; operators do something like that (the doc says dc

    provides them for bc's array operations but doesn't say what they do).

    dc's program quoting has the same syntax as that of Joy: square

    brackets (Smalltalk and Self also quote code with square brackets).

    Too bad there's no cons.

## Manfred von Thun — 2001-08-07 00:15:10

    On Sun, 5 Aug 2001, John Cowan wrote:

     > There are arbitrary-precision packages written in C.  I'll look into

    > this at some point, though bignums aren't something which really

    > fascinate me.

     Thanks.

    No urgency at all, I think. There is also the possibility that

    those packages are not widely portable, but I do not know

    anything about them.

      - Manfred

## Manfred von Thun — 2001-08-07 00:39:37

    On Mon, 6 Aug 2001, John Carter wrote:

    [deletions]

    > Hp48 RPL was what got me interested in postfix based languages in the

    > first place.

    >

    > I suddenly realised, while programming my calculator, that the huge fuss

    > made about syntax is totally irrelevant compared to the semantics. ie. A

    > postfix language is almost syntaxless, all you need is a lexical scanner,

    > no parser needed.

    >

    > Unfortunately Computer Science departments have given a generation of

    > students an obsessive fixation of syntax and parsers and parser

    > generators. All that effort and thought has been misdirected.

    Agree, at least in part. I consider myself fortunate in having only

    very few books (on Pascal) in my early days. One was the Jensen-Wirth

    Pascal manual, the other Wirth's Algorithms + Data Structures = Programs,

    the first, 1976 edition which had PLZERO. I learnt all about recursive

    descent parsing and would always design a language so that this is

    possible, especially the ease of error reporting and recovery.

    But I do think that the idea of syntax directed parsing and translating

    is something everyone should learn, and looking inside the various

    Pascal compilers (PL0, PascalS, P4) is useful.

    > What would have happened if all that creativity had been expended on the

    > semantics instead of increasingly complex syntaxes that render reflection

    > impossible....

    After some experience with Pascal I did study Lisp a bit, I think it

    was Anatomy of Lisp or something like that. Yes, Program = Data,

    wonderful stuff. Joy eventuated essentially out of that..

      - Manfred

## Manfred von Thun — 2001-08-07 01:35:19

    On Mon, 6 Aug 2001, Jack Waugh wrote:

     > Oops; dc doesn't have a string concatenation operator.  It provides

    > no programmatic way to build programs.

     The "Oops" leads me to think that you have this argument in mind:

         dc  does not have a concatenation operator

         ---

         therefore, dc is not a concatenative language

    If this is what you meant, then read on, else ignore:

    The way I define things is this:

      A language is concatenative iff

        for all programs  P and  Q

          if P denotes a function F and Q denotes a function G,

          then their concatenation  P Q  denotes the composition of F and G

    This is quite independent of what sort of data structures

    the language provides. It may have just integers and nothing else.

    If it also has quoted programs, used by combinators, then

    a concatenation operation would be useful because it makes

    the language reflective. But the concatenation operation

    _in_the_language_ is not a defining characteristic of concatenative

    languages.

      - Manfred

## Manfred von Thun — 2001-08-08 05:08:27

    Unfortunately I lost the original mail with the question from John Carter:

      Why is == an infix operator?

    The question has been raised before, including at least once on this

    mailing group. Since it recurs, I should really start another

    "Further Frequently Asked Questions", and I'll make that question

    a priority. But it will take at least a week, I'm a little snowed

    under. Sorry.

    I was able to read the details of your question by looking back

    at yahoo's archive. The way postfix does it sounds interesting.

    But I would like to see some examples of where those extra

    facilities are really useful.

      - Manfred

## waugh@acm.org — 2001-08-08 13:17:08

    > Unfortunately I lost the original mail with the question from John

     Carter:

    . . .

    Loosing "mail" that came through this forum need never be a problem.

    Just go to the message archive.  In fact, I recommend not receiving

    mail.  The message archive resides at

    http://groups.yahoo.com/group/concatenative/messages