Paste: defined

Author: goren
Mode: markdown
Date: Sun, 7 Jan 2024 23:53:22
Plain Text |
# Table of Contents

1.  [concatenative programming language *noun* \*](#org0577a9a)
        1.  [GLOBAL STRUCTURE](#orgfab2a69)
        2.  [FUNCTION COMPOSITION SYNTAX](#org3676fcb)

<a id="org0577a9a"></a>

# concatenative programming language *noun* \*

*see also: catlang*

<a id="orgfab2a69"></a>


In an applicative language (opposite of
concatenative) functions are constructed
with a set of parameters, which are later
referenced with specific words throughout
the function.


    In the following example in the Python
    programming language (an applicative
    language), you can see the we are
    defining a function called adder
    which takes two parameters, a and b.
    It returns the product of a + b by
    referring to them.
        def adder(a, b):
            return a + b
    In a concatenative programming language
    instead of functions taking parameters,
    functions take data and pass data through
    *one global structure*.


    In this example in the Forth programming
    language, a flexible language that can
    boast being *the first* stack-based
    language, we can see that we are
    defining an adder, but without all
    of the added, un-required words.
    This makes for a much nicer,
    smaller function.
        : adder + ;
    To call this adder, and add two
    numbers (in this example
    twelve and twelve) we could do
    the following:
        12 12 adder
    This is equivalent to:
        12 12 +
    Putting the operator after the numbers
    is called Reverse Polish Notation or
    postfix notation.
    This semantically does exactly what
    it says, making Reverse Polish Notation
    quite useful.
    The example program will push 12 to our
    global structure (the stack) and then
    push 12 again, and then pop them
    both from the stack and push their

<a id="org3676fcb"></a>


While this part is not absolutely required,
it is strongly considered when asking
yourself whether a language is

Syntactically, in **most** concatenative
languages, whitespace (concatenation)
indicates the composition of two

Function composition if creating a
function f∘g(x), where
x represents the global data
structure (probably the stack)
results in f(g(x)).

In a concatenative programming
language, this process is every time
you use a space to seperate two

Take this example in the Factor
programming language:

    10 10 + 2 * number>string print

This will print 40 to the console,
by adding 10 and 10, resulting in
20, and then multiplying that
by two.

This then converts the number 40
into a string ("40"). It then
prints the number to the console,
ending up in 40 being printed.

*NOTE: yes, i know about the . word, just wanted to use as many words as possible.*

This composes the function print,
number>string, \*, and +, ending
up in the perfect combination
of functions that will create our
desired result (40 being printed
to the console).

New Annotation