- Opa Application Development
- Li Wenbo
- 235字
- 2021-08-20 16:49:38
Functions
Opa is a functional language. One of its features is that functions are regular values, which means a function may be passed as a parameter or returned as a result. As such, they follow the same naming rules as any other value.
function f(x,y){ // function f with the two parameters x and y x + y + 1 } function int f(x,y){ // explicitly indicates the return type x + y + 1 }
Last expression return
You may notice that there is no return inside the body of a function. That's because Opa uses last expression return, which means the last expression of a function is the return value. For example:
function max(x,y){ if(x >= y) x else y }
If x
is greater than or equal to y
, then x
is the last expression and x
will be returned; if y
is greater than x
, then y
is the last expression and y
will be returned.
Modules
Functionalities are usually regrouped into modules; for example:
module M { x = 1 y = x function test(){ jlog("testing") } }
We can access the content of a module by using the dot operator (.
); for instance, M.x
, M.y
, and M.test
. Actually, the content of a module is not field definitions, but bindings. In this example, we bind integer 1
to variable x
, and bind the value of variable x
to variable y
.
- Oracle從入門到精通(第3版)
- C語(yǔ)言程序設(shè)計(jì)教程
- Android 7編程入門經(jīng)典:使用Android Studio 2(第4版)
- 深度學(xué)習(xí):算法入門與Keras編程實(shí)踐
- PySide GUI Application Development(Second Edition)
- FLL+WRO樂(lè)高機(jī)器人競(jìng)賽教程:機(jī)械、巡線與PID
- TypeScript項(xiàng)目開(kāi)發(fā)實(shí)戰(zhàn)
- 零基礎(chǔ)Java學(xué)習(xí)筆記
- Building Wireless Sensor Networks Using Arduino
- 青少年學(xué)Python(第2冊(cè))
- Kotlin進(jìn)階實(shí)戰(zhàn)
- C/C++代碼調(diào)試的藝術(shù)
- PHP從入門到精通(微視頻精編版)
- C++程序設(shè)計(jì)習(xí)題與實(shí)驗(yàn)指導(dǎo)
- D Cookbook