Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the expression of ABAP mesh in JavaScript and Scala

2025-04-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Today, I will talk to you about the expression of ABAP mesh expression in JavaScript and Scala, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

ABAP Mesh expression

JavaScript

I called the function f on line 10, where the second and third arguments passed in are a comma expression.

The implementation of function f checks the type of these two parameters, if it is a function, executes the function call, and then prints its return value, otherwise the value of the incoming expression is printed directly.

Execute the above code and the printout is as follows:

We can see that although the first parameter passed in is true, causing only the value of the expression represented by the second parameter y to be printed inside the function f, 5, the expression represented by the third parameter is also evaluated when the function f is called, so finally console also outputs Big calculation2.

If we want to implement the so-called "lazy evaluation", sometimes called "lazy evaluation", we only need to wrap the logic originally written in the location of the expression in a JavaScript function, as follows:

When f is called again, the type of the parameters y and z passed in is a function, so when f is called, unlike the previously passed expression, the functions represented by y and z are not immediately called. Printout:

Scala

Scala is a multi-paradigm programming language, which is designed to integrate the features of object-oriented programming and functional programming.

Scala runs on the Java virtual machine and is compatible with existing Java programs.

The Scala source code is compiled into Java bytecode, so it can run on JVM and can call existing Java class libraries.

On lines 5 and 12 below, I define two Scala functions, exp_test1 and exp_test2, respectively, which are logically similar to the previous JavaScript function f.

The second and third parameter types accepted by exp_test1 are exp1: = > Unit, meaning you need to pass in an expression whose return type is Unit.

The second and third parameters received by exp_test2 are of type exp1 (): = > Unit, which means you need to pass in a function that has no input parameters, and the return type of the function is Unit.

Lines 19 to 25 are various tests for these two functions, printout:

As you can see, Scala can lazily evaluate expressions even if the second and third arguments of the two functions exp_test1 and exp_test2 are expressions:

For the function calls on lines 19 and 20, neither the expression nor the function of the third parameter position is evaluated immediately, but lazily.

For the function calls on lines 22 and 23, neither the expression nor the function of the second parameter position is evaluated immediately, but lazily.

After reading the above, do you have any further understanding of the expression of ABAP mesh expression in JavaScript and Scala? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report