vlang trial

vlang is recently out of a programming language, integrated rust, characteristics golang, and other languages, lightweight, simple, compile
fast, detailed parity parameters can refer to the official documentation

installation

Despite the current official and a mac linux binaries, but found that running was a little problem, so the best way is to use the source code to compile

  • V source compiler compiler
 
mac:
git clone https://github.com/vlang/v
cd v/compiler
make
linux:
The problem there is a little bit, mainly gcc version, I use centos7, need to use the sc be gcc multiple versions of the process
Installation sc gcc version:
sudo yum install centos-release-scl
sudo yum install devtoolset-7-gcc*
scl enable devtoolset-7 bash
gcc -v
Compile and mac as
git clone https://github.com/vlang/v
cd v/compiler
make

Simple to use

  • Simple code

    hello_world.v

import http
import os
fn main() {
    names := ['Sam', 'Peter']
    printnames(names)
    printenv()
    fetchbaidu ()
}
// for each demo
fn printnames(n []string) {
     for item in n {
         println(item)
     }
}
// os env
fn printenv(){
    println(os.getenv('USERNAME'))
}
// http demo
, fn Fetchbaidu () {
    resp := http.get('https://www.baidu.com')
    println(resp)
}
// function demo
fn printusername(n string) {
    println(n)
}
 
  • Code Description
    above code contains a simple http, env, function, array code, the code can be seen from the above is very clear
  • && run the compiler
    actually run there will be a compiled binary file to run the command
    v run hello_world.v
    results:
 
in the run hello_world. in
============running hello_world==============================
Sam
Peter
dalong
<!DOCTYPE html><!--STATUS OK-->
<html>
<head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">
        <link rel="dns-prefetch" href="//s1.bdstatic.com"/>
        <link rel="dns-prefetch" href="//t1.baidu.com"/>
        <link rel="dns-prefetch" href="//t2.baidu.com"/>
        <link rel="dns-prefetch" href="//t3.baidu.com"/>
        <link rel="dns-prefetch" href="//t10.baidu.com"/>
        <link rel="dns-prefetch" href="//t11.baidu.com"/>
        <link rel="dns-prefetch" href="//t12.baidu.com"/>
        <link rel="dns-prefetch" href="//b1.bdstatic.com"/>
.....
 
 

Production generate binary files:
v -prod hello_world.v

Explanation

v has a lot of built-in optional module json http ui, basically enough, and supported data types is more, has its own module concept (similar to rust)
look behind the development, expectations on the ide, warehouse module It has been raised, there is the language to build cross-platform (currently looking at test or not supported, although official documentation
described).

Reference material

https://vlang.io/#faq
https://github.com/vlang/v

Guess you like

Origin www.cnblogs.com/rongfengliang/p/11102465.html