Coder Social home page Coder Social logo

vlang / v Goto Github PK

View Code? Open in Web Editor NEW
35.3K 488.0 2.1K 74.16 MB

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io

License: MIT License

Makefile 0.05% Batchfile 0.07% Dockerfile 0.02% C 0.05% V 99.35% HTML 0.05% JavaScript 0.11% Shell 0.01% CSS 0.14% Go 0.01% Python 0.02% Objective-C 0.04% Gnuplot 0.03% Smarty 0.01% C++ 0.01% C# 0.05% Tcl 0.01%
programming-language language v compiler

v's Introduction

V logo

The V Programming Language

vlang.io | Docs | Changelog | Speed | Contributing & compiler design

Sponsor Patreon Discord X Modules

Key Features of V

  • Simplicity: the language can be learned over the course of a weekend
  • Fast compilation: ≈110k loc/s with a Clang backend, ≈500k loc/s with native and tcc backends (Intel i5-7500, SSD, no optimization) (demo video)
  • Easy to develop: V compiles itself in less than a second
  • Performance: as fast as C (V's main backend compiles to human-readable C)
  • Safety: no null, no globals, no undefined behavior (wip), immutability by default
  • C to V translation (Translating DOOM demo video)
  • Hot code reloading
  • Flexible memory management. GC by default, manual via v -gc none, arena allocation via v -prealloc, autofree via v -autofree (autofree demo video).
  • Cross-platform UI library
  • Built-in graphics library
  • Easy cross-compilation
  • REPL
  • Built-in ORM
  • Built-in web framework
  • C and JavaScript backends
  • Great for writing low-level software (Vinix OS)

Stability, future changes, post 1.0 freeze

Despite being at an early development stage, the V language is relatively stable, and doesn't change often. But there will be changes before 1.0. Most changes in the syntax are handled via vfmt automatically.

The V core APIs (primarily the os module) will also have minor changes until they are stabilized in V 1.0. Of course, the APIs will grow after that, but without breaking existing code.

After the 1.0 release V is going to be in the "feature freeze" mode. That means no breaking changes in the language, only bug fixes and performance improvements. Similar to Go.

Will there be V 2.0? Not within a decade after 1.0, perhaps not ever.

To sum it up, unlike many other languages, V is not going to be always changing, with new features introduced and old features modified. It is always going to be a small and simple language, very similar to the way it is right now.

Installing V from source

--> (this is the preferred method)

Linux, macOS, Windows, *BSD, Solaris, WSL, etc.

Usually, installing V is quite simple if you have an environment that already has a functional git installation.

To get started, simply try to execute the following in your terminal/shell:

git clone https://github.com/vlang/v
cd v
make
# HINT: Using Windows? run make.bat in a cmd shell, or ./make.bat in PowerShell

That should be it and you should find your V executable at [path to V repo]/v. [path to V repo] can be anywhere.

(As in the hint above, on Windows make means running make.bat.)

Now you can try ./v run examples/hello_world.v (or v run examples/hello_world.v in cmd shell).

V is constantly being updated. To update V, simply run:

v up

Note

If you run into any trouble, or you have a different operating system or Linux distribution that doesn't install or work immediately, please see Installation Issues and search for your OS and problem.

If you can't find your problem, please add it to an existing discussion if one exists for your OS, or create a new one if a main discussion doesn't yet exist for your OS.

C compiler

The Tiny C Compiler (tcc) is downloaded for you by make if there is a compatible version for your system, and installed under the V thirdparty directory.

This compiler is very fast, but does almost no optimizations. It is best for development builds.

For production builds (using the -prod option to V), it's recommended to use clang, gcc, or Microsoft Visual C++. If you are doing development, you most likely already have one of those installed.

Otherwise, follow these instructions:

Symlinking

Note

It is highly recommended, that you put V on your PATH. That saves you the effort to type in the full path to your v executable every time. V provides a convenience v symlink command to do that more easily.

On Unix systems, it creates a /usr/local/bin/v symlink to your executable. To do that, run:

sudo ./v symlink

On Windows, start a new shell with administrative privileges, for example by pressing the Windows Key, then type cmd.exe, right-click on its menu entry, and choose Run as administrator. In the new administrative shell, cd to the path where you have compiled V, then type:

v symlink

(or ./v symlink in PowerShell)

That will make V available everywhere, by adding it to your PATH. Please restart your shell/editor after that, so that it can pick up the new PATH variable.

Note

There is no need to run v symlink more than once - v will still be available, even after v up, restarts, and so on. You only need to run it again if you decide to move the V repo folder somewhere else.

Void Linux

Expand Void Linux instructions
# xbps-install -Su base-devel
# xbps-install libatomic-devel
$ git clone https://github.com/vlang/v
$ cd v
$ make

Docker

Expand Docker instructions
git clone https://github.com/vlang/v
cd v
docker build -t vlang .
docker run --rm -it vlang:latest

Docker with Alpine/musl

git clone https://github.com/vlang/v
cd v
docker build -t vlang --file=Dockerfile.alpine .
docker run --rm -it vlang:latest

Termux/Android

On Termux, V needs some packages preinstalled - a working C compiler, also libexecinfo, libgc and libgc-static. After installing them, you can use the same script, like on Linux/macos:

pkg install clang libexecinfo libgc libgc-static make git
git clone https://github.com/vlang/v
cd v
make

Editor/IDE Plugins

To bring IDE functions for the V programming languages to your editor, check out v-analyzer. It provides a VS Code extension and language server capabilities for other editors.

The plugin for JetBrains IDEs (IntelliJ, CLion, GoLand, etc.) also offers a great development experience with V. You can find all features in its documentation.

Other Plugins:

Testing and running the examples

Make sure V can compile itself:

$ v self
$ v
V 0.3.x
Use Ctrl-C or `exit` to exit

>>> println('hello world')
hello world
>>>
cd examples
v hello_world.v && ./hello_world    # or simply
v run hello_world.v                 # this builds the program and runs it right away

v run word_counter/word_counter.v word_counter/cinderella.txt
v run news_fetcher.v
v run tetris/tetris.v

tetris screenshot

In order to build Tetris or 2048 (or anything else using sokol or gg graphics modules), you will need additional development libraries for your system.

System Installation method
Debian/Ubuntu based sudo apt install libxi-dev libxcursor-dev libgl-dev
Fedora/RH/CentOS sudo dnf install libXcursor-devel libXi-devel libX11-devel libglvnd-devel
NixOS add xorg.libX11.dev xorg.libXcursor.dev xorg.libXi.dev libGL.dev to environment.systemPackages

V net.http, net.websocket, v install

The net.http module, the net.websocket module, and the v install command may all use SSL. V comes with a version of mbedtls, which should work on all systems. If you find a need to use OpenSSL instead, you will need to make sure that it is installed on your system, then use the -d use_openssl switch when you compile.

To install OpenSSL on non-Windows systems:

System Installation command
macOS brew install openssl
Debian/Ubuntu based sudo apt install libssl-dev
Arch/Manjaro openssl is installed by default
Fedora/CentOS/RH sudo dnf install openssl-devel

On Windows, OpenSSL is simply hard to get working correctly. The instructions here may (or may not) help.

V sync

V's sync module and channel implementation uses libatomic. It is most likely already installed on your system, but if not, you can install it, by doing the following:

System Installation command
macOS already installed
Debian/Ubuntu based sudo apt install libatomic1
Fedora/CentOS/RH sudo dnf install libatomic-static

V UI

V UI example screenshot

https://github.com/vlang/ui

Android graphical apps

With V's vab tool, building V UI and graphical apps for Android can become as easy as:

./vab /path/to/v/examples/2048

https://github.com/vlang/vab. vab examples screenshot

Developing web applications

Check out the Building a simple web blog tutorial and Gitly, a light and fast alternative to GitHub/GitLab:

https://github.com/vlang/gitly

gitly screenshot

Vinix, an OS/kernel written in V

V is great for writing low-level software like drivers and kernels. Vinix is an OS/kernel that already runs bash, GCC, V, and nano.

https://github.com/vlang/vinix

vinix screenshot 1

vinix screenshot 2

Acknowledgement

V thanks Fabrice Bellard for his original work on the TCC - Tiny C Compiler. Note the TCC website is old; the current TCC repository can be found here. V utilizes pre-built TCC binaries located at https://github.com/vlang/tccbin/.

Troubleshooting

Please see the Troubleshooting section on our wiki page.

v's People

Contributors

alexesprit avatar danieldaeschle avatar delta456 avatar emily33901 avatar enghitalo avatar felipensp avatar gladear avatar henrixounez avatar hungrybluedev avatar jalonsolov avatar joe-conigliaro avatar ka-weihe avatar larpon avatar louisschmieder avatar medvednikov avatar nedpals avatar ntrel avatar penguindark avatar playxe avatar shove70 avatar sleepyroy avatar spaceface777 avatar spytheman avatar stunxfs avatar trufae avatar ttytm avatar uwekrueger avatar vitalyster avatar yuyi98 avatar zakuro9715 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

v's Issues

Which license to use?

I was going to publish the source under GPLv3 with the linking exception.

To me it looks like an ideal option: it protects the project and its contributors, and it doesn't result in any inconveniences for companies, since a compiler is not a library that has to be linked. And of course it can be used to develop proprietary software.

But several people think I should go for a copyfree license.

What are the drawbacks I'm not seeing?

Update I'm now considering MPL instead of GPLv3.

Can't pass array as function argument

Hi!
I played playground, then found a bug.

Steps to reproduce:
Enter a program:

fn reverse(dummy []int) {
}

fn main() {
        arr := [1]
	println(reverse(arr))
}
  1. Run
  2. Then I got an error message:
You just found a bug. V can't compile this program, but it should. Please create a GitHub issue.

pointers and arrays can violate immutability

The following code shows issues with dealing with deep immutability. I have written the type that i think V should be using on each pointer declaration line. One line modifies immutable data - to fix this mut needs to be part of the type, not just an attribute on a variable:

struct S { i int }
fn main() {
	p1 := &S{} //type: *S
	// p1.i++ // error
	mut p2 := p1// type: mut(*)S
	s1 := S{}
	p2 = &s1// OK, can be reassigned
	p2.i++// BUG, s1 is not mutable!
	mut s2 := S{}
	p2 = &s2// currently allowed, but *p2 was immutable
	p3 := &s2// type: *mut(S)
	// p3.i++// error, could be allowed as *p3 is mut
	mut p4 := &s2
	p4.i++// OK
}

(BTW the automatic formatting of comments is not helpful, the first line's comment gets moved to a new line - bug, and space before & after // gets added or removed. There should be a space before comments after code. The programmer may want no space after // when commenting out lines, so they are distinct from real comments).

Add a gitter channel please

Not too keen on making a new account on Slack. Nor happy about the super heavy slack client (until yours comes along :))

Support for testing

V language may support thorough and exploratory testing.

1] Tests could be written like this:

TEST() // no need to invent a name
{
  assert(2 + 2 == 4);
}

TEST()
{
  assert(2 + 2 == 5);
}

(I was able to to implement such terse syntax in C++, C and Nim.)

Adding new empty test is then matter of few seconds, there is no need to register anything, to import a test library, to invent a new name, nothing at all.

2] The tests could be optionally compiled in (or omitted) in both debug and release modes. Testing in the release mode is a quite useful insurance against Heisenbugs.

3] Tests should be invoked manually (not automagically, as in D).

E.g.

 fn main()
 {
     if (tests-compiled-in) { // compiler defined constant or something
        run_tests(ONLY_RECENT_ONES);
     }
     ....
 }

For example, one may like to invoke only tests in source files modified recently (within last few hours). Then it may be practical to make run of recent tests every time whenever application starts.

4] A superfeature would be ability to replace (mock) existing functions inside given test, e.g.

TEST() 
{
   // inside this test the provided implementation of fopen() would be used
   replace fn fopen(...) { ... } 
   ... // code doing fopen(), uses the definition above
}

Having such feature would eliminate the architecture changes, mocking frameworks, dependence injections and other complicated mechanisms.

Internally, this could be implemented using functions pointers. Call to fopen() would always go through the function pointers. Normally it would end in the standard fopen(), but inside the test the value of function pointer would change to the new definition, and then back.

5] Tests could have optional attributes, whatever the user needs:

TEST(max-time <  300 ms) // if the test takes more time, show error
{
  ...
}

TEST(used-to-collect-performance-data)
{
  ...
}

TEST(shows-GUI, max-time < 20 ms)
{
  ...
}

Ideally, one would use own attributes freely, and then, in main function, one could go through these tests, check the attributes and invoke those tests desirable in the moment.

Running tests useful for performance collecting tools is one use case (tests checking edge cases should not mess with performance data).

6] The test could check that there is no memory leak inside. I have implemented this, and it really helps to find leaks early.

7] Depending how assert() is implemented: if it is debug mode only feature, then one may add variant, say verify(), which is valid also in release mode, when test are compiled in, and valid inside these tests only.

fn foo(...)
{
  assert(x < 0); // only in debug mode
  ...
}

TEST()
{
  foo(...);
  verify (y == true); // checks even in release mode
}

fn bar(...)
{
  verify(...); // not allowed here
}

8] If such functionality is available, then these tests can be seen as small, independent programs, useful for exploration and gaining insight. When one inherits large code base, such tests could be a way to familiarize with it, step by step.

Pointers should not convert to integers

Here you seem to say that pointers implicitly dereference, so I tried that:

fn main() {
	mut i := 7
	p := &i
	i = p // implicit dereference?
	assert i == 7 // fails
}

Instead i is something like 1814195804 - I think the address of the pointer is being interpreted as an integer. This should be an error - I think implicit dereference is a confusing feature that is against V's philosophy of keeping things simple.

BTW, the above code says 'Compilation took too long' - I found that adding fn f() {} at the top makes it compile within the time for some reason!

This language is not as advertised

This language is not as advertised

This language does not do over 90% of what is advertised. Most of what is advertised is not coherent with most of the claims you have stated. With the new release of the playground, most of the examples in the docs fail, even many of the extremely basic ones.

  • You appear to do very basic tokenization/lexing which you use to naïvely convert the code into C or C++ (through testing of the playground)
  • The converter program does virtually no semantic checking other than the most basic type checking
  • Name lookups do not respect nested scopes within functions and caused the playground to crash
  • There is poor checking for certain characters and tokens you disallow
  • Record types and their methods must be declared before use, the type before the methods
  • The playground was crashing frequently
  • The playground is extremely insecure

You have previously claimed that the V compiler uses no AST. However, most of the features that you claim would require a form of AST to even work, including generics and interfaces. An AST is an abstract syntax tree, which means that it just stores data about the syntax that is in a tree-like format. It's pretty much impossible to not have unless you have a very basic language or doing naïve transformations into another similar language.


You claim that the language has no runtime but the following require a runtime:

  • All arrays are dynamic
  • println
  • Threads with go
  • Synchronization of threads with runtime.wait()
  • Automatic memory management

Things that are currently broken:
- Automatic imports 
- Interface method calls
- Interfaces have to be declared with `type Foo interface {` 
- Foo{a,b} syntax (use Foo{a:a, b:b}) 
- Closures
- a[i].field
- Locks (lock {}). Use sync.Mutex for now. 
- Enums 

Disabled features:
- Generics 

Why was the playground lacking a lot of basic functionality? If most of these extremely basic features are broken, how could you have made any software in this language other than basic things? -- e.g. Fibonacci examples.

Software claimed to be built in V:

  • Volt
  • Filey
  • Vid
  • gitly
  • Hot code reloading

Claimed C/C++ Translations into V:

  • DOOM
  • DOOM 3
  • LevelDB
  • SQLite

Claims from your "compare" page:

- No null

How would you handle pointers?! In your documentation, you demonstrate that pointers exist. This means that no null is false. Pointers also crashed the playground.

- Much stricter vfmt

And when you mean stricter, what does that mean? It was also failing quite often even on basic code in the playground.

- Cheaper interfaces without dynamic dispatch

So how do they work? Is it just static dispatch?


What you have promised does not even come close to what is delivered.

Skipping imports

I just found out that in Rust 2018 fully qualified paths don’t require use or extern crate. What do you think about not requiring import http in

fn main() { 
  http.get('http://example.com')? 
}

I guess seeing all dependencies in one place is nice. And the language will automatically insert them anyway.

Where can I download the compiler?

Apologies if I am missing something obvious but I could not find a link. Another question I have is, is there a mailing list / google group?
Thanks

Official web site don't open in my browser

I want to read more about the project but I can't open the official web site since yesterday. I don't know if It it a issue but this can be a channel to warn the community about that.

Thank you in advance.

Operator overloading for built in math types

Operator overloading is bad. It makes code unpredictable.

Mike Acton says that it should only be allowed in very simple cases, like adding vectors. I agree.

I want to make V convenient for gamedev and scientific applications. They use a lot of linear algebra, and res := a.add(b).add(c) is a lot messier than res := a + b + c

The only way to achieve this without introducing operator overloading for everything is to have official math types supported by the language (vec2, vec3, mat4 etc).

What do you think?

Cannot compile program that contains method that has pointer type receiver

Steps to reproduce:

  1. Enter program list as below:
struct Foobar {
  member int
}

fn (f *Foobar) do() { // method of pointer type receiver
  println('I am foobar')
}

fn main() {
  f := Foobar{}
  f.do() // I think f is type of "Foobar", but I assume that f can treat as pointer type with implicit conversion ( like Golang )
} 
  1. Click Run button
  2. The output was shown as below.
    You just found a bug. V can't compile this program, but it should. Please create a GitHub issue.

Underscore separators?

This looks quite cool! Looking forward to seeing more and hopefully helping out at some point.

What is the reason for "going against the grain" and using _ separators instead of camelCase for identifiers?

In #3, you mention that the reason you prefer ' and ` for characters over " is that you don't want to have to press shift. That argument resonates with me.

In keeping with that theme, isn't it more efficient and easier to use camel case over underscores? The camel case method doesn't require you to reach a satellite key, plus is more normal for users in most languages (in my experience at least).

I guess it just seems odd to make so much of the language feel very similar to Go, but then abandon camel casing.

Just a thought. Do with it what you will 😄

Pattern match support?

Will V support pattern match like Erlang?

Eshell V10.2.3  (abort with ^G)
1> L = [1, 2, 3].
[1,2,3]

2> [X, _, _] = L.
[1,2,3]

3> X.
1

More documentation regarding hot reloading ?!!!

My mind can't grasp the concept behind doing hot reloading without doing a compile!!!
At first I thought it was a joke, but I guess it's not.
Could you please explain further the concept at least briefly.

The V playground is live

https://vlang.io/play

This is a pre-alpha stage. The language is going to become
a lot more stable in the next month.

Please report all issues via GitHub.

For security reasons imports are temporarily disabled, the size of the program is limited,
and your program can't run for more than 1 second.

Coming soon: online C to V translator.

Coming not so soon: online C++ to V translator.

Optional type enhancements

Optional types is a great feature. I think there should be a way to declare an empty optional type such as:

mut opt := T?() // syntax like T(v) conversion syntax but without a value v
// with built-in function instead
mut opt := empty<T>()

(This should require a mutable variable otherwise it isn't useful). Quite often there is no valid value to initialize a variable with. Here dkersten argues against using a valid value temporarily instead of an empty option type, when the value should be set later on, perhaps with complex logic.

Also, the docs show the or statement, which requires an error block to exit the current scope. There could also be an and statement:

v := opt and {
  // v is in scope here only
} else {
  // handle err and continue below
}
// only opt is in scope here

This works for one optional value, but sometimes there are more than one - perhaps pattern matching is needed to handle cases where e.g. the programmer needs a value from either opt1 xor opt2.

Name collision with vlang.org

There is already a “Vlang” which is similar enough that it’s very confusing to google anything to do with vlang!

The project looks interesting, so you plan to choose a different name to avoid the confusion?

Can I write require member?

V-lang is very good language!!!

Can I write require member in struct?
I think a struct which has default value is nearly equal null. (ex. User{ id: 0 } )
I don't want to exist them same as null.
What do you think?


Example, I want "User must have id".

struct User {
	id int /*  'require' keyword*/
}

fn main() {
	user1 := User{id: 10}
	user2 := User{} // I want this is error
}

Waiting for few (third-party) modules/frameworks

  • ldap
  • email module for construct and parse email message (like Python’s email module)
  • DNS module for basic DNS query and parse
  • web framework. vweb, vex, valval
  • mysql.
  • postgresql
  • The builtin orm module. a simple ORM which helps build SQL statement for mysql/postgresql (and SQLite maybe)

Any plan? Or maybe already have them in development?

About runtime.wait

Hey!

Was just reading the docs of the lang. Nice project!

But I do have some points.

For example, using runtime.wait (as shown in https://vlang.io/compare) to wait for all coroutines to end... How did one gets to that?

Let's say I use it inside a nested coroutine - what would happen? Would it wait for the nested coroutine or for all the coroutines?

Is the runtime keeping the scope of the coroutines where the wait method is called?

The CSP idea that Go uses seems better in this case - I'd have to send a message through the channel and could go on with my life. I do not want to wait for this - why can't I have it is an Async way?

Also, here goes (maybe) a problem: If I create a coroutine that only calls runtime.await(). Does it wait itself (as a coroutine) to end the call? Because it looks like it'd get stuck - if I'm waiting for the coroutines to end and I'm a coroutine, I'll never end.

Well, was just wondering about this. Would love to discuss more about the language itself - if possible!

Again, nice project! Hope to see some updates :-)

Android and IOS

Is there any plans for Android and Ios support.?
Also can V used to get powerfull graphics over GPUs on deff backends like Metal and OpenGl

module name déjà vu

In base64 example:

// --- file base64.v ---
module base64

... the rest of the file

Is there a reason for this redundancy and potential for confusion? Following file name = module name rule would be the simplest, making no room to cause a mess. D does this (by default) and it is one of brighter language features.

Does vlang have a golang type keyword?

vlang declare interface, struct different from golang not use type.
vlang

interface Speaker {
    speak() string
}
struct Point {
    x int
    y int 
} 

golang

type Speaker interface {
    speak() string
}
type Point struct {
    x int
    y int 
} 

golang type keyword Can also be used as type alias.
E.g context.Context and golang.org/x/net/context.Context type alias

IO?

Hi,

Is there (going to be) an IO library included with V?

Thanks!

Clarification questions about pointers and struct immutability

Firstly, I think that v looks very promising and succinct!

I have 2 clarification questions, one about pointers and the other about struct immutability.

  1. The documentation has one example with pointers. This example shows that pointers get declared and initialized along with the struct they are pointing to. Is this the only way to make pointers, or is it possible to do declare and initialize pointers so that they refer to pre-existing structs? This is the section I am referring to in the docs, from the Structs subsection:
// & prefix returns a pointer to the struct value.  
	// It's allocated on the heap and automatically cleaned up
	// by V at the end of the function, since it doesn't escape.  
	pointer := &Point{10,10} 
	println(pointer.x, pointer.y) // Pointers have the same syntax for accessing fields  

For instance, is it possible to do the following?

	p := Point{10,10}
	pointer := &p
	println(pointer.x, pointer.y)
  1. Why is it that a struct that is declared and initialized without the mut keyword can be passed into a receiver which will modify the fields of that struct? For instance, the user struct here isn't declared with mut, and yet its fields get modified by the register() method. So then, how would one guarantee that the fields of user do not get modified by any methods? In other words, how is it possible for structs to be "immutable by default:?" Or, am I misunderstanding something about "deep immutability" versus "shallow immutability" here?
struct User {
	is_registered bool 
} 

fn (u mut User) register() {
	u.is_registered = true 
} 

fn main() {
	user := User{} 
	println(user.is_registered) // ==> "false"  
	user.register() 
	// TODO: Maybe force marking methods that modify the receiver with `!`
	// user.register()!  
	println(user.is_registered) // ==> "true"  
} 

Thanks for reading!

Cannot compile and run program that print pointer value

I played Vlang playground(https://vlang.io/play), then found a bug.
This is just a short note to inform you.

Steps to reproduce:

  1. Enter program list as below
fn main() {
	u := 100
	println(&u)
}
  1. Click Run button
  2. The outut was below.
    You just found a bug. V can't compile this program, but it should. Please create a GitHub issue.

(My English was maybe something wrong, sorry.)

A V program must have a main function

The following program:

fn main2() {
types := ['game', 'web', 'tools', 'GUI']
for typ in types {
println('Hello, $typ developers!')
}
}

gives You just found a bug. V can't compile this program, but it should. Please create a GitHub issue.
It should give a better message like: undefined: main() function

Generated C code

Wow! This looks and feels a lot like Go, which I love. Good job!

I was wondering if you could show us what the C code emitted by the V compiler looks like.

One stupid question about := and =

From doc:

const PI = 3.14   // case 1

mut age := 20
age = 21    // case 2

Why we cannot use := for both cases?

I don’t have C/C++ experience, so this may be very stupid question.
But if it doesn't require programmer to remeber one more thing (i don’t mind the syntax parser and compiler to remeber more for me) that would be even better.

Btw, will we see pattern match support like Erlang?

int on 32bits

Hello

In V, the type int is an 32bits number on every plateform. What is the point ?

Doing this you risk to suffer bad performance on some architecture (or at least not using some optimization).
If the user really need 32 bits, il will use the type i32/u32.

Il you are afraid of random integeroverflow on some plateforme (tested on a 64 bits CPU, runned on a 32 bits CPU), I guess you could add a compiler option to force the 32bits size int. Or force this behaviour only when running the test.
You could also consider adding type safe_int to fix this issue.

Prevent address of local variables escaping

To enforce memory safety, V could prevent the following:

fn f() *int {
	i := 7
	return &i // should error
}
fn g(i int) *int {
	return &i // should error
}

Escaping via a receiver field could also be prevented:

struct S {
	p *int
}
fn (s mut S) f() {
	i := 5
	s.p = &i // should error
}

When the address is stored in a local pointer, the analysis is more difficult. The local pointer would need to be flagged as containing an address to local data:

fn f() *int {
	i := 7
	p := &i
	return p // should error
}

webassembly

will it be able to compile to webassembly?

functions

are functions first class like go-lang?

Add timestamp after Run for playground

It would be good to show a message like '09:30: Execution finished' after the playground program completes. I've been testing code that doesn't print anything, and also seeing the timestamp update would be good confirmation that the updateed code was run. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.