top | item 2213012

What if Lisp were invented by the Japanese?

71 points| dpapathanasiou | 15 years ago |lispnyc.org

59 comments

order
[+] fogus|15 years ago|reply

    (defn japanjure [& e]
      (reduce #(if (fn? %2)
                 (let [[l r & m]%]
                   (cons (%2 r l) m))
                 (cons %2 %))[]e))
    
    (japanjure 
      4 5 +
      3 *
      print)
[+] T-R|15 years ago|reply
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|15 years ago|reply
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"
[+] sjs|15 years ago|reply
Interesting, in Ruby you don't need to type `self` when calling instance methods within the same class.
[+] PaulHoule|15 years ago|reply
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|15 years ago|reply
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.

[+] blahedo|15 years ago|reply
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|15 years ago|reply
You could simply reverse the order of the arguments to cons.
[+] egor83|15 years ago|reply
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.

[+] phamilton|15 years ago|reply
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.
[+] angus77|15 years ago|reply
In Japanese, you can mix word order freely as well---nouns are marked with particles ("ha" = topic marker; "wo" subject; etc etc). You can think of it as the nouns being declined, but with the declensions being completely regular.

These sentnces all mean the same thing ("Jim ate an apple"): Jim-ha ringo-wo tabeta. Tabeta ringo-wo Jim-ha. Ringo-wo tabeta Jim-ha. Jim-ha tabeta ringo-wo. Ringo-wo Jim-ha tabeta. Tabeta Jim-ha ringo-wo.

However, putting the sentences in a non-SOV order changes which which get emphasized (the same thing happens in Latin and Greek, which were also both verb-final languages by default). The SVO form of the sentence is the most neutral, plainly informative version of the sentence.

[+] jimfl|15 years ago|reply
You mean Urispu?
[+] Confusion|15 years ago|reply
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?
[+] leoc|15 years ago|reply
SUMMARY: Japanese may seem like double Dutch, but it's actually more like reverse Polish. ;)
[+] saurabh|15 years ago|reply
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|15 years ago|reply
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.
[+] pschlump|15 years ago|reply
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|15 years ago|reply
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|15 years ago|reply
How do Japanese mathematicians denote function calls? I suspect that had more direct influence than English grammar.
[+] vorg|15 years ago|reply
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|15 years ago|reply
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.

[+] kenjackson|15 years ago|reply
Isn't what the author describes almost exactly RPN (Reverse Polish Notation) aka postfix?
[+] phamilton|15 years ago|reply
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.

[+] zck|15 years ago|reply
There's no example the author gives that contradicts it, but it's not quite RPN. In Lisp, the + operator is variadic -- it can take any number of arguments. So in reverse-Lisp, this would be legal code:

  (3 4 2 +)
[+] yoshiks|15 years ago|reply
Do we discuss about order? For me it is same if you prefer Method(self param) or X.method(param)...
[+] Pooter|15 years ago|reply
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|15 years ago|reply
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.
[+] carussell|15 years ago|reply
I'm a native English speaker, and I prefer Japanese Lisp.