
Joy (Programming Language) - reedwolf
https://en.wikipedia.org/wiki/Joy_(programming_language)
======
nivertech
It's a functional programming language where every function is of type stack
-> stack.

I like concatenative languages[1] and especially pipelines[2], but IMO Forth-
like stack-oriented languages are in the wrong direction, b/c they force
programmer to manipulate arguments on a stack, which feels hackish.

And my first real physical computer was an RPN calculator. As a kid I wrote
lots of programs for it.

Also b/c of their simple implementation, Forth-s and stack-based VMs are
frequently used in the wrong domains, i.e. Bitcoin's Scripts and Ethereum's
EVM.

APL-family languages are better in this regard, but they also feel hackish in
the general case, especially when passing arguments to nested functions.
Copying RTL-style from math notation is also wrong. You are typing LTR (at
least in English), but the expressions are evaluated RTL. Here Forth, RPN, and
UNIX pipelines got it right.

The interesting direction would be a programming language with following
attributes:

    
    
      - Purely-functional
      - Statically typed with an algebraic type system
      - Concatenative [1]
      - Tacit / Pipelines [2]
      - Homoiconic
      - top-to-bottom, LTR
    

[1]
[https://en.wikipedia.org/wiki/Concatenative_programming_lang...](https://en.wikipedia.org/wiki/Concatenative_programming_language)

[2]
[https://en.wikipedia.org/wiki/Tacit_programming](https://en.wikipedia.org/wiki/Tacit_programming)

~~~
vanderZwan
I think your list basically describes
[http://kittenlang.org/](http://kittenlang.org/) which sadly has kind of
halted in development because the sole dev working on it couldn't get anyone
else on-board. Probably because it occupies a pretty rare niche of computer
science interests.

~~~
nivertech
any relation to Cat [1]?

[1] [https://web.archive.org/web/20150205081218/http://cat-
langua...](https://web.archive.org/web/20150205081218/http://cat-
language.com/manual.html)

~~~
vanderZwan
It's a direct inspiration - hence the name ;)

------
toolslive
Joy is great (at least better than SQL) as an API to a database. IE, every
query is a joy program. If you add get, set and (de)serialize as primitives,
you have stored procedures, intermediate results, galore! Want to transform
your result before you send it back to the client ? no problem, just add a
transformer function.

~~~
mafm
Can you add a link pointing at some examples?

~~~
toolslive
there's a bunch of research related to 'stack based query languages' google
for SBQL.

Anyway, in the specific case of joy is more difficult to dig up. Here's an
example (I know it, because I implemented it):
[https://github.com/openvstorage/arakoon/blob/lsl/src/system/...](https://github.com/openvstorage/arakoon/blob/lsl/src/system/single.ml#L416)

    
    
        "script1_" true 
        "script2_" false
        0
        [POP; 1; ADD] 
        FOLD_RANGE
    

The above program has basically calculates the number of keys between
"script1_" inclusive and "script2_" exclusive. It's really compact flexible
and powerful.

Now, before you run off and think about implementing this yourself. First have
a look at kitten: [https://kittenlang.org/](https://kittenlang.org/)

------
reedwolf
Example from C2[0]:

    
    
      (* x y percent approxEqual *)
      DEFINE approxEqual == 100.0 / rotate [0 =] [pop] [dup rolldown -   
      swap /] ifte > 
    

[0] [https://wiki.c2.com/?JoyLanguage](https://wiki.c2.com/?JoyLanguage)

------
vincnetas
"In Joy, everything is a function that takes a stack as an argument and
returns a stack as a result. "

But formal parameters are same things[1]. It's just a values pushed to stack
before calling a function and values poped from stack on return. That's why
you get stackoverflow exceptions in java when your recursion fails.

EDIT: [1]most of the time, in situations that i know about.

~~~
boomlinde
The difference is that in one case it's an implementation detail covered by an
abstraction to make that fact irrelevant to the programmer, and in the other
the language is fundamentally designed around the idea that the stack itself
is exposed as a data structure to the programmer.

If you don't understand how the difference is significant, I suggest trying a
language like Joy, Factor or Forth.

~~~
vincnetas

      class Fun implements Function<Stack, Stack> {
      
        public Stack apply(Stack s) {
          return s;
        }
    
      }
    

So this is Joy in Java. But as my neighbor comment asks. How does this
benefits a language as tool for humans to get job done (c). From my
perspective it only brings you down the abstractions ladder.

~~~
astrobe_
Climbing the abstraction ladder does not lead to Heaven. Rather to Noah's ark,
according to the law of leaky abstractions.

Java has this reputation of being a lot of boilerplate code, and indeed when
you compare it to Forth code this is striking. For instance this is the code
to square the top of stack:

: square dup * ;

I don't know much about Java, but I guess it something like:

Stack apply(Stack s) { int tos=s.pop(); s.push(tos*tos); return s; }

Of course this is not fair at all because Forth has no type checking, no OO
and gets its terseness from the point-free style that stack-orientation
allows.

But this example is symbolic of one thing: Java needs a lot of baggage to be
viable. A state-of-the-art GC. A state-of-the-art JIT. A complex lexer/parser.
A mildly efficient Forth interpreter/compiler can be written by one teenager.

If your job is to get some sort of interpreter running on a brand new
hardware, then Forth is probably the fastest way to get that job done. Chuck
Moore, the creator of Forth, has funded a company on this - company that is
now more than forty years old.

This extends to more common use cases. As most processors come on the market
with a C compiler, if you have a Forth interpreter written in C, you can have
it running right away. Even before you have an OS for it.

But you can benefit from the OS and the large number of C libraries too.
Writing library bindings for a Forth system is often trivial; the hardest part
is to decide how the API should look like on the Forth side (often library
APIs are too rich and you want to only expose the useful subset for you).

So "stack-oriented programming" leads to simple interpreters and compilers,
which in turns gives a lot of flexibility, which is very valuable to get
things done.

~~~
cdcarter
Thank you for this! You concisely answered the question I kept having
throughout the wikipedia page and these threads. Obviously there's a world in
which stack programming lets you be productive, its flourished, but what is
that environment? Bootstrapping, new hardware, working at pre-OS levels, these
are all places I don't have to think very much about, so I appreciate the
reminder and context for why Forth is powerful there.

------
carapace
I've been working with Joy for several years now, on an off, in a hobbyist
way, and I've got to say, I think it's the most useful, simplest language.

(I've made implementations in Python and Prolog
[https://joypy.osdn.io/](https://joypy.osdn.io/) )

------
Gormisdomai
The coolest part of this article imo is the binrec operator. Do other
languages have something similar?

------
amelius
From many viewpoints a stack is a nuisance, for example memory management and
context switching. Therefore I think that languages which use a stack are
going in the wrong direction.

------
kalium-xyz
Michelson language has distinctly ruined my taste for language like this.

------
co_dh
The point of Forth/Joy is that the language is so simple, you don't need
compiler. It is a minimum language.

------
jayp1418
I still find ada language more advanced than current ones

~~~
oddity
What do you mean? They’re different branches on the tech tree. Saying one is
more advanced than the other is strange.

------
ngcc_hk
Very confusing as just have another Joy web framework. For this kind of new
language, one may have to have a kind of FAQ for the reason why it exists at
all. Why not just FORTH?

~~~
yiyus
> Why not just FORTH?

Joy comes from a totally different background, and has a very unique set of
features. The fact that a purely functional point-free programming language
finished looked quite similar to Forth in some aspects was just an accident (a
happy accident, imo).

