Some ideas on how to use the Polish style of Lisp

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

I'm not going to use prefix expressions specifically for Lisp to go online and look for articles or books advocating this. I'm not a fan of Lisp, either. Learning Lisp at first is nothing more than learning its great ideas.
But when I slowly learned to Lisp for some time, I slowly from the heart to like it. I'm using scheme, a language for teaching. Of course, for the prefix expression it uses, I'd like to talk about my own knowledge.

First of all: the prefix expression can also be called the Polish style, the suffix expression can also be called inverse Polish style.

In the data structure class, we all know the prefix, infix and suffix expression corresponding to the first order, middle sequence and subsequent traversal of the expression tree. This means that prefixes, infix, and suffix expressions can be converted to each other.


For example:



    • Infix: 1 + 2 + (3 + 4) 5 + 6 + 7

    • Suffix: 1 2 + 3 4 + 5 + 6 + 7 +

    • Prefix: + + + + 1 2 * + 3 4 5 6 7


Many people are very uncomfortable and even disgusted with the prefix expression, because it is not used to, we learn mathematics from childhood, learning basic arithmetic, as if mathematics are used infix expression. Is that really the case?

In fact, not in the arithmetic subtraction outside the world, in fact, are used by the prefix expression, for example, such as the square root √4, which is common in mathematics to find the roots of expression. It is a prefix expression.
The square root is at the front. Of course, the radical is a unary operator, the root of the root is considered a whole, the overall evaluation.

In an example, for example, a lot of people headache points ∫. It is also a prefix expression, and the integral symbol ∫ at the front of each parameter.

Now it seems that the mathematical book is in the prefix expression, we can also adapt, why the programming is not very suitable ...



Of course, the more the pit father is the inverse of the Polish style: for example, Pascal defined variable var x:real;
Or the recent annual language Golang definition variable var x float. (By the way, I've seen Wang Yin's blog before, and it doesn't like the definition variable method of go.)
Everyone is used to defining variable methods such as Double X;

Of course, there are times when dealing with a two-dollar relationship, both Polish-style and inverse-Polish-style are not well understood by infix expressions. Just like our arithmetic, we just treat subtraction as a special arithmetic.
That is, operators that can handle only two-dollar relationships (here is a minus sign instead of a minus-unary operator).

In addition, such as the function f (x. y), this looks like a function f can have more than one parameter. That is, f (int ... a) variable parameter in the C language.

If we think of function f as an operator, it can actually be an operator or it is an operator because it handles the arguments. A function is a method of expressing a prefix.

Because if you don't use a prefix, how do you write an expression? For example, to define the sum of the three parameters of the x, Y, Z, sums (×, y, z), if you use infix how do you write an expression?
(x sum y) sum z this way? This looks like a stop to the pit daddy too. This means that the prefix can support any number of parameters, and infix can only support two. Because after the multivariate relationship, infix is almost nonexistent.
There is no comparable object at all for this representation.

So when dealing with a non-two-tuple relationship, the prefix expression has some advantages. Another point, if the name of the operator longer, put in front will look better. (Hi, Rob.

Of course, the use of prefix expressions can be consistent with the function representation method. This way, it can make a lot of things harmony, unity.

said these, in fact, prefix infix the biggest difference is the two-yuan relationship, if the two-dollar relationship appears more, then use infix expression, if the multi-relationship appears more then use the Polish style.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.