MaxCloud User Docs
演示登录
  • Welcome
    • 介绍
    • 快速开始
  • 使用说明
    • 集群管理
      • 导入集群
      • 创建集群
      • 关联授权
      • 集群功能
    • 项目管理
      • 事件订阅
    • 应用管理
      • 创建应用
      • 灰度发布
      • 持续集成
  • 客户端工具
    • kubemax
    • kubectl
    • 自定义客户端
  • MrMax
    • MrMax客户端使用指南
    • Cybercore
    • SDK Release Version
  • 开发者指南
    • MaxLang语言基础
    • MaxLang内置方法
    • MaxLang操作资源示例
  • 社区活动
    • 技术交流
      • 2023/05/28 亚马逊云科技 Community Day 深圳站
    • 技术文章
      • 2023.5 记一次EKS 1.22->1.26 升级
      • 2023.8 创建EKS后要关注的几个事情
    • Kubernetes Workshop
      • 基础篇
        • Docker学习环境
        • 开始使用Docker
        • 开始使用Kubernetes
      • 实战篇
        • Pod:运行于Kubernetes中的容器
        • ReplicationController:部署托管的pods
        • Service:让客户端发现pod并与之通信
        • Volumes:给containers挂载磁盘
        • ConfigMap和Secret:配置应用程序
        • Deployment: 声明式地升级应用
        • StatefulSet:部署有状态的多副本应用
      • 实践篇
        • Helm Charts(上)
          • 什么是Helm和Chart?
          • 使用Helm
        • Helm Charts(中)
          • 创建自己的chart
          • Chart模版构造和语法
          • 使用仓库管理chart
        • Helm Charts(下)
          • 一个实际的项目
          • 最后,Helm不是必须的
        • 持续集成(Gitops)
由 GitBook 提供支持
在本页
  • -- All New Design, All For DevOps
  • Primitive Data Types
  • Number
  • String
  • Boolean
  • Function
  • Statements
  • Conditional statement
  • Loop statement
  • Collections
  • Array
  • HashTable
  • Built-in functions
  • MaxLang is growing fast, still more to come!

这有帮助吗?

  1. 开发者指南

MaxLang语言基础

-- All New Design, All For DevOps

MaxLang is the dedicated programming language for automating the DevOps tasks, which is implemented and maintained by MaxCloud team.

Primitive Data Types

Number

In Maxlang, it is not necessary to distinguish the numerical value's type, such as integer and float. Maxlang can recoginze and convert values automatically.

a = 11
b = 100
a + b
a = 10
b = 1.2
a + b

String

A string value is quoted by " or ` .

a = "Hello World"
a
a = `Hello World!
     I love China!`
a
a = "Hello"
b = `World`
a+" "+ b

Boolean

The boolean value is either "true" or "false".

a = true;
a
2 > 3

Function

Function is treated as the basic data type and the first class citizen in Maxlang. If you are familiar with Lisp, you can treat it as the function in Lisp.

In Maxlang, function can be used as the arguments or the return value of other functions.

add = fn(x,y){x+y}
add(1,1)
sub = fn(x,y){
         return x-y;
       }
sub(2,1)

The following example is about how you can implement "Command Patter" (GoF) very easily by leveraging Maxlang's function.

cmdPattern = fn(x, y){y(x)}
cmdPattern(10, fn(x){x*10}) 
cmdPattern(10, fn(x){x/10})

Statements

Conditional statement

The typical conditional statements, "if" and "if-else" are both supported in Maxlang.

if (true) {
    "TRUE"
}else{
    "FALSE"
}

Loop statement

For loop structure, currently, only "while" statement is supported. The "break" and "continue" statements are supported, which can be used in the loop structure to change the execution flow.

i = 1;
sum = 0;
while (i < 10) {
    sum = sum + i;
    i = i + 1
}
sum 
i = 1
sum = 0
while (i<10) {  
    if (i/2 * 2 != i) { /* 2 + 4 + 6 + 8 */
        i = i + 1
        continue
    }
    sum = sum + i
    i = i+1
}
sum

Collections

Array

The elements in an array can be any primitive type object, even a function, also the different type of the elements could be mixed in an array.

The index of an array starts from 0.

myArray = [1,2, fn(x,y){x+y}, "Hello ", "World"]
myArray[2](myArray[0],myArray[1])
myArray[2](myArray[3],myArray[4])

Built-in functions for array

len ( < array > )

Get the number of the elements in the array.

arr = [1,2,3,4,5]
len(arr)

first ( < array > )

Get the first element of the array

first(arr)

last ( < array > )

Get the last element of the array

last(arr)

rest (< array >)

return a new array with removing the first element

rest(arr)

The following example is to travel an array with the built-in functions.

nums = [1,2,3,4,5,6,7,8,9,10]
sum = 0
while(len(nums)>0){
    sum = sum + first(nums)
    nums = rest(nums)
}
sum

HashTable

Like the mainstream programming language, HashTable is the collection of the key-value pairs.

In a key-value pair :

The key can be a primitive object except a function.

The value be a primitive object, a collection or a hashtable.

dic = {1:"one","one":1,"inc":fn(x){x+1}, "arr":[1,2,3,5], "table":{2:"two","sub":fn(x){x-1}}}
dic[1]
dic["inc"](dic["one"])

Built-in functions for Hashtable

keys (< hashtable >)

Get the keys of a hashtable.

keys(dic)

values (< hashtable >)

Get the values of a hashtable

values(dic)

Built-in functions

Conversion

ntos (< number >)

Convert a numeric value to the related string value.

"result = " + ntos(100)
"result = " + ntos(10.19)

ston (< string >)

Convert a string value to the related numeric value.

1 + ston("10")
1 + ston("11.11")

JSON query

For one simple example is more expressive than thousands of the words, I'd like to use several simple examples to explain how the built-in functions work.

json=`{"name":"sam", 
        "skills": { 
                    "coding":["C","Java","php"], 
                     "habits":["eating","sleeping"],
                     "scores":[80,90,100]
                    }
       }`
jpath("skills.coding.[1]", json)
jpath("skills",json)["coding"][2]

MaxLang is growing fast, still more to come!

上一页SDK Release Version下一页MaxLang内置方法

最后更新于1年前

这有帮助吗?