
What if Lisp were invented by the Japanese? - dpapathanasiou
http://lispnyc.org/blog/euske/what-if-lisp-was-invented-by-the-japanese
======
fogus

        (defn japanjure [& e]
          (reduce #(if (fn? %2)
                     (let [[l r & m]%]
                       (cons (%2 r l) m))
                     (cons %2 %))[]e))
        
        (japanjure 
          4 5 +
          3 *
          print)

~~~
sahillavingia
Someone explain?

~~~
T-R
I'm not that familiar with lisp, but it looks like he wrote a macro that
allows functions to be called in postfix

~~~
Hexstream
At the cost (among other things) of not being able to pass functions as
arguments, though that could be worked around.

~~~
fogus
True. Japanjure needs a lot of work before it's enterprise ready.

------
T-R
Japanese is a head-final, strictly left branching language, as linguists might
put it, which means it's structured like postfix.

This would actually let you read code strictly left-to-right (even though
English speakers would be tempted to think of it as right-to-left) - when you
read through functional programs, you end up reading a lot of the code right-
to-left, due to function application, to see the order that code is actually
executed. In postfix, the order objects/functions are written is the order
they're executed.

Continuing along the lines of the post, a more Japanese programming language
would also have named arguments (particles), and if it was object oriented,
you wouldn't need to type 'this'/'self', since subject can be implied by
context (well, it's really the direct object - the computer is the subject).

~~~
overgard
Interesting point with regards to functional programming, although it's worth
pointing out that at least some functional languages have operators that allow
you to do what you're describing. For instance, in F# instead of writing "f x"
you can write "x |> f"

~~~
ionfish
For functions of one argument that's easily enough defined in Haskell.

    
    
        x |> f = f x

~~~
overgard
I don't know Haskell very well, but I assume you're defining an |> function?
If so that's pretty neat. Haskell's flexibility always impresses me. I think
the F# version generally assumes one argument too, though I think you could
use partial function application to work with multiple parameters.

~~~
ionfish
Yes, that's right. Infix function names (anything made of symbols or delimited
by backticks) are allowed on the LHS of a defining equation. An alternative
syntax for this function would be this:

    
    
        (|>) f x = f x
    

The parentheses just serve to denote an infix operator being used in a prefix
way.

A type signature makes this clearer:

    
    
        (|>) :: a -> (a -> b) -> b
    

As you can see, (|>) is a function which accepts an argument of type a, a
function which takes an argument of type a and returns something of type b,
and returns something of type b. In this way it's just a flipped version of
the application operator ($), which has this type:

    
    
        ($) :: (a -> b) -> a -> b

------
PaulHoule
I think the brain is wired in such a way that it can handle different verb
orders without reprogramming. Personally, the verb order in Japanese has never
given me any trouble; combined with the way verb inflection works, I never
have trouble picking out the verbs, even in the written language.

German, on the other hand, has this mechanism where verbs split and wind up
with fragments stacked up the end of the sentence and that, combined with the
need to master grammatical gender to answer questions like "who did what to
whom?" causes me to have a much harder time parsing German, despite the use of
the roman alphabet.

~~~
codebaobab
You can see remnants of separable verbs in English:

"I passed the man in the red hat by." pass-by

"I threw all of my old, useless papers out." throw-out

In the case of pass-by, we still have the verb bypass, but its meaning has
drifted slightly from pass-by.

------
ihodes
Also how it was done in the 50's by Americans. (Arthur Burks, Don Warren and
Jesse Wright[1]).

[1] <http://en.wikipedia.org/wiki/Reverse_Polish_notation>

~~~
idonthack
That had more to do with limited computing power and putting things on a stack
in the right order than it had to do with grammar.

------
blahedo
Cute, but the prefix notation in LISP is not purely aesthetic; it is related
to the fact that lists were stored in a first-rest (car-cdr) pair structure,
and thus function calls (a list including the function itself and all its
arguments) could be broken into the function and its list of arguments, using
mechanisms already present.

I suppose you could then define car-cdr as a last-rest pair, but there are
reasons aside from linguistic ones to want the first of a list to be the
prominent one.

~~~
Miky
You could simply reverse the order of the arguments to cons.

~~~
blahedo
It's more subtle than that, though. Every list has a beginning; not all lists
have ends. If the 'car' semantics are "last item of the list" this is actually
meaningfully different from "first item of the reversed list".

~~~
Miky
It's not meaningful at all. The list would just be constructed entirely from
right to left. The "first" item in a pair would be on the right, and "car"
would just mean "item on the right of a pair", or "first item in a list".

~~~
blahedo
Are you also writing right-to-left, then? If _everything_ about the system is
reflected (including having a reading order of right-to-left), then you're
right, it's not meaningful. But it's also not what's proposed in the OP here.
When the two-dimensional text on the screen is re-formed into a linear string,
it is the right end of line N that is attached to the left end of line N+1,
and so the right-hand arguments of functions are "after" the left-hand
arguments.

------
egor83
_It's fun to speculate the cultural influence on a programming language
design._

There was a story Dijkstra told in his "Discipline of programming" - he gave
his students a task where they had to process a set of items or something like
that; and most did it in left-to-right order.

The only one to work right-to-left was Syrian or Egyptian - i.e. native Arabic
speaker.

------
kazuya
There is a Forth-like programming language that can be programmed entirely in
Japanese.

<http://www.scripts-lab.co.jp/mind/ver7/v7unix_download.html>

Example to add 4 and 5 (from <http://ja.wikipedia.org/wiki/Mind> ):

    
    
      4と　5を　加え　表示する。

~~~
T-R
That is awesome.

Now I know what language to learn once I finish reading "Real World Haskell".
I was gonna go for Factor or Forth, but this absolutely wins.

------
phamilton
What would be interesting is if Lisp were invented by the Greeks. In Greek (I
believe) there is no grammatical ordering. Each part of a sentence is declined
according to what part of speech it is. So a noun is formed differently if
it's an object or if it's a subject. Verbs are readily identifiable as well.
So a sentence can be any of SVO SOV OSV OVS VSO VOS.

~~~
daxelrod
Latin has that structure.

Take a look at Lingua::Romana::Perligata, a Perl module that gives Perl a
latin-style grammar:
<http://search.cpan.org/perldoc?Lingua::Romana::Perligata>

Damian Conway, its author, wrote a paper about it as well:
[http://www.csse.monash.edu.au/~damian/papers/HTML/Perligata....](http://www.csse.monash.edu.au/~damian/papers/HTML/Perligata.html)

~~~
Ingaz
Russian language also allows VSO, SOV, VOS, OVS, OSV - all of combinations is
correct.

Although my 6-year son always prefers SVO. He has problems with with variants.
He thinks they are "incorrect".

------
jimfl
You mean Urispu?

~~~
Confusion
I have no idea what this comment means and it is already the highest Google
hit, with all others not making any sense. Would you please care to elaborate?

~~~
jimfl
It's the roman orthography of the closest sounds in Japanese to the word
"Lisp."

------
leoc
SUMMARY: Japanese may seem like double Dutch, but it's actually more like
reverse Polish. ;)

------
saurabh
The Factor version of (((4 5 +) 3 _) print) would be

4 5 + 3 _* print

<http://factorcode.org/>

Also, Factor was influenced by LISP and Forth among other languages.

~~~
staffandsword
Factor really needs a book or large tutorial as it is one of the coolest
languages out there but you still need to read a forth book or delve deep into
the provided example problems to really get into it.

~~~
raganwald
Start with "To Mock a Mockingbird." One way to think about languages like
Factor and Joy is that they are direct representations of Combinatorial Logic,
just as Lisp and it's descendants are representations of the Lambda Calculus:

[https://github.com/raganwald/homoiconic/blob/master/2008-11-...](https://github.com/raganwald/homoiconic/blob/master/2008-11-16/joy.md)

------
pschlump
It looks a lot like Forth (a RPN language). Many years ago I worked on a
hardware project to build a Forth machine specifically for running ""reversed
lisp"".

~~~
arethuza
Many years ago I had the luck to work on a project that involved me writing a
lot of code in both Lisp and PostScript (another RPN language, although not
one commonly associated with manual code generation) - there is actually quite
a lot that the two environments had in common - particularly the REPL and a
relatively simple set of structural abstractions.

------
philh
How do Japanese mathematicians denote function calls? I suspect that had more
direct influence than English grammar.

------
vorg
If lisp was invented by the Japanese, perhaps instead of:

    
    
      (((4 5 +) 3 *) print)
      ((((make-hash-table) table)) let ((table "one" gethash) 1 setf) table)
    

we'd have:

    
    
      (((4 5 +) 3 *) 打)
      ((((做井卓) 卓)) 让 ((卓 "一" 拿井)1 放f) 卓)

~~~
angus77
I don't think you'd see a Japanese caught dead using one of China's simplified
characters like 让!

The character you picked for "hash" (井) was cute, but the actual word used in
Japanese is "ハッシュ".

You're welcome.

~~~
vorg
I was just trying to make a point with the only N.E.Asian language I know
anything about.

If the Japanese had used 讓 in a programming language, someone somewhere would
have added 让 as an alias, which would have quickly spread. As for 井, it looks
like # , which I call "hash"; again, it might have spread.

~~~
angus77
Tone of voice doesn't translate well into text---I wasn't picking on you. I
was just being a nerd.

But just to be irritating, I don't think anyone would've added the alias, as
inputting a kanji from an IME is as simple as choosing it from a list---and
the one you want (regardless of complexity) is usually the first one on the
list. It would make more sense if the language was handwritten. I heard
somewhere that Donald Knuth writes his software by hand before inputting it,
but I'm pretty sure he's an exception.

------
kenjackson
Isn't what the author describes almost exactly RPN (Reverse Polish Notation)
aka postfix?

~~~
phamilton
Yes. And as an avid HP-50g user, I wouldn't have much problem switching
everything I do to postfix. After you get used to it, everything is a lot
easier.

It is an interesting point the author makes concerning linguistic influence on
using infix notation or prefix notation. Aside from grammar, there is really
no reason to do things that way.

Consider the following sentences:

"Mix 2 eggs with 1 cup flour" (prefix)

"We ate dinner" (infix)

In both cases, the first step is to fetch the operands, being 2 eggs and 1 cup
flour and "we" and dinner. Only after we fetch them can we apply the operator,
to mix and to eat. Both of these sentences are carried out in postfix.

That's the way cpu instructions are executed. The read stage comes before the
execute stage.

~~~
kenjackson
HP 42s user here. A few years ago I went to buy a second one, so went to
EBay... they were going for a few hundred dollars. I bought mine for about $90
new. One of the few pieces of electronics that seems to have gone up in price.

~~~
alown
Another HP50g user here. My friends disliked the RPN mode for the first few
weeks (they couldn't borrow my calculator), but even they got used to it
within 10 minutes of button mashing and errors.

Has anyone actually been able to use all of its built-in functions though?

------
mixmax
Then it might look a bit like ruby, designed by this Japanese fella:
<http://en.wikipedia.org/wiki/Yukihiro_Matsumoto>

------
leoc
Similar: [http://metamerist.blogspot.com/2007/02/alan-kay-
oopsla-1997....](http://metamerist.blogspot.com/2007/02/alan-kay-
oopsla-1997.html)

------
yoshiks
Do we discuss about order? For me it is same if you prefer Method(self param)
or X.method(param)...

------
Pooter
It's worth pointing out that the default word order of English is SVO, and not
VOS/VSO like the "word" order of LISP. Perhaps, John McCarthy is a native
speaker of Malagasy?

~~~
Vivtek
Given that imperative sentences in English map onto function calls rather
well, and also have an understood subject, I think Malagasy is an unnecessary
assumption.

