News for hackers. Stuff that matters.
Re:The Joy programming language by dvh on Sunday August 05, 2018 @03:06AM (#17690130)
Quadratic formula in joy:

    DEFINE
    quadratic-3  ==                                # a b c => [root1 root2 ]
        [] cons cons cons                          # list of parameters
        [ [ [ [dup * swap] dip * 4 * - sqrt ]      # radical
            [ pop 0 swap - ]                       # minusb
            [ 2 * ] ]                              # divisor
          [i] map ]
        infra first
        [ [ [ + swap / ]                           # root1
            [ - swap / ] ]                         # root2
          [i] map ]
        infra first.
Re:The Joy programming language by geocar on Sunday August 05, 2018 @04:46AM (#17690385)
That doesn't seem very... joyful.

In q it's just {(q%x),z%q:-.5y+signum[y]sqrt(yy)-4xz}

This is easy to see is correct.

How do you know that Joy is correct?

I'm trying to mentally execute this. I know I haven't seen Joy before, but I've used Forth, Postscript and Lisp, so I feel like I have a lot to stand on:

- cons seems to have the same meaning in lisp, so x y cons -> (x . y) or in Erlangish, [x|y] right?

- x [y] dip seems to be y x

- [x] [y] infra seems to be the same as [x y]

- swap, first, pop, sqrt all seem reasonable

- wouldn't [] cons cons cons dup* be better than the extra list with [i] map ] infra first? it's not really clear to me what [i] map is doing... I see how the values have to flow, but it feels like it should be redundant.

I feel like it's immediately a lot more (mental) work. It reminds me of tracing forth code before I just gave in and started using variables like a normal person.

Is this really the best way to be introduced to Joy? Is this a typical problem that Joy programmers feel is the right way to program (and the right solution?) Am I missing something here?

Re:The Joy programming language by exikyut on Sunday August 05, 2018 @06:10AM (#17690565)
Formatting note:

It will look a bit messier for the

  things*involving*asterisks
to be on their own line (indented two spaces), but that way Arc won't chew them. I'm mentioning this because I can't determine the original text myself.
Re:The Joy programming language by geocar on Sunday August 05, 2018 @06:49AM (#17690677)
Yeah, can't edit now.

    {(q%x),z%q:-.5*y+signum[y]*sqrt(y*y)-4*x*z}
Re:The Joy programming language by mcguire on Sunday August 05, 2018 @11:22AM (#17691750)
I haven't done much with concatenate languages, but a rule of thumb is that if you see a bunch of dips, dups, and swaps, then you are probably doing something wrong. Those should be encapsulated in simple definitions.