Hacker Timesnew | past | comments | ask | show | jobs | submitlogin
What if Lisp were invented by the Japanese? (lispnyc.org)
71 points by dpapathanasiou on Feb 13, 2011 | hide | past | favorite | 59 comments


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


Someone explain?


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


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


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


my pedantry for the day: this isn't a macro.


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).


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"


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

    x |> f = f x


I was just thinking about that. You have to do it by hacking the infix syntactic sugar.

    x |> f = f x
gives you lambda calculus, but it gets ugly, since you need to specify order of operations with parentheses.

    (4 |> (5 |> (+))) |> (3 |> (*))
You can take it a step further with tuples, but you still need to be explicit about the number of arguments:

    (x,y) |> f = f x y
    ((4,5) |> (+), 3) |> (*)
Maybe you could go almost all the way by telling it to create a List when passed two values, and telling it apply to the (nested) List when called with a List and an operator, but off hand, I can't think of a way to get it to type check, particularly not without killing currying.


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.


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


Interesting, in Ruby you don't need to type `self` when calling instance methods within the same class.


IIRC this is also the case with Java


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.


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.


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


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.


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.


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


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".


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".


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.


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.


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を 加え 表示する。


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.


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.


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....


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".


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.


You mean Urispu?


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?


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


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


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.


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.


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-...


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"".


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.


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


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) 卓)


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.


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.


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.


You should write some entries for kanjidamage.


I'd never seen that site before. Too bad it wasn't around back in the Web 1.0 days---could've saved some headaches!


What's great about it is that it's fun to read through the jukugo descriptions even if you don't plan to learn Japanese.


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


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.


> using infix notation or prefix notation. Aside from grammar, there is really no reason to do things that way.

Even grammar isn't a reason to do things that way. In English:

  "2 eggs with 1 cup of flour are to be mixed" =passive (postfix)

  "Dinner we ate" =topic fronting (postfix)
Subject, verb, & object are a feature of the grammatical (transitive) structure of English. The order the nouns are introduced is a feature of the thematic structure. They're orthogonal to each other (though some combinations are less common than others). English lets us mix the two structures any way we want.


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.


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?


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 +)


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



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


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?


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.


I'm a native English speaker, and I prefer Japanese Lisp.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: