What if Lisp were invented by the Japanese?
lispnyc.org
lispnyc.org
(defn japanjure [& e]
(reduce #(if (fn? %2)
(let [[l r & m]%]
(cons (%2 r l) m))
(cons %2 %))[]e))
(japanjure
4 5 +
3 *
print)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).
x |> f = f x (|>) 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 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.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.
"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.
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.
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.
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を 加え 表示する。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.
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....
Although my 6-year son always prefers SVO. He has problems with with variants. He thinks they are "incorrect".
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.
4 5 + 3 * print
Also, Factor was influenced by LISP and Forth among other languages.
https://github.com/raganwald/homoiconic/blob/master/2008-11-...
(((4 5 +) 3 *) print)
((((make-hash-table) table)) let ((table "one" gethash) 1 setf) table)
we'd have: (((4 5 +) 3 *) 打)
((((做井卓) 卓)) 让 ((卓 "一" 拿井)1 放f) 卓)The character you picked for "hash" (井) was cute, but the actual word used in Japanese is "ハッシュ".
You're welcome.
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.
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.
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.
Has anyone actually been able to use all of its built-in functions though?
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. (3 4 2 +)